Changeset 1256

Show
Ignore:
Timestamp:
01/18/08 01:35:03 (7 months ago)
Author:
mikey
Message:

continued refactoring #118: converted tests for net::stubbles::websites::cache and net::stubbles::websites::xml

Files:

Legend:

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

    r1253 r1256  
    6161    protected function getPageName() 
    6262    { 
    63         if ($this->request->hasValue('page') == true) { 
     63        if ($this->request->hasValue('page') === true) { 
    6464            $pageName = $this->request->getValidatedValue(new stubRegexValidator('/([a-zA-Z0-9_])/'), 'page'); 
    6565            if (null == $pageName || $this->pageFactory->hasPage($this->pageDirPrefix . $pageName) === false) { 
  • trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php

    r1231 r1256  
    5454    public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 
    5555    { 
    56         if ($request->hasValue('showLastRequestXML') == true && $session->isNew() == false) { 
     56        if ($request->hasValue('showLastRequestXML') === true && $session->isNew() === false) { 
    5757            $response->addHeader('Content-type', 'text/xml'); 
    5858            $response->write($session->getValue(self::SESSION_KEY)); 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php

    r1231 r1256  
    1212                      'net::stubbles::util::stubFactory', 
    1313                      'net::stubbles::util::stubRegistry', 
    14                       'net::stubbles::xml::xsl::stubXSLProcessor', 
     14                      'net::stubbles::websites::xml::stubXMLResponse', 
    1515                      'net::stubbles::xml::stubXMLXIncludeStreamWrapper', 
    16                       'net::stubbles::xml::stubXMLStreamWriterFactory' 
     16                      'net::stubbles::xml::stubXMLStreamWriterFactory', 
     17                      'net::stubbles::xml::xsl::stubXSLProcessor' 
    1718); 
    1819/** 
  • trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php

    r1248 r1256  
    4747    protected function doProcess(stubPage $page, $pageName) 
    4848    { 
    49         $pageName        = $this->getPageName('conf'); 
    5049        $xmlSerializer   = $this->createXMLSerializer(); 
    5150        $xmlStreamWriter = $this->createXMLStreamWriter(); 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r1253 r1256  
    4747 
    4848        // xml tests 
    49         /*$suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 
     49        $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 
    5050        $suite->addTestFile($dir . '/xml/stubXMLPostInterceptorTestCase.php'); 
    5151        $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 
    52         $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php');*/ 
     52        $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); 
    5353        return $suite; 
    5454    } 
  • trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php

    r1231 r1256  
    88 */ 
    99stubClassLoader::load('net::stubbles::websites::xml::stubShowLastXMLInterceptor'); 
    10 Mock::generate('stubRequest'); 
    11 Mock::generate('stubResponse'); 
    12 Mock::generate('stubSession'); 
    1310/** 
    1411 * Tests for net::stubbles::websites::xml::stubShowLastXMLInterceptor. 
     
    1714 * @subpackage  websites_xml_test 
    1815 */ 
    19 class stubShowLastXMLInterceptorTestCase extends UnitTestCase 
     16class stubShowLastXMLInterceptorTestCase extends PHPUnit_Framework_TestCase 
    2017{ 
    2118    /** 
     
    2825     * mocked response instance 
    2926     * 
    30      * @var  SimpleMock 
     27     * @var  PHPUnit_Framework_MockObject_MockObject 
    3128     */ 
    3229    protected $mockResponse; 
     
    3431     * mocked request instance 
    3532     * 
    36      * @var  SimpleMock 
     33     * @var  PHPUnit_Framework_MockObject_MockObject 
    3734     */ 
    3835    protected $mockRequest; 
     
    4037     * mocked session instance 
    4138     * 
    42      * @var  SimpleMock 
     39     * @var  PHPUnit_Framework_MockObject_MockObject 
    4340     */ 
    4441    protected $mockSession; 
     
    5047    { 
    5148        $this->showLastXMLPreInterceptor = new stubShowLastXMLInterceptor(); 
    52         $this->mockRequest               = new MockstubRequest(); 
    53         $this->mockResponse              = new MockstubResponse(); 
    54         $this->mockSession               = new MockstubSession(); 
     49        $this->mockRequest               = $this->getMock('stubRequest'); 
     50        $this->mockResponse              = $this->getMock('stubResponse'); 
     51        $this->mockSession               = $this->getMock('stubSession'); 
    5552    } 
    5653 
    5754    /** 
    5855     * assure that a new session does not trigger the interceptor 
     56     * 
     57     * @test 
    5958     */ 
    60     public function testSessionNew() 
     59    public function newSessionDoesNotTriggerInterceptor() 
    6160    { 
    62         $this->mockRequest->setReturnValue('hasValue', true); 
    63         $this->mockSession->setReturnValue('isNew', true); 
    64         $this->mockRequest->expectNever('cancel'); 
    65         $this->mockResponse->expectNever('write'); 
     61        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     62        $this->mockSession->expects($this->once())->method('isNew')->will($this->returnValue(true)); 
     63        $this->mockRequest->expects($this->never())->method('cancel'); 
     64        $this->mockResponse->expects($this->never())->method('write'); 
    6665        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    6766    } 
     
    6968    /** 
    7069     * assure that a request that does not force to show the last request xml does not trigger the interceptor 
     70     * 
     71     * @test 
    7172     */ 
    72     public function testRequestHasNotValue() 
     73    public function requestDoesNotHaveValueThatRequestsLastXML() 
    7374    { 
    74         $this->mockRequest->setReturnValue('hasValue', false); 
    75         $this->mockSession->setReturnValue('isNew', false); 
    76         $this->mockRequest->expectNever('cancel'); 
    77         $this->mockResponse->expectNever('write'); 
     75        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     76        $this->mockSession->expects($this->never())->method('isNew'); 
     77        $this->mockRequest->expects($this->never())->method('cancel'); 
     78        $this->mockResponse->expects($this->never())->method('write'); 
    7879        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    7980    } 
     
    8182    /** 
    8283     * assure that if all requirements are met the processor is executed 
     84     * 
     85     * @test 
    8386     */ 
    84     public function testAllOk() 
     87    public function allOk() 
    8588    { 
    86         $this->mockRequest->setReturnValue('hasValue', true); 
    87         $this->mockSession->setReturnValue('isNew', false); 
    88         $this->mockSession->setReturnValue('getValue', 'foo'); 
    89         $this->mockRequest->expectOnce('cancel'); 
    90         $this->mockResponse->expect('write', array('foo')); 
     89        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     90        $this->mockSession->expects($this->once())->method('isNew')->will($this->returnValue(false)); 
     91        $this->mockSession->expects($this->once())->method('getValue')->will($this->returnValue('foo')); 
     92        $this->mockRequest->expects($this->once())->method('cancel'); 
     93        $this->mockResponse->expects($this->once())->method('write')->with($this->equalTo('foo')); 
    9194        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    9295    } 
     
    9598     * assure that postProcess() puts correct data into session 
    9699     * 
     100     * @test 
    97101     */ 
    98     public function testPostProcess() 
     102    public function postProcess() 
    99103    { 
    100         $this->mockResponse->setReturnValue('getData', 'foo'); 
    101         $this->mockSession->expect('putValue', array(stubShowLastXMLInterceptor::SESSION_KEY, 'foo')); 
     104        $this->mockResponse->expects($this->once())->method('getData')->will($this->returnValue('foo')); 
     105        $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo')); 
    102106        $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    103107    } 
  • trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php

    r1231 r1256  
    88 */ 
    99stubClassLoader::load('net::stubbles::websites::xml::stubXMLPostInterceptor'); 
    10 Mock::generate('stubRequest'); 
    11 Mock::generate('stubSession'); 
    12 Mock::generate('stubSession'); 
    13 Mock::generate('stubXSLProcessor'); 
    14 Mock::generatePartial('stubXMLPostInterceptor', 'stubTestXMLPostInterceptor', array('setXIncludeProcessor', 'createXSLProcessor', 'getCallbackList', 'createXSLStylesheet', 'createXMLSkinDocument')); 
    1510class TestDOMDocument extends DOMDocument 
    1611{ 
     
    2318 * @subpackage  websites_xml_test 
    2419 */ 
    25 class stubXMLPostInterceptorTestCase extends UnitTestCase 
     20class stubXMLPostInterceptorTestCase extends PHPUnit_Framework_TestCase 
    2621{ 
    2722    /** 
     
    4035     * mocked request instance 
    4136     * 
    42      * @var  SimpleMock 
     37     * @var  PHPUnit_Framework_MockObject_MockObject 
    4338     */ 
    4439    protected $mockRequest; 
     
    4641     * mocked response instance 
    4742     * 
    48      * @var  SimpleMock 
     43     * @var  PHPUnit_Framework_MockObject_MockObject 
    4944     */ 
    5045    protected $mockResponse; 
     
    5853     * mocked session instance 
    5954     * 
    60      * @var  SimpleMock 
     55     * @var  PHPUnit_Framework_MockObject_MockObject 
    6156     */ 
    6257    protected $mockSession; 
     
    6459     * mocked xsl processor 
    6560     * 
    66      * @var  SimpleMock 
     61     * @var  PHPUnit_Framework_MockObject_MockObject 
    6762     */ 
    6863    protected $mockXSLProcessor; 
     
    7065     * mocked image callback 
    7166     * 
    72      * @var  SimpleMock 
     67     * @var  PHPUnit_Framework_MockObject_MockObject 
    7368     */ 
    7469    protected $mockImageCallback; 
     
    7974    public function setUp() 
    8075    { 
    81         $this->xmlPostInterceptor = new stubTestXMLPostInterceptor(); 
    82         $this->mockRequest        = new MockstubRequest(); 
    83         $this->mockResponse       = new MockstubResponse(); 
    84         $this->mockResponse->setReturnValue('getData', '<foo>bar</foo>'); 
     76        $this->xmlPostInterceptor = $this->getMock('stubXMLPostInterceptor', 
     77                                                   array('setXIncludeProcessor', 
     78                                                         'createXSLProcessor', 
     79                                                         'getCallbackList', 
     80                                                        /* 'createXSLStylesheet',*/ 
     81                                                         'createXMLSkinDocument' 
     82                                                   ) 
     83                                    ); 
     84        $this->mockRequest        = $this->getMock('stubRequest'); 
     85        $this->mockResponse       = $this->getMock('stubResponse'); 
     86        $this->mockResponse->expects($this->any())->method('getData')->will($this->returnValue('<foo>bar</foo>')); 
    8587        $this->xmlResponse        = new stubXMLResponse($this->mockResponse); 
    8688        $this->page               = new stubPage(); 
    8789        $this->xmlResponse->setPage($this->page); 
    88         $this->mockSession        = new MockstubSession(); 
    89         $this->mockXSLProcessor   = new MockstubXSLProcessor(); 
     90        $this->mockSession        = $this->getMock('stubSession'); 
     91        $this->mockXSLProcessor   = $this->getMock('stubXSLProcessor'); 
    9092        $domDocument = new DOMDocument(); 
    9193        $domDocument->createElement('bar', 'foo'); 
    92         $this->mockXSLProcessor->setReturnValue('transformToDoc', $domDocument); 
    93         $this->mockXSLProcessor->setReturnValue('transformToXML', '<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>'); 
    94         $this->xmlPostInterceptor->setReturnValue('createXSLProcessor', $this->mockXSLProcessor); 
    95         $this->xmlPostInterceptor->setReturnValue('getCallbackList', array()); 
     94        $this->mockXSLProcessor->expects($this->any())->method('transformToDoc')->will($this->returnValue($domDocument)); 
     95        $this->mockXSLProcessor->expects($this->any())->method('transformToXML')->will($this->returnValue('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
     96        $this->xmlPostInterceptor->expects($this->any())->method('createXSLProcessor')->will($this->returnValue($this->mockXSLProcessor)); 
     97        $this->xmlPostInterceptor->expects($this->any())->method('getCallbackList')->will($this->returnValue(array())); 
    9698        if (stubRegistry::hasConfig('net.stubbles.language') == true) { 
    9799            stubRegistry::setConfig('net.stubbles.language', null); 
    98100        } 
    99101         
    100         stubRegistry::set('net.stubbles.ioc.stubBinder', new stubBinder()); 
     102        stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder()); 
    101103    } 
    102104 
     
    106108    public function tearDown() 
    107109    { 
    108         stubRegistry::remove('net.stubbles.ioc.stubBinder'); 
     110        stubRegistry::remove(stubBinder::REGISTRY_KEY); 
    109111    } 
    110112 
    111113    /** 
    112114     * assure that a wrong response does not trigger any action 
    113      */ 
    114     public function testWrongResponse() 
     115     * 
     116     * @test 
     117     */ 
     118    public function wrongResponse() 
    115119    { 
    116120        $this->assertFalse($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse)); 
     
    119123    /** 
    120124     * assure that a correct response works as expected 
    121      */ 
    122     public function testCorrectResponse() 
     125     * 
     126     * @test 
     127     */ 
     128    public function correctResponse() 
    123129    { 
    124130        $this->page->setProperty('name', 'baz'); 
    125         $this->xmlPostInterceptor->expect('createXMLSkinDocument', array('default')); 
    126         $this->mockXSLProcessor->expectAt(0, 'setParameter', array('', 'page', 'baz')); 
    127         $this->mockXSLProcessor->expectAt(1, 'setParameter', array('', 'lang', 'en_EN')); 
    128         $this->mockResponse->expect('replaceData', array('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
     131        $this->xmlPostInterceptor->expects($this->once()) 
     132                                 ->method('createXMLSkinDocument') 
     133                                 ->with($this->equalTo('default')) 
     134                                 ->will($this->returnValue($this->getMock('DOMDocument'))); 
     135        $this->mockXSLProcessor->expects($this->at(1))->method('setParameter')->with($this->equalTo(''), $this->equalTo('page'), $this->equalTo('baz')); 
     136        $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('en_EN')); 
     137        $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 
    129138        $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 
    130139    } 
     
    132141    /** 
    133142     * assure that another skin will be used 
    134      */ 
    135     public function testSkin() 
     143     * 
     144     * @test 
     145     */ 
     146    public function skin() 
    136147    { 
    137148        $this->page->setProperty('skin', 'another'); 
    138         $this->xmlPostInterceptor->expect('createXMLSkinDocument', array('another')); 
     149        $this->xmlPostInterceptor->expects($this->once()) 
     150                                 ->method('createXMLSkinDocument') 
     151                                 ->with($this->equalTo('another')) 
     152                                 ->will($this->returnValue($this->getMock('DOMDocument'))); 
    139153        $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 
    140154    } 
     
    142156    /** 
    143157     * assure that the language value from the registry is taken 
    144      */ 
    145     public function testRegistryLanguage() 
     158     * 
     159     * @test 
     160     */ 
     161    public function registryLanguage() 
    146162    { 
    147163        stubRegistry::setConfig('net.stubbles.language', 'foo'); 
    148         $this->mockXSLProcessor->expectAt(1, 'setParameter', array('', 'lang', 'foo')); 
     164        $this->xmlPostInterceptor->expects($this->any()) 
     165                                 ->method('createXMLSkinDocument') 
     166                                 ->will($this->returnValue($this->getMock('DOMDocument'))); 
     167        $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('foo')); 
    149168        $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 
    150169    } 
     
    152171    /** 
    153172     * assure that the language value from the page is taken 
    154      */ 
    155     public function testPageLanguage() 
     173     * 
     174     * @test 
     175     */ 
     176    public function pageLanguage() 
    156177    { 
    157178        $this->page->setProperty('language', 'bar'); 
    158179        stubRegistry::setConfig('net.stubbles.language', 'foo'); 
    159         $this->mockXSLProcessor->expectAt(1, 'setParameter', array('', 'lang', 'bar')); 
     180        $this->xmlPostInterceptor->expects($this->any()) 
     181                                 ->method('createXMLSkinDocument') 
     182                                 ->will($this->returnValue($this->getMock('DOMDocument'))); 
     183        $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('bar')); 
    160184        $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 
    161185    } 
     
    163187    /** 
    164188     * assure that the language value from the session is taken 
    165      */ 
    166     public function testSessionLanguage() 
    167     { 
    168         $this->mockSession->setReturnValue('hasValue', true); 
    169         $this->mockSession->setReturnValue('getValue', 'baz'); 
     189     * 
     190     * @test 
     191     */ 
     192    public function sessionLanguage() 
     193    { 
     194        $this->xmlPostInterceptor->expects($this->any()) 
     195                                 ->method('createXMLSkinDocument') 
     196                                 ->will($this->returnValue($this->getMock('DOMDocument'))); 
     197        $this->mockSession->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     198        $this->mockSession->expects($this->once())->method('getValue')->will($this->returnValue('baz')); 
    170199        $this->page->setProperty('language', 'bar'); 
    171200        stubRegistry::setConfig('net.stubbles.language', 'foo'); 
    172         $this->mockXSLProcessor->expectAt(1, 'setParameter', array('', 'lang', 'baz')); 
     201        $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('baz')); 
    173202        $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 
    174203    } 
     
    176205    /** 
    177206     * assure that missing binder triggers an exception 
    178      */ 
    179     public function testWithoutBinderInRegistry() 
    180     { 
    181         stubRegistry::remove('net.stubbles.ioc.stubBinder'); 
    182         $this->expectException('stubRuntimeException'); 
     207     * 
     208     * @test 
     209     * @expectedException  stubRuntimeException 
     210     */ 
     211    public function withoutBinderInRegistry() 
     212    { 
     213        stubRegistry::remove(stubBinder::REGISTRY_KEY); 
    183214        $this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse); 
    184215    } 
  • trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php

    r1231 r1256  
    88 */ 
    99stubClassLoader::load('net::stubbles::websites::xml::stubXMLProcessor'); 
    10 Mock::generate('stubRequest'); 
    11 Mock::generate('stubSession'); 
    12 Mock::generate('stubPageElement'); 
    13 Mock::generate('stubPageFactory'); 
    14 Mock::generate('stubXMLStreamWriter'); 
    15 Mock::generate('stubXMLSerializer'); 
    16 class PartialMockstubXMLProcessor extends stubXMLProcessor 
     10/** 
     11 * Helper class for the test. 
     12 * 
     13 * @package     stubbles 
     14 * @subpackage  websites_xml_test 
     15 */ 
     16class TeststubXMLProcessor extends stubXMLProcessor 
    1717{ 
     18    /** 
     19     * xml stream writer instance to be used 
     20     * 
     21     * @var  stubXMLStreamWriter 
     22     */ 
    1823    protected $xmlStreamWriter; 
     24    /** 
     25     * xml serializer instance to be used 
     26     * 
     27     * @var  stubXMLSerializer 
     28     */ 
    1929    protected $xmlSerializer; 
    20      
     30 
     31    /** 
     32     * sets the xml stream writer instance to be used 
     33     * 
     34     * @param  stubXMLStreamWriter  $xmlStreamWriter 
     35     */ 
    2136    public function setXMLStreamWriter($xmlStreamWriter) 
    2237    { 
    2338        $this->xmlStreamWriter = $xmlStreamWriter; 
    2439    } 
    25      
     40 
     41    /** 
     42     * sets the  xml serializer instance to be used 
     43     * 
     44     * @param  stubXMLSerializer  $xmlSerializer 
     45     */ 
    2646    public function setXMLSerializer($xmlSerializer) 
    2747    { 
    2848        $this->xmlSerializer = $xmlSerializer; 
    2949    } 
    30      
     50 
     51    /** 
     52     * returns a xml stream writer 
     53     * 
     54     * @return  stubXMLStreamWriter 
     55     */ 
    3156    protected function createXMLStreamWriter() 
    3257    { 
    3358        return $this->xmlStreamWriter; 
    3459    } 
    35      
     60 
     61    /** 
     62     * returns the xml serializer 
     63     * 
     64     * @return  stubXMLSerializer 
     65     */ 
    3666    protected function createXMLSerializer() 
    3767    { 
     
    4575 * @subpackage  websites_xml_test 
    4676 */ 
    47 class stubXMLProcessorTestCase extends UnitTestCase 
     77class stubXMLProcessorTestCase extends PHPUnit_Framework_TestCase 
    4878{ 
    4979    /** 
    5080     * instance to be used for tests 
    5181     * 
    52      * @var  stubXMLProcessor 
     82     * @var  TeststubXMLProcessor 
    5383     */ 
    5484    protected $xmlProcessor; 
     
    5686     * mocked request instance 
    5787     * 
    58      * @var  SimpleMock 
     88     * @var  PHPUnit_Framework_MockObject_MockObject 
    5989     */ 
    6090    protected $mockRequest; 
     
    6292     * mocked session instance 
    6393     * 
    64      * @var  SimpleMock 
     94     * @var  PHPUnit_Framework_MockObject_MockObject 
    6595     */ 
    6696    protected $mockSession; 
     
    6898     * mocked response instance 
    6999     * 
    70      * @var  SimpleMock 
     100     * @var  PHPUnit_Framework_MockObject_MockObject 
    71101     */ 
    72102    protected $mockResponse; 
     
    74104     * mocked page factory instance 
    75105     * 
    76      * @var  SimpleMock 
     106     * @var  PHPUnit_Framework_MockObject_MockObject 
    77107     */ 
    78108    protected $mockPageFactory; 
     
    80110     * mocked xml stream writer instance 
    81111     * 
    82      * @var  SimpleMock 
     112     * @var  PHPUnit_Framework_MockObject_MockObject 
    83113     */ 
    84114    protected $mockXMLStreamWriter; 
     
    86116     * mocked xml serializer instance 
    87117     * 
    88      * @var  SimpleMock 
     118     * @var  PHPUnit_Framework_MockObject_MockObject 
    89119     */ 
    90120    protected $mockXMLSerializer; 
     
    95125     */ 
    96126    protected $page; 
    97      
     127 
    98128    /** 
    99129     * set up test environment 
     
    101131    public function setUp() 
    102132    { 
    103         $this->mockRequest         = new MockstubRequest(); 
    104         $this->mockRequest->setReturnValue('getValueErrors', array()); 
    105         $this->mockSession         = new MockstubSession(); 
    106         $this->mockResponse        = new MockstubResponse(); 
    107         $this->mockPageFactory     = new MockstubPageFactory(); 
    108         $this->xmlProcessor        = new PartialMockstubXMLProcessor($this->mockRequest, $this->mockSession, $this->mockResponse, $this->mockPageFactory); 
    109         $this->mockXMLStreamWriter = new MockstubXMLStreamWriter(); 
    110         $this->mockXMLSerializer   = new MockstubXMLSerializer(); 
     133        $this->mockRequest         = $this->getMock('stubRequest'); 
     134        $this->mockRequest->expects($this->any())->method('getValueErrors')->will($this->returnValue(array())); 
     135        $this->mockSession         = $this->getMock('stubSession'); 
     136        $this->mockResponse        = $this->getMock('stubResponse'); 
     137        $this->mockPageFactory     = $this->getMock('stubPageFactory'); 
     138        $this->xmlProcessor        = new TeststubXMLProcessor($this->mockRequest, $this->mockSession, $this->mockResponse, $this->mockPageFactory); 
     139        $this->mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 
     140        $this->mockXMLSerializer   = $this->getMock('stubXMLSerializer'); 
    111141        $this->xmlProcessor->setXMLStreamWriter($this->mockXMLStreamWriter); 
    112142        $this->xmlProcessor->setXMLSerializer($this->mockXMLSerializer); 
    113143        $this->page = new stubPage(); 
    114         $this->mockPageFactory->setReturnValue('getPage', $this->page); 
    115     } 
    116      
     144        $this->mockPageFactory->expects($this->any())->method('getPage')->will($this->returnValue($this->page)); 
     145    } 
     146 
    117147    /** 
    118148     * assure that processing works as expected 
    119      */ 
    120     public function testDefaultPageWithoutElements() 
    121     { 
    122         $this->mockRequest->setReturnValue('hasValue', false); 
    123         $this->mockPageFactory->expectOnce('getPage', array('conf/index')); 
    124         $this->mockXMLStreamWriter->expectCallcount('writeStartElement', 4); 
    125         $this->mockXMLStreamWriter->expectCallcount('writeEndElement', 4); 
    126         $this->mockXMLSerializer->expectOnce('serialize'); 
     149     * 
     150     * @test 
     151     */ 
     152    public function defaultPageWithoutElements() 
     153    { 
     154        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(false)); 
     155        $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index')); 
     156        $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeStartElement'); 
     157        $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeEndElement'); 
     158        $this->mockXMLSerializer->expects($this->once())->method('serialize'); 
    127159        $return = $this->xmlProcessor->process(); 
    128         $this->assertReference($this->xmlProcessor, $return); 
     160        $this->assertSame($this->xmlProcessor, $return); 
    129161        $response = $this->xmlProcessor->getResponse(); 
    130         $this->assertIsA($response, 'stubResponse'); 
    131     } 
    132      
     162        $this->assertType('stubResponse', $response); 
     163    } 
     164 
    133165    /** 
    134166     * assure that processing works as expected 
    135      */ 
    136     public function testFallbackToDefaultPageWithElements() 
    137     { 
    138         $this->mockRequest->setReturnValue('hasValue', true); 
    139         $this->mockRequest->setReturnValue('getValidatedValue', null); 
    140         $this->mockPageFactory->expectOnce('getPage', array('conf/index')); 
    141         $response = $this->xmlProcessor->getResponse(); 
    142         $pageElement1 = new MockstubPageElement(); 
    143         $pageElement1->setReturnValue('getName', 'foo'); 
    144         $pageElement1->setReturnValue('process', 'foo'); 
    145         $pageElement1->setReturnValue('isAvailable', true); 
    146         $pageElement1->expectOnce('process'); 
    147         $pageElement2 = new MockstubPageElement(); 
    148         $pageElement2->setReturnValue('getName', 'bar'); 
    149         $pageElement2->setReturnValue('process', 'bar'); 
    150         $pageElement2->setReturnValue('isAvailable', true); 
    151         $pageElement2->expectOnce('process'); 
    152         $pageElement3 = new MockstubPageElement(); 
    153         $pageElement3->setReturnValue('getName', 'baz'); 
    154         $pageElement3->setReturnValue('process', 'baz'); 
    155         $pageElement3->setReturnValue('isAvailable', false); 
    156         $pageElement3->expectNever('process'); 
     167     * 
     168     * @test 
     169     */ 
     170    public function fallbackToDefaultPageWithElements() 
     171    { 
     172        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     173        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue(null)); 
     174        $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index')); 
     175        $pageElement1 = $this->getMock('stubPageElement'); 
     176        $pageElement1->expects($this->any())->method('getName')->will($this->returnValue('foo')); 
     177        $pageElement1->expects($this->once())->method('process')->will($this->returnValue('foo')); 
     178        $pageElement1->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); 
     179        $pageElement2 = $this->getMock('stubPageElement'); 
     180        $pageElement2->expects($this->any())->method('getName')->will($this->returnValue('bar')); 
     181        $pageElement2->expects($this->once())->method('process')->will($this->returnValue('bar')); 
     182        $pageElement2->expects($this->once())->method('isAvailable')->will($this->returnValue(true)); 
     183        $pageElement3 = $this->getMock('stubPageElement'); 
     184        $pageElement3->expects($this->any())->method('getName')->will($this->returnValue('baz')); 
     185        $pageElement3->expects($this->never())->method('process'); 
     186        $pageElement3->expects($this->once())->method('isAvailable')->will($this->returnValue(false)); 
    157187        $this->page->addElement($pageElement1); 
    158188        $this->page->addElement($pageElement2); 
    159189        $this->page->addElement($pageElement3); 
    160         $this->mockXMLStreamWriter->expectCallcount('writeStartElement', 4); 
    161         $this->mockXMLStreamWriter->expectCallcount('writeEndElement', 4); 
    162         $this->mockXMLSerializer->expectAt(0, 'serialize', array('foo', $this->mockXMLStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => 'foo'))); 
    163         $this->mockXMLSerializer->expectAt(1, 'serialize', array('bar', $this->mockXMLStreamWriter, array(stubXMLSerializer::OPT_ROOT_TAG => 'bar'))); 
     190        $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeStartElement'); 
     191        $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeEndElement'); 
     192        $this->mockXMLSerializer->expects($this->at(0)) 
     193                                ->method('serialize') 
     194                                ->with($this->equalTo('foo'), 
     195                                       $this->equalTo($this->mockXMLStreamWriter), 
     196                                       $this->equalTo(array(stubXMLSerializer::OPT_ROOT_TAG => 'foo')) 
     197                                  ); 
     198        $this->mockXMLSerializer->expects($this->at(1)) 
     199                                ->method('serialize') 
     200                                ->with($this->equalTo('bar'), 
     201                                       $this->equalTo($this->mockXMLStreamWriter), 
     202                                       $this->equalTo(array(stubXMLSerializer::OPT_ROOT_TAG => 'bar')) 
     203                                  ); 
    164204        $return = $this->xmlProcessor->process(); 
    165         $this->assertReference($this->xmlProcessor, $return); 
     205        $this->assertSame($this->xmlProcessor, $return); 
    166206        $response = $this->xmlProcessor->getResponse(); 
    167         $this->assertIsA($response, 'stubResponse'); 
    168     } 
    169      
     207        $this->assertType('stubResponse', $response); 
     208    } 
     209 
    170210    /** 
    171211     * assure that processing works as expected 
    172      */ 
    173     public function testCorrectPage() 
    174     { 
    175         $this->mockRequest->setReturnValue('hasValue', true); 
    176         $this->mockRequest->setReturnValue('getValidatedValue', 'baz'); 
    177         $this->mockPageFactory->expectOnce('getPage', array('conf/baz')); 
    178         $this->mockPageFactory->setReturnValue('hasPage', true); 
     212     * 
     213     * @test 
     214     */ 
     215    public function correctPage() 
     216    { 
     217        $this->mockRequest->expects($this->once())->method('hasValue')->will($this->returnValue(true)); 
     218        $this->mockRequest->expects($this->once())->method('getValidatedValue')->will($this->returnValue('baz')); 
     219        $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/baz')); 
     220        $this->mockPageFactory->expects($this->once())->method('hasPage')->will($this->returnValue(true)); 
    179221        $this->xmlProcessor->process(); 
    180222    } 
  • trunk/src/test/php/net/stubbles/websites/xml/stubXMLResponseTestCase.php

    r1231 r1256  
    88 */ 
    99stubClassLoader::load('net::stubbles::websites::xml::stubXMLResponse'); 
    10 Mock::generate('stubResponse'); 
     10 
    1111/** 
    1212 * Tests for net::stubbles::websites::xml::stubXMLResponse. 
     
    1515 * @subpackage  websites_xml_test 
    1616 */ 
    17 class stubXMLResponseTestCase extends UnitTestCase 
     17class stubXMLResponseTestCase extends PHPUnit_Framework_TestCase 
    1818{ 
    1919    /** 
     
    2626     * mocked response instance 
    2727     * 
    28      * @var  SimpleMock 
     28     * @var  PHPUnit_Framework_MockObject_MockObject 
    2929     */ 
    3030    protected $mockResponse; 
     
    3535    public function setUp() 
    3636    { 
    37         $this->mockResponse = new MockstubResponse(); 
     37        $this->mockResponse = $this->getMock('stubResponse'); 
    3838        $this->xmlResponse  = new stubXMLResponse($this->mockResponse); 
    3939    } 
     
    4141    /** 
    4242     * assure that page is handled correct 
     43     * 
     44     * @test 
    4345     */ 
    44     public function testPage() 
     46    public function page() 
    4547    { 
    4648        $this->assertNull($this->xmlResponse->getPage()); 
     
    4850        $this->xmlResponse->setPage($page); 
    4951        $page2 = $this->xmlResponse->getPage(); 
    50         $this->assertEqual($page2, $page); 
     52        $this->assertSame($page, $page2); 
    5153        $this->xmlResponse->clear(); 
    5254        $this->assertNull($this->xmlResponse->getPage());