Changeset 1360
- Timestamp:
- 02/22/08 19:07:47 (8 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php
r1256 r1360 18 18 */ 19 19 stubClassLoader::load('net::stubbles::ipo::interceptors::stubPreInterceptor', 20 'net::stubbles::ipo::interceptors::stubPostInterceptor', 21 'net::stubbles::ipo::request::stubRequest', 22 'net::stubbles::ipo::request::stubResponse', 23 'net::stubbles::ipo::session::stubSession' 20 'net::stubbles::websites::xml::stubXMLAbstractPostInterceptor' 24 21 ); 25 22 /** … … 38 35 * @subpackage websites_xml 39 36 */ 40 class stubShowLastXMLInterceptor extends stub BaseObject implements stubPreInterceptor, stubPostInterceptor37 class stubShowLastXMLInterceptor extends stubXMLAbstractPostInterceptor implements stubPreInterceptor 41 38 { 42 39 /** … … 64 61 * does the postprocessing stuff 65 62 * 66 * @param stubRequest $request access to request data67 * @param stubSession $session access to session data68 * @param stub Response $response access to response data63 * @param stubRequest $request access to request data 64 * @param stubSession $session access to session data 65 * @param stubXMLResponse $response access to response data 69 66 */ 70 p ublic function postProcess(stubRequest $request, stubSession $session, stubResponse $response)67 protected function doPostProcess(stubRequest $request, stubSession $session, stubXMLResponse $response) 71 68 { 72 $session->putValue(self::SESSION_KEY, $response->getData()); 69 $xmlStreamWriter = $response->getXMLStreamWriter(); 70 if ($xmlStreamWriter->isFinished() === false) { 71 $xmlStreamWriter->writeEndElement(); 72 } 73 74 $session->putValue(self::SESSION_KEY, $xmlStreamWriter->asXML()); 73 75 } 74 76 } trunk/src/main/php/net/stubbles/websites/xml/stubXMLPostInterceptor.php
r1357 r1360 90 90 $xslProcessor = $this->createXSLProcessor(); 91 91 $xslProcessor->importXSLStylesheet($resultXSL); 92 $xslProcessor->setXMLDocument(DOMDocument::loadXML($response->getData())); 92 $xmlStreamWriter = $response->getXMLStreamWriter(); 93 if ($xmlStreamWriter->isFinished() === false) { 94 $xmlStreamWriter->writeEndElement(); 95 } 96 97 $xslProcessor->setXMLDocument($xmlStreamWriter->asDOM()); 93 98 $response->replaceData(str_replace(' xmlns=""', '', preg_replace('/ xml:base="(.*)"/U', '', $xslProcessor->transformToXML()))); 94 99 } trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1355 r1360 102 102 } 103 103 104 // end document 105 $xmlStreamWriter->writeEndElement(); 106 $this->response->replaceData($xmlStreamWriter->asXML()); 104 $this->response->setXMLStreamWriter($xmlStreamWriter); 107 105 } 108 106 … … 115 113 * <document> 116 114 * <session> 115 * <acceptsCookies>true</acceptsCookies> 116 * <id>abc123</id> 117 * <name>PHPSESSID</name> 117 118 * <isNew>true</isNew> 119 * <variant> 120 * <name>foo</name> 121 * <alias>bar</alias> 122 * </variant> 118 123 * <token> 119 124 * <current>foo</current> trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php
r1256 r1360 99 99 * 100 100 * @test 101 * @expectedException stubRuntimeException 101 102 */ 102 public function postProcess ()103 public function postProcessNoXMLResponse() 103 104 { 104 $this->mockResponse->expects($this->once())->method('getData')->will($this->returnValue('foo')); 105 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 106 } 107 108 /** 109 * assure that postProcess() puts correct data into session 110 * 111 * @test 112 */ 113 public function postProcessUnfinishedStreamWriter() 114 { 115 $mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 116 $mockXMLStreamWriter->expects($this->once()) 117 ->method('isFinished') 118 ->will($this->returnValue(false)); 119 $mockXMLStreamWriter->expects($this->once()) 120 ->method('writeEndElement'); 121 $mockXMLStreamWriter->expects($this->once()) 122 ->method('asXML') 123 ->will($this->returnValue('foo')); 124 $xmlResponse = new stubXMLResponse($this->mockResponse); 125 $xmlResponse->setXMLStreamWriter($mockXMLStreamWriter); 105 126 $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo')); 106 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 127 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $xmlResponse); 128 } 129 130 /** 131 * assure that postProcess() puts correct data into session 132 * 133 * @test 134 */ 135 public function postProcessFinishedStreamWriter() 136 { 137 $mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 138 $mockXMLStreamWriter->expects($this->once()) 139 ->method('isFinished') 140 ->will($this->returnValue(true)); 141 $mockXMLStreamWriter->expects($this->never()) 142 ->method('writeEndElement'); 143 $mockXMLStreamWriter->expects($this->once()) 144 ->method('asXML') 145 ->will($this->returnValue('foo')); 146 $xmlResponse = new stubXMLResponse($this->mockResponse); 147 $xmlResponse->setXMLStreamWriter($mockXMLStreamWriter); 148 $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo')); 149 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $xmlResponse); 107 150 } 108 151 } trunk/src/test/php/net/stubbles/websites/xml/stubXMLPostInterceptorTestCase.php
r1357 r1360 33 33 protected $xmlResponse; 34 34 /** 35 * instance to be used for tests 36 * 37 * @var PHPUnit_Framework_MockObject_MockObject 38 */ 39 protected $mockXMLStreamWriter; 40 /** 35 41 * mocked request instance 36 42 * … … 82 88 ) 83 89 ); 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>')); 90 $this->mockRequest = $this->getMock('stubRequest'); 91 $this->mockResponse = $this->getMock('stubResponse'); 92 $this->mockXMLStreamWriter = $this->getMock('stubXMLStreamWriter'); 93 $domDocument0 = new DOMDocument(); 94 $domDocument0->createElement('bar', 'foo'); 95 $this->mockXMLStreamWriter->expects($this->any())->method('isFinished')->will($this->returnValue(true)); 96 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 87 97 $this->xmlResponse = new stubXMLResponse($this->mockResponse); 98 $this->xmlResponse->setXMLStreamWriter($this->mockXMLStreamWriter); 88 99 $this->page = new stubPage(); 89 100 $this->xmlResponse->setPage($this->page); trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php
r1355 r1360 155 155 $this->mockPageFactory->expects($this->once())->method('getPage')->with($this->equalTo('conf/index')); 156 156 $this->mockXMLStreamWriter->expects($this->exactly(5))->method('writeStartElement'); 157 $this->mockXMLStreamWriter->expects($this->exactly( 5))->method('writeEndElement');157 $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeEndElement'); 158 158 $this->mockXMLSerializer->expects($this->once())->method('serialize'); 159 159 $return = $this->xmlProcessor->process(); … … 189 189 $this->page->addElement($pageElement3); 190 190 $this->mockXMLStreamWriter->expects($this->exactly(5))->method('writeStartElement'); 191 $this->mockXMLStreamWriter->expects($this->exactly( 5))->method('writeEndElement');191 $this->mockXMLStreamWriter->expects($this->exactly(4))->method('writeEndElement'); 192 192 $this->mockXMLSerializer->expects($this->at(0)) 193 193 ->method('serialize')
