Changeset 868

Show
Ignore:
Timestamp:
08/22/07 16:13:58 (1 year ago)
Author:
mikey
Message:

interceptor cleanup

Files:

Legend:

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

    r473 r868  
    4141{ 
    4242    /** 
     43     * key with which last xml is stored in session 
     44     */ 
     45    const SESSION_KEY = 'net.stubbles.websites.lastRequestResponseData'; 
     46 
     47    /** 
    4348     * does the preprocessing stuff 
    4449     * 
     
    5156        if ($request->hasValue('showLastRequestXML') == true && $session->isNew() == false) { 
    5257            $response->addHeader('Content-type', 'text/xml'); 
    53             $response->write($session->getValue('net.stubbles.websites.lastRequestResponseData')); 
     58            $response->write($session->getValue(self::SESSION_KEY)); 
    5459            $request->cancel(); 
    5560        } 
     
    6570    public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) 
    6671    { 
    67         $session->putValue('net.stubbles.websites.lastRequestResponseData', $response->getData()); 
     72        $session->putValue(self::SESSION_KEY, $response->getData()); 
    6873    } 
    6974} 
  • trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php

    r811 r868  
    3737 
    3838        // xml tests 
     39        $this->addTestFile($dir . '/xml/stubShowLastXMLInterceptorTestCase.php'); 
    3940        $this->addTestFile($dir . '/xml/stubXMLPostInterceptorTestCase.php'); 
    40         $this->addTestFile($dir . '/xml/stubXMLPreInterceptorTestCase.php'); 
    4141        $this->addTestFile($dir . '/xml/stubXMLProcessorTestCase.php'); 
    4242        $this->addTestFile($dir . '/xml/stubXMLResponseTestCase.php'); 
  • trunk/src/test/php/net/stubbles/websites/xml/stubShowLastXMLInterceptorTestCase.php

    r473 r868  
    11<?php 
    22/** 
    3  * Tests for net.stubbles.websites.xml.stubXMLPreInterceptor 
     3 * Tests for net.stubbles.websites.xml.stubShowLastXMLInterceptor. 
    44 * 
    55 * @author      Frank Kleine <mikey@stubbles.net> 
     
    77 * @subpackage  websites_xml_test 
    88 */ 
    9 stubClassLoader::load('net.stubbles.websites.xml.stubXMLPreInterceptor'); 
     9stubClassLoader::load('net.stubbles.websites.xml.stubShowLastXMLInterceptor'); 
    1010Mock::generate('stubRequest'); 
    1111Mock::generate('stubResponse'); 
    1212Mock::generate('stubSession'); 
    1313/** 
    14  * Tests for net.stubbles.websites.xml.stubXMLPreInterceptor 
     14 * Tests for net.stubbles.websites.xml.stubShowLastXMLInterceptor. 
    1515 * 
    1616 * @package     stubbles 
    1717 * @subpackage  websites_xml_test 
    1818 */ 
    19 class stubXMLPreInterceptorTestCase extends UnitTestCase 
     19class stubShowLastXMLInterceptorTestCase extends UnitTestCase 
    2020{ 
    2121    /** 
    2222     * instance to test 
    2323     * 
    24      * @var  stubXMLPreInterceptor 
     24     * @var  stubShowLastXMLInterceptor 
    2525     */ 
    26     protected $xmlPreInterceptor; 
     26    protected $showLastXMLPreInterceptor; 
    2727    /** 
    2828     * mocked response instance 
     
    4343     */ 
    4444    protected $mockSession; 
    45      
     45 
    4646    /** 
    4747     * set up test environment 
     
    4949    public function setUp() 
    5050    { 
    51         $this->xmlPreInterceptor = new stubXMLPreInterceptor(); 
    52         $this->mockRequest       = new MockstubRequest(); 
    53         $this->mockResponse      = new MockstubResponse(); 
    54         $this->mockSession       = new MockstubSession(); 
     51        $this->showLastXMLPreInterceptor = new stubShowLastXMLInterceptor(); 
     52        $this->mockRequest               = new MockstubRequest(); 
     53        $this->mockResponse              = new MockstubResponse(); 
     54        $this->mockSession               = new MockstubSession(); 
    5555    } 
    56      
     56 
    5757    /** 
    5858     * assure that a new session does not trigger the interceptor 
     
    6363        $this->mockSession->setReturnValue('isNew', true); 
    6464        $this->mockRequest->expectNever('cancel'); 
    65         $this->xmlPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
     65        $this->mockResponse->expectNever('write'); 
     66        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    6667    } 
    67      
     68 
    6869    /** 
    6970     * assure that a request that does not force to show the last request xml does not trigger the interceptor 
     
    7475        $this->mockSession->setReturnValue('isNew', false); 
    7576        $this->mockRequest->expectNever('cancel'); 
    76         $this->xmlPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
     77        $this->mockResponse->expectNever('write'); 
     78        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    7779    } 
    78      
     80 
    7981    /** 
    8082     * assure that if all requirements are met the processor is executed 
     
    8486        $this->mockRequest->setReturnValue('hasValue', true); 
    8587        $this->mockSession->setReturnValue('isNew', false); 
     88        $this->mockSession->setReturnValue('getValue', 'foo'); 
    8689        $this->mockRequest->expectOnce('cancel'); 
    87         $this->xmlPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
     90        $this->mockResponse->expect('write', array('foo')); 
     91        $this->showLastXMLPreInterceptor->preProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
     92    } 
     93 
     94    /** 
     95     * assure that postProcess() puts correct data into session 
     96     * 
     97     */ 
     98    public function testPostProcess() 
     99    { 
     100        $this->mockResponse->setReturnValue('getData', 'foo'); 
     101        $this->mockSession->expect('putValue', array(stubShowLastXMLInterceptor::SESSION_KEY, 'foo')); 
     102        $this->showLastXMLPreInterceptor->postProcess($this->mockRequest, $this->mockSession, $this->mockResponse); 
    88103    } 
    89104}