Changeset 1141

Show
Ignore:
Timestamp:
12/13/07 17:14:42 (9 months ago)
Author:
mikey
Message:

removed getPage() abstraction

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php

    r1140 r1141  
    101101    { 
    102102        $pageName      = $this->getPageName(); 
    103         $page          = $this->getPage($pageName); 
     103        $page          = $this->pageFactory->getPage($pageName); 
    104104        $elements      = $page->getElements(); 
    105105        $prefixRequest = new stubRequestPrefixDecorator($this->request, ''); 
     
    129129            $this->response->replaceData(str_replace('$SESSION_ID', $this->session->getId(), $contents)); 
    130130        } 
    131     } 
    132  
    133     /** 
    134      * retrieves the page instance for given page name 
    135      * 
    136      * Exception is only thrown when mode is not PROD, in mode PROD the page 
    137      * will not have any elements and the frame 404. 
    138      * 
    139      * @param   string    $pageName 
    140      * @return  stubPage 
    141      * @throws  stubPageConfigurationException 
    142      */ 
    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; 
    159131    } 
    160132 
  • trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php

    r1140 r1141  
    2020                      array('createTemplate', 
    2121                            'getPageName', 
    22                             'getPage', 
    2322                            'getFrameId', 
    2423                            'processCacheVars', 
     
    2726                      ) 
    2827); 
    29 /** 
    30  * Page factory that will always throw an exception when a page is requested. 
    31  * 
    32  * @package     stubbles 
    33  * @subpackage  websites_memphis_test 
    34  */ 
    35 class stubExceptionPageFactory extends stubBaseObject implements stubPageFactory 
    36 { 
    37     /** 
    38      * checks whether the page factory knows the page or not 
    39      * 
    40      * @param   string  $configSource  source of the page configuration to use 
    41      * @return  bool 
    42      */ 
    43     public function hasPage($configSource) 
    44     { 
    45         return true; 
    46     } 
    47      
    48     /** 
    49      * returns the configured stubPage instance 
    50      * 
    51      * @param   string    $configSource  source of the page configuration to use 
    52      * @return  stubPage 
    53      * @throws  stubPageConfigurationException 
    54      */ 
    55     public function getPage($configSource) 
    56     { 
    57         throw new stubPageConfigurationException('Page not found'); 
    58     } 
    59 } 
    6028/** 
    6129 * Extend tested class to be able to inject mock instances. 
     
    11583    { 
    11684        return $this->template; 
    117     } 
    118  
    119     /** 
    120      * helper method to access protected method processCacheVars() 
    121      * 
    122      * @param   string    $pageName 
    123      * @return  stubPage 
    124      * @throws  stubPageConfigurationException 
    125      */ 
    126     public function callGetPage($pageName) 
    127     { 
    128         return $this->getPage($pageName); 
    12985    } 
    13086 
     
    324280        $memphisProcessor->setReturnValue('getPageName', 'foo'); 
    325281        $memphisProcessor->setReturnValue('getFrameId', 'bar'); 
    326         $memphisProcessor->setReturnValue('getPage', $this->mockPage); 
    327282        $mockPageElement = new MockstubPageElement(); 
    328283        $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); 
     
    348303        $memphisProcessor->setReturnValue('getPageName', 'foo'); 
    349304        $memphisProcessor->setReturnValue('getFrameId', 'bar'); 
    350         $memphisProcessor->setReturnValue('getPage', $this->mockPage); 
    351305        $mockPageElement = new MockstubPageElement(); 
    352306        $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); 
     
    381335        $memphisProcessor->setReturnValue('getPageName', 'foo'); 
    382336        $memphisProcessor->setReturnValue('getFrameId', 'bar'); 
    383         $memphisProcessor->setReturnValue('getPage', $this->mockPage); 
    384337        $mockPageElement = new MockstubPageElement(); 
    385338        $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); 
     
    413366        $memphisProcessor->setReturnValue('getPageName', 'foo'); 
    414367        $memphisProcessor->setReturnValue('getFrameId', 'bar'); 
    415         $memphisProcessor->setReturnValue('getPage', $this->mockPage); 
    416368        $mockPageElement = new MockstubPageElement(); 
    417369        $this->mockPage->setReturnValue('getElements', array('baz' => $mockPageElement)); 
     
    430382        $this->mockResponse->expectNever('replaceData'); 
    431383        $memphisProcessor->callDoProcess(); 
    432     } 
    433  
    434     /** 
    435      * test that correct page instance is created 
    436      */ 
    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 created 
    445      */ 
    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 created 
    457      */ 
    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')); 
    467384    } 
    468385