Changeset 1256
- Timestamp:
- 01/18/08 01:35:03 (7 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/processors/stubAbstractPageProcessor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php (modified) (9 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php (modified) (15 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLResponseTestCase.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/processors/stubAbstractPageProcessor.php
r1253 r1256 61 61 protected function getPageName() 62 62 { 63 if ($this->request->hasValue('page') == true) {63 if ($this->request->hasValue('page') === true) { 64 64 $pageName = $this->request->getValidatedValue(new stubRegexValidator('/([a-zA-Z0-9_])/'), 'page'); 65 65 if (null == $pageName || $this->pageFactory->hasPage($this->pageDirPrefix . $pageName) === false) { trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php
r1231 r1256 54 54 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 55 55 { 56 if ($request->hasValue('showLastRequestXML') == true && $session->isNew()== false) {56 if ($request->hasValue('showLastRequestXML') === true && $session->isNew() === false) { 57 57 $response->addHeader('Content-type', 'text/xml'); 58 58 $response->write($session->getValue(self::SESSION_KEY)); trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php
r1231 r1256 12 12 'net::stubbles::util::stubFactory', 13 13 'net::stubbles::util::stubRegistry', 14 'net::stubbles:: xml::xsl::stubXSLProcessor',14 'net::stubbles::websites::xml::stubXMLResponse', 15 15 'net::stubbles::xml::stubXMLXIncludeStreamWrapper', 16 'net::stubbles::xml::stubXMLStreamWriterFactory' 16 'net::stubbles::xml::stubXMLStreamWriterFactory', 17 'net::stubbles::xml::xsl::stubXSLProcessor' 17 18 ); 18 19 /** trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1248 r1256 47 47 protected function doProcess(stubPage $page, $pageName) 48 48 { 49 $pageName = $this->getPageName('conf');50 49 $xmlSerializer = $this->createXMLSerializer(); 51 50 $xmlStreamWriter = $this->createXMLStreamWriter(); trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r1253 r1256 47 47 48 48 // xml tests 49 /*$suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php');49 $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 50 50 $suite->addTestFile($dir . '/xml/stubXMLPostInterceptorTestCase.php'); 51 51 $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 52 $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); */52 $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); 53 53 return $suite; 54 54 } trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php
r1231 r1256 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::xml::stubShowLastXMLInterceptor'); 10 Mock::generate('stubRequest');11 Mock::generate('stubResponse');12 Mock::generate('stubSession');13 10 /** 14 11 * Tests for net::stubbles::websites::xml::stubShowLastXMLInterceptor. … … 17 14 * @subpackage websites_xml_test 18 15 */ 19 class stubShowLastXMLInterceptorTestCase extends UnitTestCase16 class stubShowLastXMLInterceptorTestCase extends PHPUnit_Framework_TestCase 20 17 { 21 18 /** … … 28 25 * mocked response instance 29 26 * 30 * @var SimpleMock27 * @var PHPUnit_Framework_MockObject_MockObject 31 28 */ 32 29 protected $mockResponse; … … 34 31 * mocked request instance 35 32 * 36 * @var SimpleMock33 * @var PHPUnit_Framework_MockObject_MockObject 37 34 */ 38 35 protected $mockRequest; … … 40 37 * mocked session instance 41 38 * 42 * @var SimpleMock39 * @var PHPUnit_Framework_MockObject_MockObject 43 40 */ 44 41 protected $mockSession; … … 50 47 { 51 48 $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'); 55 52 } 56 53 57 54 /** 58 55 * assure that a new session does not trigger the interceptor 56 * 57 * @test 59 58 */ 60 public function testSessionNew()59 public function newSessionDoesNotTriggerInterceptor() 61 60 { 62 $this->mockRequest-> setReturnValue('hasValue', true);63 $this->mockSession-> setReturnValue('isNew', true);64 $this->mockRequest->expect Never('cancel');65 $this->mockResponse->expect Never('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'); 66 65 $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 67 66 } … … 69 68 /** 70 69 * assure that a request that does not force to show the last request xml does not trigger the interceptor 70 * 71 * @test 71 72 */ 72 public function testRequestHasNotValue()73 public function requestDoesNotHaveValueThatRequestsLastXML() 73 74 { 74 $this->mockRequest-> setReturnValue('hasValue', false);75 $this->mockSession-> setReturnValue('isNew', false);76 $this->mockRequest->expect Never('cancel');77 $this->mockResponse->expect Never('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'); 78 79 $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 79 80 } … … 81 82 /** 82 83 * assure that if all requirements are met the processor is executed 84 * 85 * @test 83 86 */ 84 public function testAllOk()87 public function allOk() 85 88 { 86 $this->mockRequest-> setReturnValue('hasValue', true);87 $this->mockSession-> setReturnValue('isNew', false);88 $this->mockSession-> setReturnValue('getValue', 'foo');89 $this->mockRequest->expect Once('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')); 91 94 $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 92 95 } … … 95 98 * assure that postProcess() puts correct data into session 96 99 * 100 * @test 97 101 */ 98 public function testPostProcess()102 public function postProcess() 99 103 { 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')); 102 106 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 103 107 } trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php
r1231 r1256 8 8 */ 9 9 stubClassLoader::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'));15 10 class TestDOMDocument extends DOMDocument 16 11 { … … 23 18 * @subpackage websites_xml_test 24 19 */ 25 class stubXMLPostInterceptorTestCase extends UnitTestCase20 class stubXMLPostInterceptorTestCase extends PHPUnit_Framework_TestCase 26 21 { 27 22 /** … … 40 35 * mocked request instance 41 36 * 42 * @var SimpleMock37 * @var PHPUnit_Framework_MockObject_MockObject 43 38 */ 44 39 protected $mockRequest; … … 46 41 * mocked response instance 47 42 * 48 * @var SimpleMock43 * @var PHPUnit_Framework_MockObject_MockObject 49 44 */ 50 45 protected $mockResponse; … … 58 53 * mocked session instance 59 54 * 60 * @var SimpleMock55 * @var PHPUnit_Framework_MockObject_MockObject 61 56 */ 62 57 protected $mockSession; … … 64 59 * mocked xsl processor 65 60 * 66 * @var SimpleMock61 * @var PHPUnit_Framework_MockObject_MockObject 67 62 */ 68 63 protected $mockXSLProcessor; … … 70 65 * mocked image callback 71 66 * 72 * @var SimpleMock67 * @var PHPUnit_Framework_MockObject_MockObject 73 68 */ 74 69 protected $mockImageCallback; … … 79 74 public function setUp() 80 75 { 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>')); 85 87 $this->xmlResponse = new stubXMLResponse($this->mockResponse); 86 88 $this->page = new stubPage(); 87 89 $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'); 90 92 $domDocument = new DOMDocument(); 91 93 $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())); 96 98 if (stubRegistry::hasConfig('net.stubbles.language') == true) { 97 99 stubRegistry::setConfig('net.stubbles.language', null); 98 100 } 99 101 100 stubRegistry::set( 'net.stubbles.ioc.stubBinder', new stubBinder());102 stubRegistry::set(stubBinder::REGISTRY_KEY, new stubBinder()); 101 103 } 102 104 … … 106 108 public function tearDown() 107 109 { 108 stubRegistry::remove( 'net.stubbles.ioc.stubBinder');110 stubRegistry::remove(stubBinder::REGISTRY_KEY); 109 111 } 110 112 111 113 /** 112 114 * assure that a wrong response does not trigger any action 113 */ 114 public function testWrongResponse() 115 * 116 * @test 117 */ 118 public function wrongResponse() 115 119 { 116 120 $this->assertFalse($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse)); … … 119 123 /** 120 124 * assure that a correct response works as expected 121 */ 122 public function testCorrectResponse() 125 * 126 * @test 127 */ 128 public function correctResponse() 123 129 { 124 130 $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>')); 129 138 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 130 139 } … … 132 141 /** 133 142 * assure that another skin will be used 134 */ 135 public function testSkin() 143 * 144 * @test 145 */ 146 public function skin() 136 147 { 137 148 $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'))); 139 153 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 140 154 } … … 142 156 /** 143 157 * assure that the language value from the registry is taken 144 */ 145 public function testRegistryLanguage() 158 * 159 * @test 160 */ 161 public function registryLanguage() 146 162 { 147 163 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')); 149 168 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 150 169 } … … 152 171 /** 153 172 * assure that the language value from the page is taken 154 */ 155 public function testPageLanguage() 173 * 174 * @test 175 */ 176 public function pageLanguage() 156 177 { 157 178 $this->page->setProperty('language', 'bar'); 158 179 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')); 160 184 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 161 185 } … … 163 187 /** 164 188 * 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')); 170 199 $this->page->setProperty('language', 'bar'); 171 200 stubRegistry::setConfig('net.stubbles.language', 'foo'); 172 $this->mockXSLProcessor->expect At(1, 'setParameter', array('', 'lang','baz'));201 $this->mockXSLProcessor->expects($this->at(2))->method('setParameter')->with($this->equalTo(''), $this->equalTo('lang'), $this->equalTo('baz')); 173 202 $this->assertTrue($this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse)); 174 203 } … … 176 205 /** 177 206 * 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); 183 214 $this->xmlPostInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->xmlResponse); 184 215 } trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php
r1231 r1256 8 8 */ 9 9 stubClassLoader::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 stubXMLProcessor10 /** 11 * Helper class for the test. 12 * 13 * @package stubbles 14 * @subpackage websites_xml_test 15 */ 16 class TeststubXMLProcessor extends stubXMLProcessor 17 17 { 18 /** 19 * xml stream writer instance to be used 20 * 21 * @var stubXMLStreamWriter 22 */ 18 23 protected $xmlStreamWriter; 24 /** 25 * xml serializer instance to be used 26 * 27 * @var stubXMLSerializer 28 */ 19 29 protected $xmlSerializer; 20 30 31 /** 32 * sets the xml stream writer instance to be used 33 * 34 * @param stubXMLStreamWriter $xmlStreamWriter 35 */ 21 36 public function setXMLStreamWriter($xmlStreamWriter) 22 37 { 23 38 $this->xmlStreamWriter = $xmlStreamWriter; 24 39 } 25 40 41 /** 42 * sets the xml serializer instance to be used 43 * 44 * @param stubXMLSerializer $xmlSerializer 45 */ 26 46 public function setXMLSerializer($xmlSerializer) 27 47 { 28 48 $this->xmlSerializer = $xmlSerializer; 29 49 } 30 50 51 /** 52 * returns a xml stream writer 53 * 54 * @return stubXMLStreamWriter 55 */ 31 56 protected function createXMLStreamWriter() 32 57 { 33 58 return $this->xmlStreamWriter; 34 59 } 35 60 61 /** 62 * returns the xml serializer 63 * 64 * @return stubXMLSerializer 65 */ 36 66 protected function createXMLSerializer() 37 67 { … … 45 75 * @subpackage websites_xml_test 46 76 */ 47 class stubXMLProcessorTestCase extends UnitTestCase77 class stubXMLProcessorTestCase extends PHPUnit_Framework_TestCase 48 78 { 49 79 /** 50 80 * instance to be used for tests 51 81 * 52 * @var stubXMLProcessor82 * @var TeststubXMLProcessor 53 83 */ 54 84 protected $xmlProcessor; … … 56 86 * mocked request instance 57 87 * 58 * @var SimpleMock88 * @var PHPUnit_Framework_MockObject_MockObject 59 89 */ 60 90 protected $mockRequest; … … 62 92 * mocked session instance 63 93 * 64 * @var SimpleMock94 * @var PHPUnit_Framework_MockObject_MockObject 65 95 */ 66 96 protected $mockSession; … … 68 98 * mocked response instance 69 99 * 70 * @var SimpleMock100 * @var PHPUnit_Framework_MockObject_MockObject 71 101 */ 72 102 protected $mockResponse; … … 74 104 * mocked page factory instance 75 105 * 76 * @var SimpleMock106 * @var PHPUnit_Framework_MockObject_MockObject 77 107 */ 78 108 protected $mockPageFactory; … … 80 110 * mocked xml stream writer instance 81 111 * 82 * @var SimpleMock112 * @var PHPUnit_Framework_MockObject_MockObject 83 113 */ 84 114 protected $mockXMLStreamWriter; … … 86 116 * mocked xml serializer instance 87 117 * 88 * @var SimpleMock118 * @var PHPUnit_Framework_MockObject_MockObject 89 119 */ 90 120 protected $mockXMLSerializer; … … 95 125 */ 96 126 protected $page; 97 127 98 128 /** 99 129 * set up test environment … … 101 131 public function setUp() 102 132 { 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'); 111 141 $this->xmlProcessor->setXMLStreamWriter($this->mockXMLStreamWriter); 112 142 $this->xmlProcessor->setXMLSerializer($this->mockXMLSerializer); 113 143 $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 117 147 /** 118 148 * 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'); 127 159 $return = $this->xmlProcessor->process(); 128 $this->assert Reference($this->xmlProcessor, $return);160 $this->assertSame($this->xmlProcessor, $return); 129 161 $response = $this->xmlProcessor->getResponse(); 130 $this->assert IsA($response, 'stubResponse');131 } 132 162 $this->assertType('stubResponse', $response); 163 } 164 133 165 /** 134 166 * 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)); 157 187 $this->page->addElement($pageElement1); 158 188 $this->page->addElement($pageElement2); 159 189 $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 ); 164 204 $return = $this->xmlProcessor->process(); 165 $this->assert Reference($this->xmlProcessor, $return);205 $this->assertSame($this->xmlProcessor, $return); 166 206 $response = $this->xmlProcessor->getResponse(); 167 $this->assert IsA($response, 'stubResponse');168 } 169 207 $this->assertType('stubResponse', $response); 208 } 209 170 210 /** 171 211 * 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)); 179 221 $this->xmlProcessor->process(); 180 222 } trunk/src/test/php/net/stubbles/websites/xml/stubXMLResponseTestCase.php
r1231 r1256 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::xml::stubXMLResponse'); 10 Mock::generate('stubResponse'); 10 11 11 /** 12 12 * Tests for net::stubbles::websites::xml::stubXMLResponse. … … 15 15 * @subpackage websites_xml_test 16 16 */ 17 class stubXMLResponseTestCase extends UnitTestCase17 class stubXMLResponseTestCase extends PHPUnit_Framework_TestCase 18 18 { 19 19 /** … … 26 26 * mocked response instance 27 27 * 28 * @var SimpleMock28 * @var PHPUnit_Framework_MockObject_MockObject 29 29 */ 30 30 protected $mockResponse; … … 35 35 public function setUp() 36 36 { 37 $this->mockResponse = new MockstubResponse();37 $this->mockResponse = $this->getMock('stubResponse'); 38 38 $this->xmlResponse = new stubXMLResponse($this->mockResponse); 39 39 } … … 41 41 /** 42 42 * assure that page is handled correct 43 * 44 * @test 43 45 */ 44 public function testPage()46 public function page() 45 47 { 46 48 $this->assertNull($this->xmlResponse->getPage()); … … 48 50 $this->xmlResponse->setPage($page); 49 51 $page2 = $this->xmlResponse->getPage(); 50 $this->assert Equal($page2, $page);52 $this->assertSame($page, $page2); 51 53 $this->xmlResponse->clear(); 52 54 $this->assertNull($this->xmlResponse->getPage());
