Changeset 1468

Show
Ignore:
Timestamp:
03/27/08 15:12:08 (3 months ago)
Author:
mikey
Message:

delay xml generator initialization to processing time

Files:

Legend:

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

    r1467 r1468  
    5454     */ 
    5555    protected $pageName; 
    56     /** 
    57      * binder to be used for ioc 
    58      * 
    59      * @var  stubBinder 
    60      */ 
    61     protected $binder; 
    6256 
    6357    /** 
     
    7266        $this->page     = $pageFactory->getPage($this->pageName); 
    7367        $this->session->putValue('net.stubbles.websites.lastPage', $this->pageName); 
    74         $this->initializeGenerators(); 
    7568    } 
    7669 
     
    8275    protected function initializeGenerators() 
    8376    { 
     77        if (count($this->xmlGenerators) > 0) { 
     78            return; 
     79        } 
     80         
    8481        $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); 
    8582        if (($binder instanceof stubBinder) === false) { 
     
    116113    public function addCacheVars(stubWebsiteCache $cache) 
    117114    { 
     115        $this->initializeGenerators(); 
    118116        foreach ($this->xmlGenerators as $xmlGenerator) { 
    119117            if ($xmlGenerator->isCachable() === false) { 
     
    147145    public function process() 
    148146    { 
     147        $this->initializeGenerators(); 
    149148        $xmlStreamWriter = $this->createXMLStreamWriter(); 
    150149        $xmlStreamWriter->writeStartElement('document'); 
  • trunk/src/test/php/net/stubbles/integration/ProcessorTestCase.php

    r1467 r1468  
    1616class ProcessorTestCase extends PHPUnit_Framework_TestCase 
    1717{ 
    18     /** 
    19      * set up test environment 
    20      */ 
    21     public function setUp() 
    22     { 
    23         stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder($this->getMock('stubInjector'))); 
    24     } 
    25  
    26     /** 
    27      * clean up test environment 
    28      */ 
    29     public function tearDown() 
    30     { 
    31         stubRegistry::remove(stubBinder::REGISTRY_KEY); 
    32     } 
    33  
    3418    /** 
    3519     * helper method 
  • trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php

    r1467 r1468  
    9999        $this->mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($this->page)); 
    100100        $this->mockSession->expects($this->at(0))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastPage'), $this->equalTo('index')); 
     101        $this->xmlProcessor->selectPage($this->mockPageFactory); 
    101102    } 
    102103 
     
    115116     * @expectedException  stubRuntimeException 
    116117     */ 
    117     public function selectPageWithoutBinderInRegistryThrowsRuntimeException() 
     118    public function cachabilityTestWithoutBinderInRegistryThrowsRuntimeException() 
    118119    { 
    119120        stubRegistry::remove(stubBinder::REGISTRY_KEY); 
    120         $this->xmlProcessor->selectPage($this->mockPageFactory); 
     121        $this->xmlProcessor->addCacheVars($this->getMock('stubWebsiteCache')); 
     122    } 
     123 
     124    /** 
     125     * no binder available > runtime exception 
     126     * 
     127     * @test 
     128     * @expectedException  stubRuntimeException 
     129     */ 
     130    public function processWithoutBinderInRegistryThrowsRuntimeException() 
     131    { 
     132        stubRegistry::remove(stubBinder::REGISTRY_KEY); 
     133        $this->xmlProcessor->process(); 
    121134    } 
    122135 
     
    128141    public function isCachable() 
    129142    { 
     143        $this->assertEquals('index', $this->xmlProcessor->getPageName()); 
     144         
    130145        $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 
    131146        $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 
    132         $mockXMLGenerator->expects($this->exactly(3))->method('isCachable')->will($this->returnValue(true)); 
    133         $mockXMLGenerator->expects($this->exactly(3))->method('getCacheVars')->will($this->returnValue(array('foo' => 'bar'))); 
    134         $mockXMLGenerator->expects($this->exactly(3))->method('getUsedFiles')->will($this->returnValue(array('foo.bar'))); 
    135         $this->xmlProcessor->selectPage($this->mockPageFactory); 
    136          
     147        $mockXMLGenerator->expects($this->exactly(6))->method('isCachable')->will($this->returnValue(true)); 
     148        $mockXMLGenerator->expects($this->exactly(6))->method('getCacheVars')->will($this->returnValue(array('foo' => 'bar'))); 
     149        $mockXMLGenerator->expects($this->exactly(6))->method('getUsedFiles')->will($this->returnValue(array('foo.bar'))); 
     150        $mockWebsiteCache = $this->getMock('stubWebsiteCache'); 
     151        $mockWebsiteCache->expects($this->exactly(2))->method('addCacheVar')->with($this->equalTo('page'), $this->equalTo('index')); 
     152        $mockWebsiteCache->expects($this->exactly(6))->method('addCacheVars')->with($this->equalTo(array('foo' => 'bar'))); 
     153        $mockWebsiteCache->expects($this->exactly(6))->method('addUsedFiles')->with($this->equalTo(array('foo.bar'))); 
     154        $this->assertTrue($this->xmlProcessor->addCacheVars($mockWebsiteCache)); 
     155        $this->assertTrue($this->xmlProcessor->addCacheVars($mockWebsiteCache)); 
     156    } 
     157 
     158    /** 
     159     * page to be generated is not cachable 
     160     * 
     161     * @test 
     162     */ 
     163    public function isNotCachable() 
     164    { 
    137165        $this->assertEquals('index', $this->xmlProcessor->getPageName()); 
    138         $mockWebsiteCache = $this->getMock('stubWebsiteCache'); 
    139         $mockWebsiteCache->expects($this->once())->method('addCacheVar')->with($this->equalTo('page'), $this->equalTo('index')); 
    140         $mockWebsiteCache->expects($this->exactly(3))->method('addCacheVars')->with($this->equalTo(array('foo' => 'bar'))); 
    141         $mockWebsiteCache->expects($this->exactly(3))->method('addUsedFiles')->with($this->equalTo(array('foo.bar'))); 
    142         $this->assertTrue($this->xmlProcessor->addCacheVars($mockWebsiteCache)); 
    143     } 
    144  
    145     /** 
    146      * page to be generated is not cachable 
    147      * 
    148      * @test 
    149      */ 
    150     public function isNotCachable() 
    151     { 
     166         
    152167        $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 
    153168        $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 
     
    155170        $mockXMLGenerator->expects($this->never())->method('getCacheVars'); 
    156171        $mockXMLGenerator->expects($this->never())->method('getUsedFiles'); 
    157         $this->xmlProcessor->selectPage($this->mockPageFactory); 
    158          
    159         $this->assertEquals('index', $this->xmlProcessor->getPageName()); 
    160172        $mockWebsiteCache = $this->getMock('stubWebsiteCache'); 
    161173        $mockWebsiteCache->expects($this->never())->method('addCacheVar'); 
     
    175187        $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 
    176188        $mockXMLGenerator->expects($this->exactly(3))->method('generate')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); 
    177         $this->xmlProcessor->selectPage($this->mockPageFactory); 
    178          
    179189        $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); 
    180190        $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer));