Changeset 1141
- Timestamp:
- 12/13/07 17:14:42 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php
r1140 r1141 101 101 { 102 102 $pageName = $this->getPageName(); 103 $page = $this-> getPage($pageName);103 $page = $this->pageFactory->getPage($pageName); 104 104 $elements = $page->getElements(); 105 105 $prefixRequest = new stubRequestPrefixDecorator($this->request, ''); … … 129 129 $this->response->replaceData(str_replace('$SESSION_ID', $this->session->getId(), $contents)); 130 130 } 131 }132 133 /**134 * retrieves the page instance for given page name135 *136 * Exception is only thrown when mode is not PROD, in mode PROD the page137 * will not have any elements and the frame 404.138 *139 * @param string $pageName140 * @return stubPage141 * @throws stubPageConfigurationException142 */143 protected function getPage($pageName)144 {145 try {146 $page = $this->pageFactory->getPage($pageName);147 } catch (stubPageConfigurationException $pce) {148 if (stubMode::$CURRENT->name() !== 'PROD') {149 throw $pce;150 }151 152 header('HTTP/1.0 404 Not Found');153 $page = new stubPage();154 $page->setProperty('frame', '404');155 $page->setProperty('frame_fixed', true);156 }157 158 return $page;159 131 } 160 132 trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php
r1140 r1141 20 20 array('createTemplate', 21 21 'getPageName', 22 'getPage',23 22 'getFrameId', 24 23 'processCacheVars', … … 27 26 ) 28 27 ); 29 /**30 * Page factory that will always throw an exception when a page is requested.31 *32 * @package stubbles33 * @subpackage websites_memphis_test34 */35 class stubExceptionPageFactory extends stubBaseObject implements stubPageFactory36 {37 /**38 * checks whether the page factory knows the page or not39 *40 * @param string $configSource source of the page configuration to use41 * @return bool42 */43 public function hasPage($configSource)44 {45 return true;46 }47 48 /**49 * returns the configured stubPage instance50 *51 * @param string $configSource source of the page configuration to use52 * @return stubPage53 * @throws stubPageConfigurationException54 */55 public function getPage($configSource)56 {57 throw new stubPageConfigurationException('Page not found');58 }59 }60 28 /** 61 29 * Extend tested class to be able to inject mock instances. … … 115 83 { 116 84 return $this->template; 117 }118 119 /**120 * helper method to access protected method processCacheVars()121 *122 * @param string $pageName123 * @return stubPage124 * @throws stubPageConfigurationException125 */126 public function callGetPage($pageName)127 {128 return $this->getPage($pageName);129 85 } 130 86 … … 324 280 $memphisProcessor->setReturnValue('getPageName', 'foo'); 325 281 $memphisProcessor->setReturnValue('getFrameId', 'bar'); 326 $memphisProcessor->setReturnValue('getPage', $this->mockPage);327 282 $mockPageElement = new MockstubPageElement(); 328 283 $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); … … 348 303 $memphisProcessor->setReturnValue('getPageName', 'foo'); 349 304 $memphisProcessor->setReturnValue('getFrameId', 'bar'); 350 $memphisProcessor->setReturnValue('getPage', $this->mockPage);351 305 $mockPageElement = new MockstubPageElement(); 352 306 $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); … … 381 335 $memphisProcessor->setReturnValue('getPageName', 'foo'); 382 336 $memphisProcessor->setReturnValue('getFrameId', 'bar'); 383 $memphisProcessor->setReturnValue('getPage', $this->mockPage);384 337 $mockPageElement = new MockstubPageElement(); 385 338 $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); … … 413 366 $memphisProcessor->setReturnValue('getPageName', 'foo'); 414 367 $memphisProcessor->setReturnValue('getFrameId', 'bar'); 415 $memphisProcessor->setReturnValue('getPage', $this->mockPage);416 368 $mockPageElement = new MockstubPageElement(); 417 369 $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); … … 430 382 $this->mockResponse->expectNever('replaceData'); 431 383 $memphisProcessor->callDoProcess(); 432 }433 434 /**435 * test that correct page instance is created436 */437 public function testGetPage()438 {439 $this->mockPageFactory->expectOnce('getPage', array('foo'));440 $this->assertEqual($this->memphisProcessor->callGetPage('foo'), $this->mockPage);441 }442 443 /**444 * test that correct page instance is created445 */446 public function testGetPageButNotFoundModeNotProd()447 {448 stubMode::setCurrent(stubMode::$DEV);449 $pageFactory = new stubExceptionPageFactory();450 $this->memphisProcessor->setPageFactory($pageFactory);451 $this->expectException('stubPageConfigurationException');452 $this->memphisProcessor->callGetPage('foo');453 }454 455 /**456 * test that correct page instance is created457 */458 public function testGetPageButNotFoundModeIsProd()459 {460 stubMode::setCurrent(stubMode::$PROD);461 $pageFactory = new stubExceptionPageFactory();462 $this->memphisProcessor->setPageFactory($pageFactory);463 $page = $this->memphisProcessor->callGetPage('foo');464 $this->assertIsA($page, 'stubPage');465 $this->assertEqual($page->getProperty('frame'), '404');466 $this->assertTrue($page->getProperty('frame_fixed'));467 384 } 468 385
