Changeset 1424

Show
Ignore:
Timestamp:
03/14/08 16:56:22 (4 months ago)
Author:
mikey
Message:

moved skin generator into its own package

Files:

Legend:

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

    r1413 r1424  
    55 * @author      Frank Kleine <mikey@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  websites_xml 
     7 * @subpackage  websites_xml_skin 
    88 */ 
    99stubClassLoader::load('net::stubbles::ioc::stubBinder', 
     
    1717/** 
    1818 * 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 * 
    2520 * Please make sure as well that a file named xsl-callbacks.ini resides in the 
    2621 * base config directory configured in stubConfig::getConfigPath(). 
    2722 * 
    2823 * @package     stubbles 
    29  * @subpackage  websites_xml 
     24 * @subpackage  websites_xml_skin 
    3025 */ 
    3126class stubSkinGenerator extends stubBaseObject 
    3227{ 
     28    /** 
     29     * callback config file name 
     30     * 
     31     * @var  string 
     32     */ 
     33    protected $callbackConfigFile; 
     34 
    3335    /** 
    3436     * constructor 
     
    3941        stubXMLXIncludeStreamWrapper::setIncludePath(stubConfig::getPagePath() . '/txt'); 
    4042        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; 
    4154    } 
    4255 
     
    4760     * @param   stubXMLResponse  $response 
    4861     * @return  DOMDocument 
     62     * @throws  stubRuntimeException 
    4963     */ 
    5064    public function generate(stubSession $session, stubXMLResponse $response) 
     
    7892        $xslProcessor->setParameter('', 'lang', $language); 
    7993        // use same xsl processor for xincludes 
    80         $this->setXIncludeProcessor($xslProcessor); 
     94        stubXMLXIncludeStreamWrapper::setXSLProcessor($xslProcessor); 
    8195 
    8296        // first we create the xsl with applying the master.xsl on the skin and the page 
     
    93107     * @return  stubXSLProcessor 
    94108     */ 
     109    // @codeCoverageIgnoreStart 
    95110    protected function createXSLProcessor() 
    96111    { 
    97112        return new stubXSLProcessor(); 
    98113    } 
     114    // @codeCoverageIgnoreEnd 
    99115 
    100116    /** 
     
    106122    protected function getCallbackList() 
    107123    { 
    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.'); 
    111126        } 
    112127         
    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); 
    124129    } 
    125130 
     
    130135     * @todo    fix selection of uri 
    131136     */ 
     137    // @codeCoverageIgnoreStart 
    132138    protected function createXSLStylesheet() 
    133139    { 
     
    135141        return DOMDocument::load($uris[0]); 
    136142    } 
     143    // @codeCoverageIgnoreEnd 
    137144 
    138145    /** 
     
    142149     * @return  DOMDocument 
    143150     */ 
     151    // @codeCoverageIgnoreStart 
    144152    protected function createXMLSkinDocument($skin) 
    145153    { 
    146154        return DOMDocument::load(stubConfig::getPagePath() . '/skin/' . $skin . '.xml'); 
    147155    } 
     156    // @codeCoverageIgnoreEnd 
    148157} 
    149158?> 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php

    r1423 r1424  
    1212                      'net::stubbles::util::stubRegistry', 
    1313                      'net::stubbles::websites::processors::stubAbstractPageProcessor', 
    14                       'net::stubbles::websites::xml::stubSkinGenerator', 
     14                      'net::stubbles::websites::xml::skin::stubSkinGenerator', 
    1515                      'net::stubbles::websites::xml::stubXMLResponse', 
    1616                      'net::stubbles::xml::stubXMLStreamWriterFactory', 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r1423 r1424  
    2727        $suite->addTestFile($dir . '/stubFrontControllerTestCase.php'); 
    2828        $suite->addTestFile($dir . '/stubPageTestCase.php'); 
    29          
    30         // cache tests 
     29 
     30        // cache 
    3131        $suite->addTestFile($dir . '/cache/stubAbstractWebsiteCacheTestCase.php'); 
    3232        $suite->addTestFile($dir . '/cache/stubDefaultWebsiteCacheFactoryTestCase.php'); 
     
    3434        $suite->addTestFile($dir . '/cache/stubGzipWebsiteCacheTestCase.php'); 
    3535 
    36         // memphis tests 
     36        // memphis 
    3737        $suite->addTestFile($dir . '/memphis/stubMemphisIncludeFilePageElementTestCase.php'); 
    3838        $suite->addTestFile($dir . '/memphis/stubMemphisPageElementTestCase.php'); 
    3939        $suite->addTestFile($dir . '/memphis/stubMemphisProcessorTestCase.php'); 
    4040 
    41         // processors tests 
     41        // processors 
    4242        $suite->addTestFile($dir . '/processors/stubAbstractPageProcessorTestCase.php'); 
    4343        $suite->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php'); 
     
    4747        $suite->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); 
    4848 
    49         // xml tests 
     49        // xml 
    5050        $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 
    51         $suite->addTestFile($dir . '/xml/stubSkinGeneratorTestCase.php'); 
    5251        $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 
    5352        $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 
    5658        $suite->addTestFile($dir . '/xml/generator/stubPageXMLGeneratorTestCase.php'); 
    5759        $suite->addTestFile($dir . '/xml/generator/stubRequestXMLGeneratorTestCase.php'); 
  • trunk/src/test/php/net/stubbles/websites/xml/skin/stubSkinGeneratorTestCase.php

    r1413 r1424  
    11<?php 
    22/** 
    3  * Tests for net::stubbles::websites::xml::stubSkinGenerator. 
     3 * Tests for net::stubbles::websites::xml::skin::stubSkinGenerator. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
    66 * @package     stubbles 
    7  * @subpackage  websites_xml_test 
     7 * @subpackage  websites_xml_skin_test 
    88 */ 
    9 stubClassLoader::load('net::stubbles::websites::xml::stubSkinGenerator'); 
     9stubClassLoader::load('net::stubbles::websites::xml::skin::stubSkinGenerator'); 
    1010/** 
    11  * Tests for net::stubbles::websites::xml::stubSkinGenerator
     11 * Helper class to access a protected method
    1212 * 
    1313 * @package     stubbles 
    14  * @subpackage  websites_xml_test 
     14 * @subpackage  websites_xml_skin_test 
     15 */ 
     16class 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 
    1533 */ 
    1634class stubSkinGeneratorTestCase extends PHPUnit_Framework_TestCase 
     
    6482     */ 
    6583    protected $resultDomDocument; 
     84    /** 
     85     * mocked injector instance 
     86     * 
     87     * @var  PHPUnit_Framework_MockObject_MockObject 
     88     */ 
     89    protected $mockInjector; 
    6690 
    6791    /** 
     
    7195    { 
    7296        $this->skinGenerator = $this->getMock('stubSkinGenerator', 
    73                                               array('setXIncludeProcessor', 
    74                                                     'createXSLProcessor', 
     97                                              array('createXSLProcessor', 
    7598                                                    'getCallbackList', 
    7699                                                    'createXMLSkinDocument' 
     
    87110        $this->mockXSLProcessor->expects($this->any())->method('transformToDoc')->will($this->returnValue($this->resultDomDocument)); 
    88111        $this->skinGenerator->expects($this->any())->method('createXSLProcessor')->will($this->returnValue($this->mockXSLProcessor)); 
    89         $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    90112        if (stubRegistry::hasConfig('net.stubbles.language') == true) { 
    91113            stubRegistry::setConfig('net.stubbles.language', null); 
    92114        } 
    93115         
    94         stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder()); 
     116        $this->mockInjector = $this->getMock('stubInjector'); 
     117        stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder($this->mockInjector)); 
    95118    } 
    96119 
     
    111134    { 
    112135        $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'))); 
    113139        $this->skinGenerator->expects($this->once()) 
    114140                            ->method('createXMLSkinDocument') 
    115141                            ->with($this->equalTo('default')) 
    116142                            ->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)); 
    119146 
    120147        $this->assertSame($this->resultDomDocument, $this->skinGenerator->generate($this->mockSession, $this->xmlResponse)); 
     
    129156    { 
    130157        $this->page->setProperty('skin', 'another'); 
     158        $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    131159        $this->skinGenerator->expects($this->once()) 
    132160                            ->method('createXMLSkinDocument') 
     
    144172    { 
    145173        stubRegistry::setConfig('net.stubbles.language', 'foo'); 
     174        $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    146175        $this->skinGenerator->expects($this->any()) 
    147176                            ->method('createXMLSkinDocument') 
     
    160189        $this->page->setProperty('language', 'bar'); 
    161190        stubRegistry::setConfig('net.stubbles.language', 'foo'); 
     191        $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    162192        $this->skinGenerator->expects($this->any()) 
    163193                            ->method('createXMLSkinDocument') 
     
    174204    public function sessionLanguage() 
    175205    { 
     206        $this->skinGenerator->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    176207        $this->skinGenerator->expects($this->any()) 
    177208                            ->method('createXMLSkinDocument') 
     
    196227        $this->skinGenerator->generate($this->mockSession, $this->xmlResponse); 
    197228    } 
     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    } 
    198253} 
    199254?>