Changeset 1424
- Timestamp:
- 03/14/08 16:56:22 (4 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/xml/skin (added)
- trunk/src/main/php/net/stubbles/websites/xml/skin/stubSkinGenerator.php (moved) (moved from trunk/src/main/php/net/stubbles/websites/xml/stubSkinGenerator.php) (10 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/skin (added)
- trunk/src/test/php/net/stubbles/websites/xml/skin/stubSkinGeneratorTestCase.php (moved) (moved from trunk/src/test/php/net/stubbles/websites/xml/stubSkinGeneratorTestCase.php) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/xml/skin/stubSkinGenerator.php
r1413 r1424 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 * @subpackage websites_xml 7 * @subpackage websites_xml_skin 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ioc::stubBinder', … … 17 17 /** 18 18 * Class to generate the skin to be applied onto the XML result document. 19 * 20 * Please make sure that within the registry a value accessible with key 21 * 'net::stubbles::ioc.stubBinder' is configured and an instance of 22 * net::stubbles::ioc::stubBinder. If the pre interceptor 23 * net::stubbles::ioc::stubIOCPreInterceptor is configured as pre interceptor 24 * this one will put a stubBinder instance into the registry. 19 * 25 20 * Please make sure as well that a file named xsl-callbacks.ini resides in the 26 21 * base config directory configured in stubConfig::getConfigPath(). 27 22 * 28 23 * @package stubbles 29 * @subpackage websites_xml 24 * @subpackage websites_xml_skin 30 25 */ 31 26 class stubSkinGenerator extends stubBaseObject 32 27 { 28 /** 29 * callback config file name 30 * 31 * @var string 32 */ 33 protected $callbackConfigFile; 34 33 35 /** 34 36 * constructor … … 39 41 stubXMLXIncludeStreamWrapper::setIncludePath(stubConfig::getPagePath() . '/txt'); 40 42 stubXMLXIncludeStreamWrapper::setCachePath(stubConfig::getCachePath()); 43 $this->callbackConfigFile = stubConfig::getConfigPath() . '/xsl-callbacks.ini'; 44 } 45 46 /** 47 * sets the callback config file 48 * 49 * @param string $callbackConfigFile 50 */ 51 public function setCallbackConfigFile($callbackConfigFile) 52 { 53 $this->callbackConfigFile = $callbackConfigFile; 41 54 } 42 55 … … 47 60 * @param stubXMLResponse $response 48 61 * @return DOMDocument 62 * @throws stubRuntimeException 49 63 */ 50 64 public function generate(stubSession $session, stubXMLResponse $response) … … 78 92 $xslProcessor->setParameter('', 'lang', $language); 79 93 // use same xsl processor for xincludes 80 $this->setXIncludeProcessor($xslProcessor);94 stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 81 95 82 96 // first we create the xsl with applying the master.xsl on the skin and the page … … 93 107 * @return stubXSLProcessor 94 108 */ 109 // @codeCoverageIgnoreStart 95 110 protected function createXSLProcessor() 96 111 { 97 112 return new stubXSLProcessor(); 98 113 } 114 // @codeCoverageIgnoreEnd 99 115 100 116 /** … … 106 122 protected function getCallbackList() 107 123 { 108 $iniFile = stubConfig::getConfigPath() . '/xsl-callbacks.ini'; 109 if (file_exists($iniFile) === false) { 110 throw new stubRuntimeException('Configuration file ' . $iniFile . ' for XSL callback configuration is missing.'); 124 if (file_exists($this->callbackConfigFile) === false) { 125 throw new stubRuntimeException('Configuration file ' . $this->callbackConfigFile . ' for XSL callback configuration is missing.'); 111 126 } 112 127 113 return parse_ini_file($iniFile); 114 } 115 116 /** 117 * use same xsl processor for the xincludes 118 * 119 * @param stubXSLProcessor $xslProcessor 120 */ 121 protected function setXIncludeProcessor($xslProcessor) 122 { 123 stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 128 return parse_ini_file($this->callbackConfigFile); 124 129 } 125 130 … … 130 135 * @todo fix selection of uri 131 136 */ 137 // @codeCoverageIgnoreStart 132 138 protected function createXSLStylesheet() 133 139 { … … 135 141 return DOMDocument::load($uris[0]); 136 142 } 143 // @codeCoverageIgnoreEnd 137 144 138 145 /** … … 142 149 * @return DOMDocument 143 150 */ 151 // @codeCoverageIgnoreStart 144 152 protected function createXMLSkinDocument($skin) 145 153 { 146 154 return DOMDocument::load(stubConfig::getPagePath() . '/skin/' . $skin . '.xml'); 147 155 } 156 // @codeCoverageIgnoreEnd 148 157 } 149 158 ?> trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1423 r1424 12 12 'net::stubbles::util::stubRegistry', 13 13 'net::stubbles::websites::processors::stubAbstractPageProcessor', 14 'net::stubbles::websites::xml::s tubSkinGenerator',14 'net::stubbles::websites::xml::skin::stubSkinGenerator', 15 15 'net::stubbles::websites::xml::stubXMLResponse', 16 16 'net::stubbles::xml::stubXMLStreamWriterFactory', trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r1423 r1424 27 27 $suite->addTestFile($dir . '/stubFrontControllerTestCase.php'); 28 28 $suite->addTestFile($dir . '/stubPageTestCase.php'); 29 30 // cache tests29 30 // cache 31 31 $suite->addTestFile($dir . '/cache/stubAbstractWebsiteCacheTestCase.php'); 32 32 $suite->addTestFile($dir . '/cache/stubDefaultWebsiteCacheFactoryTestCase.php'); … … 34 34 $suite->addTestFile($dir . '/cache/stubGzipWebsiteCacheTestCase.php'); 35 35 36 // memphis tests36 // memphis 37 37 $suite->addTestFile($dir . '/memphis/stubMemphisIncludeFilePageElementTestCase.php'); 38 38 $suite->addTestFile($dir . '/memphis/stubMemphisPageElementTestCase.php'); 39 39 $suite->addTestFile($dir . '/memphis/stubMemphisProcessorTestCase.php'); 40 40 41 // processors tests41 // processors 42 42 $suite->addTestFile($dir . '/processors/stubAbstractPageProcessorTestCase.php'); 43 43 $suite->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php'); … … 47 47 $suite->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); 48 48 49 // xml tests49 // xml 50 50 $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 51 $suite->addTestFile($dir . '/xml/stubSkinGeneratorTestCase.php');52 51 $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 53 52 $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); 54 55 // xml generators 53 54 // xml skin 55 $suite->addTestFile($dir . '/xml/skin/stubSkinGeneratorTestCase.php'); 56 57 // xml generator 56 58 $suite->addTestFile($dir . '/xml/generator/stubPageXMLGeneratorTestCase.php'); 57 59 $suite->addTestFile($dir . '/xml/generator/stubRequestXMLGeneratorTestCase.php'); trunk/src/test/php/net/stubbles/websites/xml/skin/stubSkinGeneratorTestCase.php
r1413 r1424 1 1 <?php 2 2 /** 3 * Tests for net::stubbles::websites::xml::s tubSkinGenerator.3 * Tests for net::stubbles::websites::xml::skin::stubSkinGenerator. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 * @subpackage websites_xml_ test7 * @subpackage websites_xml_skin_test 8 8 */ 9 stubClassLoader::load('net::stubbles::websites::xml::s tubSkinGenerator');9 stubClassLoader::load('net::stubbles::websites::xml::skin::stubSkinGenerator'); 10 10 /** 11 * Tests for net::stubbles::websites::xml::stubSkinGenerator.11 * Helper class to access a protected method. 12 12 * 13 13 * @package stubbles 14 * @subpackage websites_xml_test 14 * @subpackage websites_xml_skin_test 15 */ 16 class TeststubSkinGenerator extends stubSkinGenerator 17 { 18 /** 19 * method to access the protected method under test 20 * 21 * @return array 22 */ 23 public function callGetCallbackList() 24 { 25 return $this->getCallbackList(); 26 } 27 } 28 /** 29 * Tests for net::stubbles::websites::xml::skin::stubSkinGenerator. 30 * 31 * @package stubbles 32 * @subpackage websites_xml_skin_test 15 33 */ 16 34 class stubSkinGeneratorTestCase extends PHPUnit_Framework_TestCase … … 64 82 */ 65 83 protected $resultDomDocument; 84 /** 85 * mocked injector instance 86 * 87 * @var PHPUnit_Framework_MockObject_MockObject 88 */ 89 protected $mockInjector; 66 90 67 91 /** … … 71 95 { 72 96 $this->skinGenerator = $this->getMock('stubSkinGenerator', 73 array('setXIncludeProcessor', 74 'createXSLProcessor', 97 array('createXSLProcessor', 75 98 'getCallbackList', 76 99 'createXMLSkinDocument' … … 87 110 $this->mockXSLProcessor->expects($this->any())->method('transformToDoc')->will($this->returnValue($this->resultDomDocument)); 88 111 $this->skinGenerator->expects($this->any())->method('createXSLProcessor')->will($this->returnValue($this->mockXSLProcessor)); 89 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array()));90 112 if (stubRegistry::hasConfig('net.stubbles.language') == true) { 91 113 stubRegistry::setConfig('net.stubbles.language', null); 92 114 } 93 115 94 stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder()); 116 $this->mockInjector = $this->getMock('stubInjector'); 117 stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder($this->mockInjector)); 95 118 } 96 119 … … 111 134 { 112 135 $this->page->setProperty('name', 'baz'); 136 $callback = $this->getMock('stubObject'); 137 $this->mockInjector->expects($this->once())->method('getInstance')->with($this->equalTo('stdClass'))->will($this->returnValue($callback)); 138 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array('foo' => 'stdClass'))); 113 139 $this->skinGenerator->expects($this->once()) 114 140 ->method('createXMLSkinDocument') 115 141 ->with($this->equalTo('default')) 116 142 ->will($this->returnValue($this->getMock('DOMDocument'))); 117 $this->mockXSLProcessor->expects($this->at(1))->method('setParameter')->with($this->equalTo(''), $this->equalTo('page'), $this->equalTo('baz')); 118 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('en_EN')); 143 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('page'), $this->equalTo('baz')); 144 $this->mockXSLProcessor->expects($this->at(3))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('en_EN')); 145 $this->mockXSLProcessor->expects($this->once())->method('registerCallback')->with($this->equalTo('foo'), $this->equalTo($callback)); 119 146 120 147 $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->xmlResponse)); … … 129 156 { 130 157 $this->page->setProperty('skin', 'another'); 158 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 131 159 $this->skinGenerator->expects($this->once()) 132 160 ->method('createXMLSkinDocument') … … 144 172 { 145 173 stubRegistry::setConfig('net.stubbles.language', 'foo'); 174 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 146 175 $this->skinGenerator->expects($this->any()) 147 176 ->method('createXMLSkinDocument') … … 160 189 $this->page->setProperty('language', 'bar'); 161 190 stubRegistry::setConfig('net.stubbles.language', 'foo'); 191 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 162 192 $this->skinGenerator->expects($this->any()) 163 193 ->method('createXMLSkinDocument') … … 174 204 public function sessionLanguage() 175 205 { 206 $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 176 207 $this->skinGenerator->expects($this->any()) 177 208 ->method('createXMLSkinDocument') … … 196 227 $this->skinGenerator->generate($this->mockSession, $this->xmlResponse); 197 228 } 229 230 /** 231 * ensure callback configuration is correct 232 * 233 * @test 234 */ 235 public function callbacks() 236 { 237 $skinGenerator = new TeststubSkinGenerator(); 238 $this->assertEquals(array('image' => 'net::stubbles::xml::xsl::util::stubXSLImageDimensions'), $skinGenerator->callGetCallbackList()); 239 } 240 241 /** 242 * ensure callback configuration is correct 243 * 244 * @test 245 * @expectedException stubRuntimeException 246 */ 247 public function callbacksConfigurationFileMissing() 248 { 249 $skinGenerator = new TeststubSkinGenerator(); 250 $skinGenerator->setCallbackConfigFile(dirname(__FILE__) . '/doesNotExist.ini'); 251 $skinGenerator->callGetCallbackList(); 252 } 198 253 } 199 254 ?>
