Changeset 1272
- Timestamp:
- 01/21/08 09:29:29 (10 months ago)
- Files:
-
- trunk/src/test/AllTests.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializerTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/ipo/response/stubCookieTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/ipo/response/stubDecoratedResponseTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManagerTestCase.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php (modified) (12 diffs)
- trunk/src/test/php/net/stubbles/ipo/session/stubNoneDurableSessionTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/ipo/session/stubPHPSessionTestCase.php (modified) (7 diffs)
- trunk/src/test/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/test/AllTests.php
r1271 r1272 27 27 require_once $dir . '/php/net/stubbles/events/EventTestSuite.php'; 28 28 require_once $dir . '/php/net/stubbles/ioc/IOCTestSuite.php'; 29 require_once $dir . '/php/net/stubbles/ipo/IPOTestSuite.php'; 29 30 require_once $dir . '/php/net/stubbles/websites/WebsitesTestSuite.php'; 30 31 require_once $dir . '/php/net/stubbles/websites/variantmanager/VariantManagerTestSuite.php'; … … 58 59 $suite->addTestSuite('EventTestSuite'); 59 60 $suite->addTestSuite('IOCTestSuite'); 61 $suite->addTestSuite('IPOTestSuite'); 60 62 $suite->addTestSuite('WebsitesTestSuite'); 61 63 $suite->addTestSuite('VariantManagerTestSuite'); trunk/src/test/php/net/stubbles/ipo/IPOTestSuite.php
r1166 r1272 13 13 * @subpackage test 14 14 */ 15 class IPOTestSuite extends TestSuite15 class IPOTestSuite extends PHPUnit_Framework_TestSuite 16 16 { 17 17 /** 18 * constructor 18 * returns the test suite to be run 19 * 20 * @return PHPUnit_Framework_TestSuite 19 21 */ 20 public function __construct()22 public static function suite() 21 23 { 22 $ dir = dirname(__FILE__);23 $ this->TestSuite('All ipo tests');24 $ this->addTestFile($dir . '/interceptors/stubInterceptorXJConfInitializerTestCase.php');24 $suite = new self(); 25 $dir = dirname(__FILE__); 26 $suite->addTestFile($dir . '/interceptors/stubInterceptorXJConfInitializerTestCase.php'); 25 27 26 $this->addTestFile($dir . '/request/stubAbstractRequestTestCase.php');27 $this->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php');28 $this->addTestFile($dir . '/request/stubRequestValueErrorFactoryMappingDecoratorTestCase.php');29 $this->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php');28 #$suite->addTestFile($dir . '/request/stubAbstractRequestTestCase.php'); 29 #$suite->addTestFile($dir . '/request/stubRequestPrefixDecoratorTestCase.php'); 30 #$suite->addTestFile($dir . '/request/stubRequestValueErrorFactoryMappingDecoratorTestCase.php'); 31 #$suite->addTestFile($dir . '/request/stubRequestValueErrorTestCase.php'); 30 32 31 $this->addTestFile($dir . '/request/broker/stubRequestBrokerTestCase.php');32 $this->addTestFile($dir . '/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php');33 $this->addTestFile($dir . '/request/broker/annotations/stubFloatFilterAnnotationTestCase.php');34 $this->addTestFile($dir . '/request/broker/annotations/stubHTTPURLFilterAnnotationTestCase.php');35 $this->addTestFile($dir . '/request/broker/annotations/stubIntegerFilterAnnotationTestCase.php');36 $this->addTestFile($dir . '/request/broker/annotations/stubMailFilterAnnotationTestCase.php');37 $this->addTestFile($dir . '/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php');38 $this->addTestFile($dir . '/request/broker/annotations/stubStringFilterAnnotationTestCase.php');39 $this->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php');33 #$suite->addTestFile($dir . '/request/broker/stubRequestBrokerTestCase.php'); 34 #$suite->addTestFile($dir . '/request/broker/annotations/stubAbstractFilterAnnotationTestCase.php'); 35 #$suite->addTestFile($dir . '/request/broker/annotations/stubFloatFilterAnnotationTestCase.php'); 36 #$suite->addTestFile($dir . '/request/broker/annotations/stubHTTPURLFilterAnnotationTestCase.php'); 37 #$suite->addTestFile($dir . '/request/broker/annotations/stubIntegerFilterAnnotationTestCase.php'); 38 #$suite->addTestFile($dir . '/request/broker/annotations/stubMailFilterAnnotationTestCase.php'); 39 #$suite->addTestFile($dir . '/request/broker/annotations/stubPasswordFilterAnnotationTestCase.php'); 40 #$suite->addTestFile($dir . '/request/broker/annotations/stubStringFilterAnnotationTestCase.php'); 41 #$suite->addTestFile($dir . '/request/broker/annotations/stubTextFilterAnnotationTestCase.php'); 40 42 41 $this->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php');42 $this->addTestFile($dir . '/request/filters/stubHTTPURLFilterTestCase.php');43 $this->addTestFile($dir . '/request/filters/stubIntegerFilterTestCase.php');44 $this->addTestFile($dir . '/request/filters/stubMailFilterTestCase.php');45 $this->addTestFile($dir . '/request/filters/stubMD5FilterTestCase.php');46 $this->addTestFile($dir . '/request/filters/stubPassThruFilterTestCase.php');47 $this->addTestFile($dir . '/request/filters/stubPasswordFilterTestCase.php');48 $this->addTestFile($dir . '/request/filters/stubRegexFilterDecoratorTestCase.php');49 $this->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php');50 $this->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php');43 #$suite->addTestFile($dir . '/request/filters/stubFloatFilterTestCase.php'); 44 #$suite->addTestFile($dir . '/request/filters/stubHTTPURLFilterTestCase.php'); 45 #$suite->addTestFile($dir . '/request/filters/stubIntegerFilterTestCase.php'); 46 #$suite->addTestFile($dir . '/request/filters/stubMailFilterTestCase.php'); 47 #$suite->addTestFile($dir . '/request/filters/stubMD5FilterTestCase.php'); 48 #$suite->addTestFile($dir . '/request/filters/stubPassThruFilterTestCase.php'); 49 #$suite->addTestFile($dir . '/request/filters/stubPasswordFilterTestCase.php'); 50 #$suite->addTestFile($dir . '/request/filters/stubRegexFilterDecoratorTestCase.php'); 51 #$suite->addTestFile($dir . '/request/filters/stubStringFilterTestCase.php'); 52 #$suite->addTestFile($dir . '/request/filters/stubTextFilterTestCase.php'); 51 53 52 $ this->addTestFile($dir . '/response/stubCookieTestCase.php');53 $ this->addTestFile($dir . '/response/stubDecoratedResponseTestCase.php');54 $suite->addTestFile($dir . '/response/stubCookieTestCase.php'); 55 $suite->addTestFile($dir . '/response/stubDecoratedResponseTestCase.php'); 54 56 55 $this->addTestFile($dir . '/session/stubAbstractSessionTestCase.php'); 56 $this->addTestFile($dir . '/session/stubNoneDurableSessionTestCase.php'); 57 $this->addTestFile($dir . '/session/stubPHPSessionTestCase.php'); 58 $this->addTestFile($dir . '/session/resourcemanager/stubSessionResourceManagerTestCase.php'); 57 $suite->addTestFile($dir . '/session/stubAbstractSessionTestCase.php'); 58 $suite->addTestFile($dir . '/session/stubNoneDurableSessionTestCase.php'); 59 $suite->addTestFile($dir . '/session/stubPHPSessionTestCase.php'); 60 $suite->addTestFile($dir . '/session/resourcemanager/stubSessionResourceManagerTestCase.php'); 61 return $suite; 59 62 } 60 63 } trunk/src/test/php/net/stubbles/ipo/interceptors/stubInterceptorXJConfInitializerTestCase.php
r1223 r1272 11 11 'net::stubbles::ipo::interceptors::stubPostInterceptor' 12 12 ); 13 Mock::generate('stubPreInterceptor'); 14 Mock::generate('stubPostInterceptor'); 13 /** 14 * Helper class for test: serializable pre- and postinterceptor. 15 * 16 * @package stubbles 17 * @subpackage ipo_interceptors_test 18 */ 15 19 class MockSerializableInterceptor extends stubSerializableObject implements stubPreInterceptor, stubPostInterceptor 16 20 { 17 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) 21 /** 22 * does the preprocessing stuff 23 * 24 * @param stubRequest $request access to request data 25 * @param stubSession $session access to session data 26 * @param stubResponse $response access to response data 27 */ 28 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 29 30 /** 31 * does the postprocessing stuff 32 * 33 * @param stubRequest $request access to request data 34 * @param stubSession $session access to session data 35 * @param stubResponse $response access to response data 36 */ 37 public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 38 } 39 /** 40 * Helper class for test: non-serializable preinterceptor. 41 * 42 * @package stubbles 43 * @subpackage ipo_interceptors_test 44 */ 45 class MockPreInterceptor extends stubBaseObject implements stubPreInterceptor 46 { 47 /** 48 * does the preprocessing stuff 49 * 50 * @param stubRequest $request access to request data 51 * @param stubSession $session access to session data 52 * @param stubResponse $response access to response data 53 */ 54 public function preProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 55 56 /** 57 * returns the full qualified class name 58 * 59 * @return string 60 */ 61 public function getClassName() 18 62 { 19 63 return 'MockPreInterceptor'; 20 64 } 21 22 public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) 65 } 66 /** 67 * Helper class for test: non-serializable postinterceptor. 68 * 69 * @package stubbles 70 * @subpackage ipo_interceptors_test 71 */ 72 class MockPostInterceptor extends stubBaseObject implements stubPostInterceptor 73 { 74 /** 75 * does the postprocessing stuff 76 * 77 * @param stubRequest $request access to request data 78 * @param stubSession $session access to session data 79 * @param stubResponse $response access to response data 80 */ 81 public function postProcess(stubRequest $request, stubSession $session, stubResponse $response) {} 82 83 /** 84 * returns the full qualified class name 85 * 86 * @return string 87 */ 88 public function getClassName() 23 89 { 24 90 return 'MockPostInterceptor'; 25 91 } 26 92 } … … 31 97 * @subpackage ipo_interceptors_test 32 98 */ 33 class stubInterceptorXJConfInitializerTestCase extends UnitTestCase99 class stubInterceptorXJConfInitializerTestCase extends PHPUnit_Framework_TestCase 34 100 { 35 101 /** … … 58 124 { 59 125 $this->interceptorXJConfInitializer = new stubInterceptorXJConfInitializer(); 60 $this->preInterceptors[] = new MockstubPreInterceptor(); 61 $this->preInterceptors[0]->setReturnValue('getClassName', 'MockstubPreInterceptor'); 126 $this->preInterceptors[] = new MockPreInterceptor(); 62 127 $this->preInterceptors[] = new MockSerializableInterceptor(); 63 128 $this->postInterceptors[] = new MockSerializableInterceptor(); 64 $this->postInterceptors[] = new MockstubPostInterceptor(); 65 $this->postInterceptors[1]->setReturnValue('getClassName', 'MockstubPostInterceptor'); 129 $this->postInterceptors[] = new MockPostInterceptor(); 66 130 } 67 131 68 132 /** 69 133 * test descriptor 134 * 135 * @test 70 136 */ 71 public function testDescriptor()137 public function descriptor() 72 138 { 73 $this->assertEqual ($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG), 'interceptors');74 $this->assertEqual ($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION), 'interceptors');139 $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG)); 140 $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION)); 75 141 $this->interceptorXJConfInitializer->setDescriptor('foo'); 76 $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG), 'foo'); 77 $this->assertEqual($this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION), 'interceptors'); 78 $this->expectException('stubIllegalArgumentException'); 142 $this->assertEquals('foo', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_CONFIG)); 143 $this->assertEquals('interceptors', $this->interceptorXJConfInitializer->getDescriptor(stubXJConfInitializer::DESCRIPTOR_DEFINITION)); 144 } 145 146 /** 147 * test descriptor 148 * 149 * @test 150 * @expectedException stubIllegalArgumentException 151 */ 152 public function descriptorWrongArgument() 153 { 79 154 $this->interceptorXJConfInitializer->getDescriptor('bar'); 80 155 } … … 82 157 /** 83 158 * check that the cache data is correct 159 * 160 * @test 84 161 */ 85 public function testGetCacheData()162 public function getCacheData() 86 163 { 87 164 $this->interceptorXJConfInitializer->setPreInterceptors($this->preInterceptors); 88 165 $this->interceptorXJConfInitializer->setPostInterceptors($this->postInterceptors); 89 166 $cacheData = $this->interceptorXJConfInitializer->getCacheData(); 90 $this->assertEqual ($cacheData['preInterceptors'][0], 'MockstubPreInterceptor');91 $this->assert IsA($cacheData['preInterceptors'][1], 'stubSerializedObject');92 $this->assert IsA($cacheData['postInterceptors'][0], 'stubSerializedObject');93 $this->assertEqual ($cacheData['postInterceptors'][1], 'MockstubPostInterceptor');167 $this->assertEquals('MockPreInterceptor', $cacheData['preInterceptors'][0]); 168 $this->assertType('stubSerializedObject', $cacheData['preInterceptors'][1]); 169 $this->assertType('stubSerializedObject', $cacheData['postInterceptors'][0]); 170 $this->assertEquals('MockPostInterceptor', $cacheData['postInterceptors'][1]); 94 171 95 172 } … … 97 174 /** 98 175 * check that cache data is used correct 176 * 177 * @test 99 178 */ 100 public function testSetCacheData()179 public function setCacheData() 101 180 { 102 $cacheData['preInterceptors'][0] = 'Mock stubPreInterceptor';181 $cacheData['preInterceptors'][0] = 'MockPreInterceptor'; 103 182 $cacheData['preInterceptors'][1] = $this->preInterceptors[1]->getSerialized(); 104 183 $cacheData['postInterceptors'][0] = $this->postInterceptors[0]->getSerialized(); 105 $cacheData['postInterceptors'][1] = 'Mock stubPostInterceptor';184 $cacheData['postInterceptors'][1] = 'MockPostInterceptor'; 106 185 $this->interceptorXJConfInitializer->setCacheData($cacheData); 107 186 $preInterceptors = $this->interceptorXJConfInitializer->getPreInterceptors(); 108 $this->assert IsA($preInterceptors[0], 'MockstubPreInterceptor');109 $this->assert IsA($preInterceptors[1], 'MockSerializableInterceptor');187 $this->assertType('MockPreInterceptor', $preInterceptors[0]); 188 $this->assertType('MockSerializableInterceptor', $preInterceptors[1]); 110 189 $postInterceptors = $this->interceptorXJConfInitializer->getPostInterceptors(); 111 $this->assert IsA($postInterceptors[0], 'MockSerializableInterceptor');112 $this->assert IsA($postInterceptors[1], 'MockstubPostInterceptor');190 $this->assertType('MockSerializableInterceptor', $postInterceptors[0]); 191 $this->assertType('MockPostInterceptor', $postInterceptors[1]); 113 192 } 114 193 } trunk/src/test/php/net/stubbles/ipo/response/stubCookieTestCase.php
r1223 r1272 1 1 <?php 2 2 /** 3 * Tests for net::stubbles::ipo.response::stubCooki 3 * Tests for net::stubbles::ipo.response::stubCookie. 4 4 * 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 * @subpackage ipo_ test7 * @subpackage ipo_response_test 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ipo.response::stubCookie'); 10 10 /** 11 * Tests for net::stubbles::ipo.response::stubCooki 11 * Tests for net::stubbles::ipo.response::stubCookie. 12 12 * 13 13 * @package stubbles 14 * @subpackage ipo_ test14 * @subpackage ipo_response_test 15 15 */ 16 class stubCookieTestCase extends UnitTestCase16 class stubCookieTestCase extends PHPUnit_Framework_TestCase 17 17 { 18 18 /** 19 19 * test with default values 20 * 21 * @test 20 22 */ 21 public function testValuesDefault()23 public function defaultValues() 22 24 { 23 25 $cookie = stubCookie::create('foo', 'bar'); 24 $this->assertEqual ($cookie->getName(), 'foo');25 $this->assertEqual ($cookie->getValue(), 'bar');26 $this->assertEqual ($cookie->getExpiration(), 0);26 $this->assertEquals('foo', $cookie->getName()); 27 $this->assertEquals('bar', $cookie->getValue()); 28 $this->assertEquals(0, $cookie->getExpiration()); 27 29 $this->assertNull($cookie->getPath()); 28 30 $this->assertNull($cookie->getDomain()); … … 33 35 /** 34 36 * test that values are returned as expected 37 * 38 * @test 35 39 */ 36 public function testValuesSet()40 public function valuesSet() 37 41 { 38 42 $cookie = stubCookie::create('foo', 'bar')->expiringAt(100) … … 41 45 ->withSecurity(true) 42 46 ->usingHttpOnly(true); 43 $this->assertEqual ($cookie->getName(), 'foo');44 $this->assertEqual ($cookie->getValue(), 'bar');45 $this->assertEqual ($cookie->getExpiration(), 100);46 $this->assertEqual ($cookie->getPath(), 'bar');47 $this->assertEqual ($cookie->getDomain(), '.example.org');47 $this->assertEquals('foo', $cookie->getName()); 48 $this->assertEquals('bar', $cookie->getValue()); 49 $this->assertEquals(100, $cookie->getExpiration()); 50 $this->assertEquals('bar', $cookie->getPath()); 51 $this->assertEquals('.example.org', $cookie->getDomain()); 48 52 $this->assertTrue($cookie->isSecure()); 49 53 $this->assertTrue($cookie->isHttpOnly()); trunk/src/test/php/net/stubbles/ipo/response/stubDecoratedResponseTestCase.php
r1223 r1272 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ipo::response::stubDecoratedResponse'); 10 Mock::generate('stubResponse');11 10 /** 12 11 * Tests for net::stubbles::ipo::response::stubDecoratedResponse. … … 15 14 * @subpackage ipo_response_test 16 15 */ 17 class stubDecoratedResponseTestCase extends UnitTestCase16 class stubDecoratedResponseTestCase extends PHPUnit_Framework_TestCase 18 17 { 19 18 /** … … 26 25 * mocked response instance 27 26 * 28 * @var SimpleMock27 * @var PHPUnit_Framework_MockObject_MockObject 29 28 */ 30 29 protected $mockResponse; … … 35 34 public function setUp() 36 35 { 37 $this->mockResponse = new MockstubResponse();36 $this->mockResponse = $this->getMock('stubResponse'); 38 37 $this->decoratedResponse = new stubDecoratedResponse($this->mockResponse); 39 38 } … … 41 40 /** 42 41 * assure that all methods of the decorated response are called correct 42 * 43 * @test 43 44 */ 44 public function testPassthru()45 public function passthru() 45 46 { 46 $this->mockResponse->expectOnce('clear'); 47 $this->mockResponse->expectOnce('addHeader', array('name', 'value')); 48 $this->mockResponse->expectOnce('getHeaders'); 49 $this->mockResponse->setReturnValue('getHeaders', array('name' => 'value')); 47 $this->mockResponse->expects($this->once())->method('clear'); 48 $this->mockResponse->expects($this->once())->method('addHeader')->with($this->equalTo('name'), $this->equalTo('value')); 49 $this->mockResponse->expects($this->once())->method('getHeaders')->will($this->returnValue(array('name' => 'value'))); 50 50 $cookie = stubCookie::create('name', 'value'); 51 $this->mockResponse->expectOnce('setCookie', array($cookie)); 52 $this->mockResponse->expectOnce('getCookies'); 53 $this->mockResponse->setReturnValue('getCookies', array('name' => $cookie)); 54 $this->mockResponse->expectOnce('write', array('data')); 55 $this->mockResponse->expectOnce('getData'); 56 $this->mockResponse->setReturnValue('getData', 'data'); 57 $this->mockResponse->expectOnce('replaceData', array('data')); 58 $this->mockResponse->expectOnce('send'); 51 $this->mockResponse->expects($this->once())->method('setCookie', array($cookie)); 52 $this->mockResponse->expects($this->once())->method('getCookies')->will($this->returnValue(array('name' => $cookie))); 53 $this->mockResponse->expects($this->once())->method('write', array('data')); 54 $this->mockResponse->expects($this->once())->method('getData')->will($this->returnValue('data')); 55 $this->mockResponse->expects($this->once())->method('replaceData')->with($this->equalTo('data')); 56 $this->mockResponse->expects($this->once())->method('send'); 59 57 $this->decoratedResponse->clear(); 60 58 $this->decoratedResponse->addHeader('name', 'value'); 61 $this->assertEqual ($this->decoratedResponse->getHeaders(), array('name' => 'value'));59 $this->assertEquals(array('name' => 'value'), $this->decoratedResponse->getHeaders()); 62 60 $this->decoratedResponse->setCookie($cookie); 63 $this->assertEqual ($this->decoratedResponse->getCookies(), array('name' => $cookie));61 $this->assertEquals(array('name' => $cookie), $this->decoratedResponse->getCookies()); 64 62 $this->decoratedResponse->write('data'); 65 $this->assertEqual ($this->decoratedResponse->getData(), 'data');63 $this->assertEquals('data', $this->decoratedResponse->getData()); 66 64 $this->decoratedResponse->replaceData('data'); 67 65 $this->decoratedResponse->send(); trunk/src/test/php/net/stubbles/ipo/session/resourcemanager/stubSessionResourceManagerTestCase.php
r1223 r1272 5 5 * @author Stephan Schmidt <schst@stubbles.net> 6 6 * @package stubbles 7 * @subpackage ipo_session_ test7 * @subpackage ipo_session_resourcemanager_test 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ipo::session::stubNoneDurableSession', 10 'net::stubbles::ipo::session::resourcemanager::stubSessionResourceManager'); 11 Mock::generate('stubRequest'); 12 10 'net::stubbles::ipo::session::resourcemanager::stubSessionResourceManager' 11 ); 13 12 /** 14 13 * Session resource interface … … 63 62 * 64 63 * @package stubbles 65 * @subpackage ipo_session_ test66 */ 67 class stubSessionResourceManagerTestCase extends UnitTestCase64 * @subpackage ipo_session_resourcemanager_test 65 */ 66 class stubSessionResourceManagerTestCase extends PHPUnit_Framework_TestCase 68 67 { 69 68 /** 69 * instance to test 70 * 71 * @var stubSessionResourceManager 72 */ 73 protected $resourceManager; 74 /** 75 * session instance to be used 76 * 77 * @var stubNoneDurableSession 78 */ 79 protected $session; 80 81 /** 70 82 * set up test environment 71 83 */ 72 84 public function setUp() 73 85 { 86 $this->session = new stubNoneDurableSession($this->getMock('stubRequest'), 'test'); 87 $this->resourceManager = new stubSessionResourceManager($this->session); 74 88 } 75 89 76 90 /** 77 91 * Test fetching a resource via string 78 */ 79 public function testGetResourceByString() 80 { 81 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 82 $manager = new stubSessionResourceManager($session); 83 84 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 85 86 $resource = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 87 $this->assertIsA($resource, 'stubSessionResource'); 88 $this->assertIsA($resource, 'stubSessionResourceManagerTestCase_MyResource'); 92 * 93 * @test 94 */ 95 public function getResourceByString() 96 { 97 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 98 $resource = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 99 $this->assertType('stubSessionResource', $resource); 100 $this->assertType('stubSessionResourceManagerTestCase_MyResource', $resource); 89 101 } 90 102 91 103 /** 92 104 * Test fetching a resource via clazz 93 */ 94 public function testGetResourceByClazz() 95 { 96 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 97 $manager = new stubSessionResourceManager($session); 98 99 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 100 101 $resource = $manager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 102 $this->assertIsA($resource, 'stubSessionResource'); 103 $this->assertIsA($resource, 'stubSessionResourceManagerTestCase_MyResource'); 105 * 106 * @test 107 */ 108 public function getResourceByClazz() 109 { 110 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 111 $resource = $this->resourceManager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 112 $this->assertType('stubSessionResource', $resource); 113 $this->assertType('stubSessionResourceManagerTestCase_MyResource', $resource); 104 114 } 105 115 106 116 /** 107 117 * Test that always the same object is returned 108 */ 109 public function testGetResourceIdentical() 110 { 111 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 112 $manager = new stubSessionResourceManager($session); 113 114 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 115 116 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 117 $resource2 = $manager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 118 $this->assertIdentical($resource1, $resource2); 118 * 119 * @test 120 */ 121 public function getResourceIdentical() 122 { 123 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 124 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 125 $resource2 = $this->resourceManager->getResource(new stubReflectionClass('stubSessionResourceManagerTestCase_MyResource')); 126 $this->identicalTo($resource1, $resource2); 119 127 } 120 128 121 129 /** 122 130 * Test that always the same object is returned 123 */ 124 public function testGetResourceTwoInterfacesIdentical() 125 { 126 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 127 $manager = new stubSessionResourceManager($session); 128 129 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource', 'stubSessionResourceManagerTestCase_MyResource2')); 130 131 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource'); 132 $resource2 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 133 $this->assertIdentical($resource1, $resource2); 131 * 132 * @test 133 */ 134 public function getResourceTwoInterfacesIdentical() 135 { 136 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource', 'stubSessionResourceManagerTestCase_MyResource2')); 137 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource'); 138 $resource2 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 139 $this->identicalTo($resource1, $resource2); 134 140 } 135 141 136 142 /** 137 143 * Test that an exception occurs, if the interface does not exist 138 */ 139 public function testGetResourceInterfaceNotExists() 140 { 141 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 142 $manager = new stubSessionResourceManager($session); 143 144 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 145 146 $this->expectException('ReflectionException'); 147 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceFoo'); 144 * 145 * @test 146 * @expectedException ReflectionException 147 */ 148 public function getResourceInterfaceNotExists() 149 { 150 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 151 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceFoo'); 148 152 } 149 153 150 154 /** 151 155 * Test that an exception occurs, if a class instead of interface has been passed 152 */ 153 public function testGetResourceNoInterface() 154 { 155 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 156 $manager = new stubSessionResourceManager($session); 157 158 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 159 160 $this->expectException('stubIllegalArgumentException'); 161 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceImpl'); 156 * 157 * @test 158 * @expectedException stubIllegalArgumentException 159 */ 160 public function getResourceNoInterface() 161 { 162 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 163 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceImpl'); 162 164 } 163 165 164 166 /** 165 167 * Test that an exception occurs, if a interfaces, that does not extend session resource has been passed 166 */ 167 public function testGetResourceNoSessionResource() 168 { 169 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 170 $manager = new stubSessionResourceManager($session); 171 172 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 173 174 $this->expectException('stubIllegalArgumentException'); 175 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResourceInvalid'); 168 * 169 * @test 170 * @expectedException stubIllegalArgumentException 171 */ 172 public function getResourceNoSessionResource() 173 { 174 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 175 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResourceInvalid'); 176 176 } 177 177 178 178 /** 179 179 * Test that an exception occurs, if a class instead of interface has been passed 180 */ 181 public function testGetResourceNotDefined() 182 { 183 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 184 $manager = new stubSessionResourceManager($session); 185 186 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 187 188 $this->expectException('stubIllegalArgumentException'); 189 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 180 * 181 * @test 182 * @expectedException stubIllegalArgumentException 183 */ 184 public function getResourceNotDefined() 185 { 186 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource')); 187 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource2'); 190 188 } 191 189 192 190 /** 193 191 * Test that an exception occurs, if a class does not implement the specified interface 194 */ 195 public function testGetResourceWrongInterface() 196 { 197 $session = new stubNoneDurableSession(new MockstubRequest(), 'test'); 198 $manager = new stubSessionResourceManager($session); 199 200 $manager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource3')); 201 202 $this->expectException('stubConfigurationException'); 203 $resource1 = $manager->getResource('stubSessionResourceManagerTestCase_MyResource3'); 192 * 193 * @test 194 * @expectedException stubConfigurationException 195 */ 196 public function getResourceWrongInterface() 197 { 198 $this->resourceManager->addResourceDefinition('stubSessionResourceManagerTestCase_MyResourceImpl', array('stubSessionResourceManagerTestCase_MyResource3')); 199 $resource1 = $this->resourceManager->getResource('stubSessionResourceManagerTestCase_MyResource3'); 204 200 } 205 201 } trunk/src/test/php/net/stubbles/ipo/session/stubAbstractSessionTestCase.php
r1223 r1272 8 8 */ 9 9 stubClassLoader::load('net::stubbles::ipo::session::stubAbstractSession'); 10 Mock::generate('stubRequest');11 Mock::generate('stubSerializable');12 10 class stubTestSession extends stubAbstractSession 13 11 { … … 57 55 * @subpackage ipo_session_test 58 56 */ 59 class stubAbstractSessionTestCase extends UnitTestCase57 class stubAbstractSessionTestCase extends PHPUnit_Framework_TestCase 60 58 { 61 59 /** … … 71 69 public function setUp() 72 70 { 73 $this->session = new stubTestSession( new MockstubRequest(), 'foo');71 $this->session = new stubTestSession($this->getMock('stubRequest'), 'foo'); 74 72 } 75 73 76 74 /** 77 75 * test with default values 78 */ 79 public function testDefaultValues() 80 { 81 $this->assertEqual($this->session->getName(), 'foo'); 76 * 77 * @test 78 */ 79 public function defaultValues() 80 { 81 $this->assertEquals('foo', $this->session->getName()); 82 82 $this->assertTrue($this->session->hasValue(stubSession::START_TIME)); 83 83 $startTime = $this->session->getStartTime(); 84 $this->assertEqual ($this->session->getValue(stubSession::FINGERPRINT), 'foobarbaz');84 $this->assertEquals('foobarbaz', $this->session->getValue(stubSession::FINGERPRINT)); 85 85 $this->assertTrue($this->session->hasValue(stubSession::NEXT_TOKEN)); 86 86 $this->assertTrue($this->session->isNew()); … … 88 88 $nextToken = $this->session->getNextToken(); 89 89 90 $this->session = new stubTestSession( new MockstubRequest(), $startTime . '|foobarbaz|' . $nextToken);91 $this->assertEqual ($this->session->getStartTime(), $startTime);90 $this->session = new stubTestSession($this->getMock('stubRequest'), $startTime . '|foobarbaz|' . $nextToken); 91 $this->assertEquals($startTime, $this->session->getStartTime()); 92 92 $this->assertFalse($this->session->isNew()); 93 $this->assertEqual ($nextToken, $this->session->getCurrentToken());93 $this->assertEquals($nextToken, $this->session->getCurrentToken()); 94 94 $this->assertTrue($this->session->isValid()); 95 95 } … … 97 97 /** 98 98 * test that an invalid sesssion throws an exception 99 */ 100 public function testInvalidGetStartTime() 101 { 102 $this->session->invalidate(); 103 $this->assertFalse($this->session->isValid()); 104 $this->expectException('stubSessionException'); 99 * 100 * @test 101 * @expectedException stubSessionException 102 */ 103 public function invalidGetStartTime() 104 { 105 $this->session->invalidate(); 106 $this->assertFalse($this->session->isValid()); 105 107 $this->session->getStartTime(); 106 108 } … … 108 110 /** 109 111 * test that an invalid sesssion throws an exception 110 */ 111 public function testInvalidGetValue() 112 { 113 $this->session->invalidate(); 114 $this->assertFalse($this->session->isValid()); 115 $this->expectException('stubSessionException'); 112 * 113 * @test 114 * @expectedException stubSessionException 115 */ 116 public function invalidGetValue() 117 { 118 $this->session->invalidate(); 119 $this->assertFalse($this->session->isValid()); 116 120 $this->session->getValue('foo'); 117 121 } … … 119 123 /** 120 124 * test that an invalid sesssion throws an exception 121 */ 122 public function testInvalidRemoveValue() 123 { 124 $this->session->invalidate(); 125 $this->assertFalse($this->session->isValid()); 126 $this->expectException('stubSessionException'); 125 * 126 * @test 127 * @expectedException stubSessionException 128 */ 129 public function invalidRemoveValue() 130 { 131 $this->session->invalidate(); 132 $this->assertFalse($this->session->isValid()); 127 133 $this->session->removeValue('foo'); 128 134 } … … 130 136 /** 131 137 * test that an invalid sesssion throws an exception 132 */ 133 public function testInvalidGetValueKeys() 134 { 135 $this->session->invalidate(); 136 $this->assertFalse($this->session->isValid()); 137 $this->expectException('stubSessionException'); 138 * 139 * @test 140 * @expectedException stubSessionException 141 */ 142 public function invalidGetValueKeys() 143 { 144 $this->session->invalidate(); 145 $this->assertFalse($this->session->isValid()); 138 146 $this->session->getValueKeys(); 139 147 } … … 141 149 /** 142 150 * test getting a value from session 143 */ 144 public function testGetValue() 151 * 152 * @test 153 */ 154 public function getValue() 145 155 { 146 156 $this->assertNull($this->session->getValue('foo')); 147 $this->assertEqual ($this->session->getValue('foo', 'bar'), 'bar');157 $this->assertEquals('bar', $this->session->getValue('foo', 'bar')); 148 158 $this->session->putValue('foo', 'baz'); 149 $this->assertEqual ($this->session->getValue('foo'), 'baz');150 $this->assertEqual ($this->session->getValue('foo', 'bar'), 'baz');159 $this->assertEquals('baz', $this->session->getValue('foo')); 160 $this->assertEquals('baz', $this->session->getValue('foo', 'bar')); 151 161 } 152 162 153 163 /** 154 164 * test removing a value from session 155 */ 156 public function testRemoveValue() 165 * 166 * @test 167 */ 168 public function removeValue() 157 169 { 158 170 $this->assertFalse($this->session->removeValue('foo')); … … 166 178 /** 167 179 * assure that no session fixation is possible 168 */ 169 public function testSessionFixation() 180 * 181 * @test 182 */ 183 public function sessionFixation() 170 184 { 171 185 // session id is always regenerated for new sessions 172 $this->assertEqual ($this->session->getId(), 'foo');186 $this->assertEquals('foo', $this->session->getId()); 173 187 } 174 188 175 189 /** 176 190 * assure that no session hijacking is possible 177 */ 178 public function testSessionHijacking() 191 * 192 * @test 193 */ 194 public function sessionHijacking() 179 195 { 180 196 // original session started at 50 with fingerprint blub 181 $this->session = new stubTestSession( new MockstubRequest(), '50|blub|dummy');197 $this->session = new stubTestSession($this->getMock('stubRequest'), '50|blub|dummy'); 182 198 $this->assertTrue($this->session->isNew()); 183 $this->assertNotEqual ($this->session->getStartTime(), 50);184 $this->assertNotEqual ($this->session->getCurrentToken(),'dummy');199 $this->assertNotEquals(50, $this->session->getStartTime()); 200 $this->assertNotEquals('dummy', $this->session->getCurrentToken()); 185 201
