Changeset 1426
- Timestamp:
- 03/14/08 17:53:51 (4 months ago)
- Files:
-
- trunk/config/xml/interceptors.xml (modified) (1 diff)
- trunk/examples/config/xml/interceptors-xml.xml (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLAbstractPostInterceptor.php (deleted)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php (modified) (4 diffs)
- trunk/src/main/php/net/stubbles/websites/xml/stubXMLResponse.php (deleted)
- trunk/src/test/php/net/stubbles/integration/InterceptorTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/xml/stubXMLResponseTestCase.php (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/config/xml/interceptors.xml
r1419 r1426 8 8 </preInterceptors> 9 9 <postInterceptors> 10 <postInterceptor type="net::stubbles::websites::xml::stubShowLastXMLInterceptor" />11 10 </postInterceptors> 12 11 </xj:configuration> trunk/examples/config/xml/interceptors-xml.xml
r1419 r1426 10 10 </preInterceptors> 11 11 <postInterceptors> 12 <postInterceptor type="net::stubbles::websites::xml::stubShowLastXMLInterceptor"/>13 12 </postInterceptors> 14 13 </xj:configuration> trunk/src/main/php/net/stubbles/websites/xml/stubShowLastXMLInterceptor.php
r1360 r1426 1 1 <?php 2 2 /** 3 * Interceptor that stores the last XML tree in the session and 4 * is able to display it. 5 * 6 * This interceptor must be added as pre-interceptor AND 7 * post-interceptor. In the post-interceptor queue, it should 8 * be added prior to the XSL transformation processor. 9 * 10 * In the pre-interceptor queue, it cancels the request in case 11 * the request param showLastRequestXML is set and the session 12 * is not new. 3 * Preinterceptor that is able to display the last created XML result document. 13 4 * 14 5 * @author Frank Kleine <mikey@stubbles.net> … … 17 8 * @subpackage websites_xml 18 9 */ 19 stubClassLoader::load('net::stubbles::ipo::interceptors::stubPreInterceptor', 20 'net::stubbles::websites::xml::stubXMLAbstractPostInterceptor' 21 ); 10 stubClassLoader::load('net::stubbles::ipo::interceptors::stubPreInterceptor'); 22 11 /** 23 * Interceptor that stores the last XML tree in the session and 24 * is able to display it. 12 * Preinterceptor that is able to display the last created XML result document. 25 13 * 26 * This interceptor must be added as pre-interceptor AND 27 * post-interceptor. In the post-interceptor queue, it should 28 * be added prior to the XSL transformation processor. 29 * 30 * In the pre-interceptor queue, it cancels the request in case 31 * the request param showLastRequestXML is set and the session 32 * is not new. 14 * This interceptor cancels the request in case the request param 15 * showLastRequestXML is set and the session is not new. 33 16 * 34 17 * @package stubbles 35 18 * @subpackage websites_xml 36 19 */ 37 class stubShowLastXMLInterceptor extends stub XMLAbstractPostInterceptorimplements stubPreInterceptor20 class stubShowLastXMLInterceptor extends stubBaseObject implements stubPreInterceptor 38 21 { 39 /**40 * key with which last xml is stored in session41 */42 const SESSION_KEY = 'net.stubbles.websites.lastRequestResponseData';43 44 22 /** 45 23 * does the preprocessing stuff … … 53 31 if ($request->hasValue('showLastRequestXML') === true && $session->isNew() === false) { 54 32 $response->addHeader('Content-type', 'text/xml'); 55 $response->write($session->getValue( self::SESSION_KEY));33 $response->write($session->getValue('net.stubbles.websites.lastRequestResponseData')); 56 34 $request->cancel(); 57 35 } 58 36 } 59 60 /**61 * does the postprocessing stuff62 *63 * @param stubRequest $request access to request data64 * @param stubSession $session access to session data65 * @param stubXMLResponse $response access to response data66 */67 protected function doPostProcess(stubRequest $request, stubSession $session, stubXMLResponse $response)68 {69 $xmlStreamWriter = $response->getXMLStreamWriter();70 if ($xmlStreamWriter->isFinished() === false) {71 $xmlStreamWriter->writeEndElement();72 }73 74 $session->putValue(self::SESSION_KEY, $xmlStreamWriter->asXML());75 }76 37 } 77 38 ?> trunk/src/main/php/net/stubbles/websites/xml/stubXMLProcessor.php
r1425 r1426 13 13 'net::stubbles::websites::processors::stubAbstractPageProcessor', 14 14 'net::stubbles::websites::xml::skin::stubSkinGenerator', 15 'net::stubbles::websites::xml::stubXMLResponse',16 15 'net::stubbles::xml::stubXMLStreamWriterFactory', 17 16 'net::stubbles::xml::serializer::stubXMLSerializer' … … 42 41 public function __construct(stubRequest $request, stubSession $session, stubResponse $response, stubPageFactory $pageFactory) 43 42 { 44 $response = new stubXMLResponse($response);45 43 parent::__construct($request, $session, $response, $pageFactory); 46 44 $this->pageDirPrefix = 'conf/'; … … 76 74 $injector = $binder->getInjector(); 77 75 $xmlStreamWriter = $this->createXMLStreamWriter(); 78 $this->response->setPage($page);79 76 $xmlStreamWriter->writeStartElement('document'); 80 77 $xmlStreamWriter->writeAttribute('page', $pageName); … … 86 83 87 84 $xmlStreamWriter->writeEndElement(); // end document 88 $this->response->setXMLStreamWriter($xmlStreamWriter);89 85 $xslProcessor = $this->createXSLProcessor(); 90 86 $xslProcessor->importXSLStylesheet($this->createSkinGenerator()->generate($this->session, $page)); 91 87 $xslProcessor->setXMLDocument($xmlStreamWriter->asDOM()); 88 $this->session->putValue('net.stubbles.websites.lastRequestResponseData', $xmlStreamWriter->asXML()); 92 89 $this->response->replaceData(str_replace(' xmlns=""', '', preg_replace('/ xml:base="(.*)"/U', '', $xslProcessor->transformToXML()))); 93 90 } trunk/src/test/php/net/stubbles/integration/InterceptorTestCase.php
r1419 r1426 39 39 $this->assertType('stubShowLastXMLInterceptor', $preInterceptors[0]); 40 40 $postInterceptors = $interceptorXJConfInitializer->getPostInterceptors(); 41 $this->assert Type('stubShowLastXMLInterceptor', $postInterceptors[0]);41 $this->assertEquals(array(), $postInterceptors); 42 42 43 43 // cached … … 46 46 $this->assertType('stubShowLastXMLInterceptor', $preInterceptors[0]); 47 47 $postInterceptors = $interceptorXJConfInitializer->getPostInterceptors(); 48 $this->assert Type('stubShowLastXMLInterceptor', $postInterceptors[0]);48 $this->assertEquals(array(), $postInterceptors); 49 49 } 50 50 } trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r1424 r1426 50 50 $suite->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 51 51 $suite->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 52 $suite->addTestFile($dir . '/xml/stubXMLResponseTestCase.php');53 52 54 53 // xml skin trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php
r1360 r1426 94 94 $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 95 95 } 96 97 /**98 * assure that postProcess() puts correct data into session99 *100 * @test101 * @expectedException stubRuntimeException102 */103 public function postProcessNoXMLResponse()104 {105 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse);106 }107 108 /**109 * assure that postProcess() puts correct data into session110 *111 * @test112 */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);126 $this->mockSession->expects($this->once())->method('putValue')->with($this->equalTo(stubShowLastXMLInterceptor::SESSION_KEY), $this->equalTo('foo'));127 $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $xmlResponse);128 }129 130 /**131 * assure that postProcess() puts correct data into session132 *133 * @test134 */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);150 }151 96 } 152 97 ?> trunk/src/test/php/net/stubbles/websites/xml/stubXMLProcessorTestCase.php
r1423 r1426 157 157 $domDocument0->createElement('bar', 'foo'); 158 158 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 159 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 160 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 159 161 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 160 162 $this->xmlProcessor->process(); … … 194 196 $domDocument0->createElement('bar', 'foo'); 195 197 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 198 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 199 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 196 200 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 197 201 $this->xmlProcessor->process(); … … 232 236 $domDocument0->createElement('bar', 'foo'); 233 237 $this->mockXMLStreamWriter->expects($this->any())->method('asDOM')->will($this->returnValue($domDocument0)); 238 $this->mockXMLStreamWriter->expects($this->any())->method('asXML')->will($this->returnValue('<bar>foo</bar>')); 239 $this->mockSession->expects($this->at(1))->method('putValue')->with($this->equalTo('net.stubbles.websites.lastRequestResponseData'), $this->equalTo('<bar>foo</bar>')); 234 240 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('<html><head><title>Test</title></head><body><p>Hello world.</p></body></html>')); 235 241 $this->xmlProcessor->process();
