Changeset 1468
- Timestamp:
- 03/27/08 15:12:08 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1467 r1468 54 54 */ 55 55 protected $pageName; 56 /**57 * binder to be used for ioc58 *59 * @var stubBinder60 */61 protected $binder;62 56 63 57 /** … … 72 66 $this->page = $pageFactory->getPage($this->pageName); 73 67 $this->session->putValue('net.stubbles.websites.lastPage', $this->pageName); 74 $this->initializeGenerators();75 68 } 76 69 … … 82 75 protected function initializeGenerators() 83 76 { 77 if (count($this->xmlGenerators) > 0) { 78 return; 79 } 80 84 81 $binder = stubRegistry::get(stubBinder::REGISTRY_KEY); 85 82 if (($binder instanceof stubBinder) === false) { … … 116 113 public function addCacheVars(stubWebsiteCache $cache) 117 114 { 115 $this->initializeGenerators(); 118 116 foreach ($this->xmlGenerators as $xmlGenerator) { 119 117 if ($xmlGenerator->isCachable() === false) { … … 147 145 public function process() 148 146 { 147 $this->initializeGenerators(); 149 148 $xmlStreamWriter = $this->createXMLStreamWriter(); 150 149 $xmlStreamWriter->writeStartElement('document'); trunk/src/test/php/net/stubbles/integration/ProcessorTestCase.php
r1467 r1468 16 16 class ProcessorTestCase extends PHPUnit_Framework_TestCase 17 17 { 18 /**19 * set up test environment20 */21 public function setUp()22 {23 stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder($this->getMock('stubInjector')));24 }25 26 /**27 * clean up test environment28 */29 public function tearDown()30 {31 stubRegistry::remove(stubBinder::REGISTRY_KEY);32 }33 34 18 /** 35 19 * helper method trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php
r1467 r1468 99 99 $this->mockPageFactory->expects($this->once())->method('getPage')->will($this->returnValue($this->page)); 100 100 $this->mockSession->expects($this->at(0))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastPage'), $this->equalTo('index')); 101 $this->xmlProcessor->selectPage($this->mockPageFactory); 101 102 } 102 103 … … 115 116 * @expectedException stubRuntimeException 116 117 */ 117 public function selectPageWithoutBinderInRegistryThrowsRuntimeException()118 public function cachabilityTestWithoutBinderInRegistryThrowsRuntimeException() 118 119 { 119 120 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(); 121 134 } 122 135 … … 128 141 public function isCachable() 129 142 { 143 $this->assertEquals('index', $this->xmlProcessor->getPageName()); 144 130 145 $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 131 146 $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 { 137 165 $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 152 167 $mockXMLGenerator = $this->getMock('stubXMLGenerator'); 153 168 $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); … … 155 170 $mockXMLGenerator->expects($this->never())->method('getCacheVars'); 156 171 $mockXMLGenerator->expects($this->never())->method('getUsedFiles'); 157 $this->xmlProcessor->selectPage($this->mockPageFactory);158 159 $this->assertEquals('index', $this->xmlProcessor->getPageName());160 172 $mockWebsiteCache = $this->getMock('stubWebsiteCache'); 161 173 $mockWebsiteCache->expects($this->never())->method('addCacheVar'); … … 175 187 $this->mockInjector->expects($this->exactly(3))->method('getInstance')->will($this->returnValue($mockXMLGenerator)); 176 188 $mockXMLGenerator->expects($this->exactly(3))->method('generate')->with($this->equalTo($this->mockXMLStreamWriter), $this->equalTo($this->mockXMLSerializer)); 177 $this->xmlProcessor->selectPage($this->mockPageFactory);178 179 189 $this->xmlProcessor->expects($this->once())->method('createXMLStreamWriter')->will($this->returnValue($this->mockXMLStreamWriter)); 180 190 $this->xmlProcessor->expects($this->once())->method('createXMLSerializer')->will($this->returnValue($this->mockXMLSerializer));
