Changeset 1252
- Timestamp:
- 01/17/08 08:56:47 (10 months ago)
- Files:
-
- trunk/src/test/AllTests.php (modified) (1 diff)
- trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php (modified) (2 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubAbstractWebsiteCacheTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheFactoryTestCase.php (modified) (4 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheTestCase.php (modified) (12 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubGzipWebsiteCacheTestCase.php (modified) (11 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubAbstractProcessorResolverTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubDefaultProcessorResolverTestCase.php (modified) (10 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubProcessorResolverXJConfFactoryTestCase.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/processors/stubSimpleProcessorResolverTestCase.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/test/AllTests.php
r1250 r1252 7 7 * @subpackage test 8 8 */ 9 ini_set('memory_limit', -1); 9 10 if (defined('PHPUnit_MAIN_METHOD') === false) { 10 11 define('PHPUnit_MAIN_METHOD', 'src_test_AllTests::main'); trunk/src/test/php/net/stubbles/websites/WebsitesTestSuite.php
r1250 r1252 28 28 29 29 // cache tests 30 /*$suite->addTestFile($dir . '/cache/stubAbstractWebsiteCacheTestCase.php');30 $suite->addTestFile($dir . '/cache/stubAbstractWebsiteCacheTestCase.php'); 31 31 $suite->addTestFile($dir . '/cache/stubDefaultWebsiteCacheFactoryTestCase.php'); 32 32 $suite->addTestFile($dir . '/cache/stubDefaultWebsiteCacheTestCase.php'); 33 $suite->addTestFile($dir . '/cache/stubGzipWebsiteCacheTestCase.php'); */33 $suite->addTestFile($dir . '/cache/stubGzipWebsiteCacheTestCase.php'); 34 34 35 35 // memphis tests … … 39 39 40 40 // processors tests 41 /*$suite->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php');41 $suite->addTestFile($dir . '/processors/stubAbstractProcessorResolverTestCase.php'); 42 42 $suite->addTestFile($dir . '/processors/stubDefaultProcessorResolverTestCase.php'); 43 43 $suite->addTestFile($dir . '/processors/stubProcessorResolverXJConfFactoryTestCase.php'); 44 $suite->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); */44 $suite->addTestFile($dir . '/processors/stubSimpleProcessorResolverTestCase.php'); 45 45 46 46 // xml tests trunk/src/test/php/net/stubbles/websites/cache/stubAbstractWebsiteCacheTestCase.php
r1231 r1252 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::cache::stubAbstractWebsiteCache'); 10 Mock::generatePartial('stubAbstractWebsiteCache',11 'PartialMockstubAbstractWebsiteCache',12 array('doRetrieve',13 'doStore',14 'isUsedFilesCheckEnabled',15 'getUsedFiles',16 'log',17 'getCacheVars',18 'setCheckFiles',19 'addCacheVar',20 'addCacheVars',21 'addUsedFile',22 'addUsedFiles'23 )24 );25 Mock::generate('stubRequest');26 Mock::generate('stubSession');27 Mock::generate('stubResponse');28 Mock::generate('stubCacheContainer');29 10 /** 30 11 * Helper class for unit test to set the cache container to be used. … … 33 14 * @subpackage websites_cache_test 34 15 */ 35 class TestPartialMockstubAbstractWebsiteCache extends PartialMockstubAbstractWebsiteCache16 abstract class TeststubAbstractWebsiteCache extends stubAbstractWebsiteCache 36 17 { 37 18 /** … … 61 42 * @subpackage websites_cache_test 62 43 */ 63 class stubAbstractWebsiteCacheTestCase extends UnitTestCase44 class stubAbstractWebsiteCacheTestCase extends PHPUnit_Framework_TestCase 64 45 { 65 46 /** 66 47 * instance to be used for tests 67 48 * 68 * @var Test PartialMockstubAbstractWebsiteCache49 * @var TeststubAbstractWebsiteCache 69 50 */ 70 51 protected $abstractWebsiteCache; … … 72 53 * mocked cache container instance 73 54 * 74 * @var SimpleMock55 * @var PHPUnit_Framework_MockObject_MockObject 75 56 */ 76 57 protected $mockCacheContainer; … … 78 59 * mocked request instance 79 60 * 80 * @var SimpleMock61 * @var PHPUnit_Framework_MockObject_MockObject 81 62 */ 82 63 protected $mockRequest; … … 84 65 * mocked session instance 85 66 * 86 * @var SimpleMock67 * @var PHPUnit_Framework_MockObject_MockObject 87 68 */ 88 69 protected $mockSession; … … 90 71 * mocked response instance 91 72 * 92 * @var SimpleMock73 * @var PHPUnit_Framework_MockObject_MockObject 93 74 */ 94 75 protected $mockResponse; 95 76 96 77 /** 97 78 * set up test environment … … 99 80 public function setUp() 100 81 { 101 $this->abstractWebsiteCache = new TestPartialMockstubAbstractWebsiteCache(); 102 $this->mockCacheContainer = new MockstubCacheContainer(); 82 $this->abstractWebsiteCache = $this->getMock('TeststubAbstractWebsiteCache', array('doRetrieve', 83 'doStore', 84 'isUsedFilesCheckEnabled', 85 'getUsedFiles', 86 'log', 87 'getCacheVars', 88 'setCheckFiles', 89 'addCacheVar', 90 'addCacheVars', 91 'addUsedFile', 92 'addUsedFiles' 93 ) 94 ); 95 $this->mockCacheContainer = $this->getMock('stubCacheContainer'); 103 96 $this->abstractWebsiteCache->setCacheContainer($this->mockCacheContainer); 104 $this->abstractWebsiteCache->setReturnValue('getCacheVars', array('foo' => 'bar')); 105 $this->mockRequest = new MockstubRequest(); 106 $this->mockSession = new MockstubSession(); 107 $this->mockResponse = new MockstubResponse(); 97 $this->abstractWebsiteCache->expects($this->any()) 98 ->method('getCacheVars') 99 ->will($this->returnValue(array('foo' => 'bar'))); 100 $this->mockRequest = $this->getMock('stubRequest'); 101 $this->mockSession = $this->getMock('stubSession'); 102 $this->mockResponse = $this->getMock('stubResponse'); 108 103 stubMode::setCurrent(stubMode::$PROD); 109 104 } … … 111 106 /** 112 107 * assure that disabled caching leads to nothing set in the response 113 */ 114 public function testRetrieveCachingDisabled() 108 * 109 * @test 110 */ 111 public function retrieveCachingDisabled() 115 112 { 116 113 stubMode::setCurrent(stubMode::$DEV); 117 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::MISS)); 118 $this->abstractWebsiteCache->expectNever('doRetrieve'); 119 $this->mockResponse->expectNever('addHeader'); 120 $this->mockCacheContainer->expectNever('has'); 114 $this->abstractWebsiteCache->expects($this->once()) 115 ->method('log') 116 ->with($this->equalTo('baz'), $this->anything(), $this->equalTo(stubWebsiteCache::MISS)); 117 $this->abstractWebsiteCache->expects($this->never())->method('doRetrieve'); 118 $this->mockResponse->expects($this->never())->method('addHeader'); 119 $this->mockCacheContainer->expects($this->never())->method('has'); 121 120 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 122 $this->assertEqual ($this->abstractWebsiteCache->getMissReason(), 'disabled');121 $this->assertEquals('disabled', $this->abstractWebsiteCache->getMissReason()); 123 122 } 124 123 125 124 /** 126 125 * assure that a missing cache entry leads to nothing set in the response 127 */ 128 public function testCachingEntryMissing() 129 { 130 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::MISS)); 131 $this->abstractWebsiteCache->expectNever('doRetrieve'); 132 $this->mockResponse->expectNever('addHeader'); 133 $this->mockCacheContainer->expectOnce('has'); 134 $this->mockCacheContainer->setReturnValue('has', false); 126 * 127 * @test 128 */ 129 public function cachingEntryMissing() 130 { 131 $this->abstractWebsiteCache->expects($this->once()) 132 ->method('log') 133 ->with($this->equalTo('baz'), $this->anything(), $this->equalTo(stubWebsiteCache::MISS)); 134 $this->abstractWebsiteCache->expects($this->never())->method('doRetrieve'); 135 $this->mockResponse->expects($this->never())->method('addHeader'); 136 $this->mockCacheContainer->expects($this->once())->method('has')->will($this->returnValue(false)); 135 137 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 136 $this->assertEqual ($this->abstractWebsiteCache->getMissReason(), 'no cache file');138 $this->assertEquals('no cache file', $this->abstractWebsiteCache->getMissReason()); 137 139 } 138 140 139 141 /** 140 142 * assure that a failing to set the response works as expected 141 */ 142 public function testCachingEntryFoundAndFailedToSet() 143 { 144 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::MISS)); 145 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 146 $this->abstractWebsiteCache->setReturnValue('doRetrieve', false); 147 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 148 $this->abstractWebsiteCache->expectNever('getUsedFiles'); 149 $this->mockResponse->expectNever('addHeader'); 150 $this->mockCacheContainer->expectOnce('has'); 151 $this->mockCacheContainer->setReturnValue('has', true); 143 * 144 * @test 145 */ 146 public function cachingEntryFoundAndFailedToSet() 147 { 148 $this->abstractWebsiteCache->expects($this->once()) 149 ->method('log') 150 ->with($this->equalTo('baz'), $this->anything(), $this->equalTo(stubWebsiteCache::MISS)); 151 $this->abstractWebsiteCache->expects($this->once()) 152 ->method('doRetrieve') 153 ->with($this->equalTo($this->mockRequest), $this->equalTo($this->mockSession), $this->equalTo($this->mockResponse)) 154 ->will($this->returnValue(false)); 155 $this->abstractWebsiteCache->expects($this->once())->method('isUsedFilesCheckEnabled')->will($this->returnValue(false)); 156 $this->abstractWebsiteCache->expects($this->never())->method('getUsedFiles'); 157 $this->mockResponse->expects($this->never())->method('addHeader'); 158 $this->mockCacheContainer->expects($this->once())->method('has')->will($this->returnValue(true)); 152 159 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 153 $this->assertEqual ($this->abstractWebsiteCache->getMissReason(), '');160 $this->assertEquals('', $this->abstractWebsiteCache->getMissReason()); 154 161 } 155 162 156 163 /** 157 164 * assure that a response data is set 158 */ 159 public function testCachingEntryFound() 160 { 161 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 162 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 163 $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 164 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 165 $this->abstractWebsiteCache->expectNever('getUsedFiles'); 166 $this->mockResponse->expectNever('addHeader'); 167 $this->mockCacheContainer->expectOnce('has'); 168 $this->mockCacheContainer->setReturnValue('has', true); 165 * 166 * @test 167 */ 168 public function cachingEntryFound() 169 { 170 $this->abstractWebsiteCache->expects($this->once()) 171 ->method('log') 172 ->with($this->equalTo('baz'), $this->anything(), $this->equalTo(stubWebsiteCache::HIT)); 173 $this->abstractWebsiteCache->expects($this->once()) 174 ->method('doRetrieve') 175 ->with($this->equalTo($this->mockRequest), $this->equalTo($this->mockSession), $this->equalTo($this->mockResponse)) 176 ->will($this->returnValue(true)); 177 $this->abstractWebsiteCache->expects($this->once())->method('isUsedFilesCheckEnabled')->will($this->returnValue(false)); 178 $this->abstractWebsiteCache->expects($this->never())->method('getUsedFiles'); 179 $this->mockResponse->expects($this->never())->method('addHeader'); 180 $this->mockCacheContainer->expects($this->once())->method('has')->will($this->returnValue(true)); 169 181 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 170 $this->assertEqual ($this->abstractWebsiteCache->getMissReason(), '');182 $this->assertEquals('', $this->abstractWebsiteCache->getMissReason()); 171 183 } 172 184 173 185 /** 174 186 * assure that a response data is set 175 */ 176 public function testCachingEntryFoundTestMode() 187 * 188 * @test 189 */ 190 public function cachingEntryFoundTestMode() 177 191 { 178 192 stubMode::setCurrent(stubMode::$TEST); 179 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 180 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 181 $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 182 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); 183 $this->abstractWebsiteCache->expectNever('getUsedFiles'); 184 $this->mockResponse->expectOnce('addHeader'); 185 $this->mockCacheContainer->expectOnce('has'); 186 $this->mockCacheContainer->setReturnValue('has', true); 193 $this->abstractWebsiteCache->expects($this->once()) 194 ->method('log') 195 ->with($this->equalTo('baz'), $this->anything(), $this->equalTo(stubWebsiteCache::HIT)); 196 $this->abstractWebsiteCache->expects($this->once()) 197 ->method('doRetrieve') 198 ->with($this->equalTo($this->mockRequest), $this->equalTo($this->mockSession), $this->equalTo($this->mockResponse)) 199 ->will($this->returnValue(true)); 200 $this->abstractWebsiteCache->expects($this->once())->method('isUsedFilesCheckEnabled')->will($this->returnValue(false)); 201 $this->abstractWebsiteCache->expects($this->never())->method('getUsedFiles'); 202 $this->mockResponse->expects($this->once())->method('addHeader'); 203 $this->mockCacheContainer->expects($this->once())->method('has')->will($this->returnValue(true)); 187 204 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 188 $this->assertEqual ($this->abstractWebsiteCache->getMissReason(), '');205 $this->assertEquals('', $this->abstractWebsiteCache->getMissReason()); 189 206 } 190 207 191 208 /** 192 209 * assure that disabled caching leads to no store 193 */ 194 public function testStoreCachingDisabled() 210 * 211 * @test 212 */ 213 public function storeCachingDisabled() 195 214 { 196 215 stubMode::setCurrent(stubMode::$DEV); 197 $this->abstractWebsiteCache->expect Never('doStore');216 $this->abstractWebsiteCache->expects($this->never())->method('doStore'); 198 217 $this->assertFalse($this->abstractWebsiteCache->store($this->mockRequest, $this->mockResponse, 'baz')); 199 218 } … … 201 220 /** 202 221 * assure that disabled caching leads to storing data 203 */ 204 public function testStore() 205 { 206 $this->abstractWebsiteCache->expect('doStore', array($this->mockRequest, $this->mockResponse, '*')); 207 $this->abstractWebsiteCache->setReturnValueAt(0, 'doStore', false); 208 $this->abstractWebsiteCache->setReturnValueAt(1, 'doStore', true); 222 * 223 * @test 224 */ 225 public function store() 226 { 227 $this->abstractWebsiteCache->expects($this->exactly(2)) 228 ->method('doStore') 229 ->with($this->equalTo($this->mockRequest), $this->equalTo($this->mockResponse)) 230 ->will($this->onConsecutiveCalls(false, true)); 209 231 $this->assertFalse($this->abstractWebsiteCache->store($this->mockRequest, $this->mockResponse, 'baz')); 210 232 $this->assertTrue($this->abstractWebsiteCache->store($this->mockRequest, $this->mockResponse, 'baz')); trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheFactoryTestCase.php
r1231 r1252 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::cache::stubDefaultWebsiteCacheFactory'); 10 Mock::generate('stubProcessor');11 Mock::generate('stubCachableProcessor');12 Mock::generate('stubCacheContainer');13 10 /** 14 11 * Tests for net::stubbles::websites::cache::stubDefaultWebsiteCacheFactory. … … 17 14 * @subpackage websites_cache_test 18 15 */ 19 class stubDefaultWebsiteCacheFactoryTestCase extends UnitTestCase16 class stubDefaultWebsiteCacheFactoryTestCase extends PHPUnit_Framework_TestCase 20 17 { 21 18 /** … … 36 33 /** 37 34 * assure that a cachable processor does get a website cache 35 * 36 * @test 37 * @expectedException stubRuntimeException 38 38 */ 39 public function testCachableProcessorWithoutConfiguredCache()39 public function cachableProcessorWithoutConfiguredCache() 40 40 { 41 $cachableProcessor = new MockstubCachableProcessor(); 42 $this->expectException('stubRuntimeException'); 41 $cachableProcessor = $this->getMock('stubCachableProcessor'); 43 42 $this->defaultWebsiteCacheFactory->configure($cachableProcessor); 44 43 } … … 46 45 /** 47 46 * assure that a cachable processor does get a website cache 47 * 48 * @test 48 49 */ 49 public function testCachableProcessorWithConfiguredCache()50 public function cachableProcessorWithConfiguredCache() 50 51 { 51 $mockCacheContainer = new MockstubCacheContainer();52 $mockCacheContainer-> setReturnValue('getId', __CLASS__);52 $mockCacheContainer = $this->getMock('stubCacheContainer'); 53 $mockCacheContainer->expects($this->any())->method('getId')->will($this->returnValue(__CLASS__)); 53 54 stubCache::addContainer($mockCacheContainer); 54 $cachableProcessor = new MockstubCachableProcessor();55 $cachableProcessor->expect Once('setWebsiteCache');55 $cachableProcessor = $this->getMock('stubCachableProcessor'); 56 $cachableProcessor->expects($this->once())->method('setWebsiteCache'); 56 57 $this->defaultWebsiteCacheFactory->configure($cachableProcessor); 57 58 } trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheTestCase.php
r1231 r1252 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::cache::stubDefaultWebsiteCache'); 10 Mock::generate('stubRequest');11 Mock::generate('stubSession');12 Mock::generate('stubResponse');13 Mock::generate('stubCacheContainer');14 10 /** 15 11 * Helper class for unit test to access some methods without using implementation … … 84 80 * @subpackage websites_cache_test 85 81 */ 86 class stubDefaultWebsiteCacheTestCase extends UnitTestCase82 class stubDefaultWebsiteCacheTestCase extends PHPUnit_Framework_TestCase 87 83 { 88 84 /** … … 95 91 * mocked cache container instance 96 92 * 97 * @var SimpleMock93 * @var PHPUnit_Framework_MockObject_MockObject 98 94 */ 99 95 protected $mockCacheContainer; … … 101 97 * mocked request instance 102 98 * 103 * @var SimpleMock99 * @var PHPUnit_Framework_MockObject_MockObject 104 100 */ 105 101 protected $mockRequest; … … 107 103 * mocked session instance 108 104 * 109 * @var SimpleMock105 * @var PHPUnit_Framework_MockObject_MockObject 110 106 */ 111 107 protected $mockSession; … … 113 109 * mocked response instance 114 110 * 115 * @var SimpleMock111 * @var PHPUnit_Framework_MockObject_MockObject 116 112 */ 117 113 protected $mockResponse; … … 122 118 public function setUp() 123 119 { 124 $this->mockCacheContainer = new MockstubCacheContainer();120 $this->mockCacheContainer = $this->getMock('stubCacheContainer'); 125 121 $this->defaultWebsiteCache = new TeststubDefaultWebsiteCache($this->mockCacheContainer); 126 $this->mockRequest = new MockstubRequest();127 $this->mockSession = new MockstubSession();128 $this->mockResponse = new MockstubResponse();122 $this->mockRequest = $this->getMock('stubRequest'); 123 $this->mockSession = $this->getMock('stubSession'); 124 $this->mockResponse = $this->getMock('stubResponse'); 129 125 } 130 126 … … 134 130 public function testCacheContainer() 135 131 { 136 $this->assert Reference($this->defaultWebsiteCache->getCacheContainer(), $this->mockCacheContainer);132 $this->assertSame($this->mockCacheContainer, $this->defaultWebsiteCache->getCacheContainer()); 137 133 } 138 134 139 135 /** 140 136 * test that check files switch is handled correct 141 */ 142 public function testCheckFiles() 137 * 138 * @test 139 */ 140 public function checkFiles() 143 141 { 144 142 $this->assertFalse($this->defaultWebsiteCache->getCheckFiles()); … … 149 147 /** 150 148 * assert that cache variables are handled correct 151 */ 152 public function testCacheVars() 153 { 154 $this->assertEqual($this->defaultWebsiteCache->retrieveCacheVars(), array()); 149 * 150 * @test 151 */ 152 public function cacheVars() 153 { 154 $this->assertEquals(array(), $this->defaultWebsiteCache->retrieveCacheVars()); 155 155 $this->defaultWebsiteCache->addCacheVar('foo', 'bar'); 156 $this->assertEqual ($this->defaultWebsiteCache->retrieveCacheVars(), array('foo' => 'bar'));156 $this->assertEquals(array('foo' => 'bar'), $this->defaultWebsiteCache->retrieveCacheVars()); 157 157 $this->defaultWebsiteCache->addCacheVars(array('bar' => 'baz')); 158 $this->assertEqual($this->defaultWebsiteCache->retrieveCacheVars(), array('foo' => 'bar', 159 'bar' => 'baz' 160 ) 158 $this->assertEquals(array('foo' => 'bar', 159 'bar' => 'baz' 160 ), 161 $this->defaultWebsiteCache->retrieveCacheVars() 161 162 ); 162 163 } … … 164 165 /** 165 166 * assert that used files are handled correct 166 */ 167 public function testUsedFiles() 168 { 169 $this->assertEqual($this->defaultWebsiteCache->retrieveUsedFiles(), array()); 167 * 168 * @test 169 */ 170 public function usedFiles() 171 { 172 $this->assertEquals(array(), $this->defaultWebsiteCache->retrieveUsedFiles()); 170 173 $this->defaultWebsiteCache->addUsedFile('foo.bar'); 171 $this->assertEqual ($this->defaultWebsiteCache->retrieveUsedFiles(), array('foo.bar' => 'foo.bar'));174 $this->assertEquals(array('foo.bar' => 'foo.bar'), $this->defaultWebsiteCache->retrieveUsedFiles()); 172 175 $this->defaultWebsiteCache->addUsedFiles(array('bar.baz')); 173 $this->assertEqual($this->defaultWebsiteCache->retrieveUsedFiles(), array('foo.bar' => 'foo.bar', 174 'bar.baz' => 'bar.baz' 175 ) 176 $this->assertEquals(array('foo.bar' => 'foo.bar', 177 'bar.baz' => 'bar.baz' 178 ), 179 $this->defaultWebsiteCache->retrieveUsedFiles() 176 180 ); 177 181 } … … 179 183 /** 180 184 * assure that disabled caching leads to nothing set in the response 181 */ 182 public function testRetrieve() 183 { 184 $this->mockCacheContainer->expectOnce('get', array('foo')); 185 $this->mockCacheContainer->setReturnValue('get', 'fooContents'); 186 $this->mockResponse->expectOnce('write', array('fooContents')); 185 * 186 * @test 187 */ 188 public function retrieve() 189 { 190 $this->mockCacheContainer->expects($this->once()) 191 ->method('get') 192 ->with($this->equalTo('foo')) 193 ->will($this->returnValue('fooContents')); 194 $this->mockResponse->expects($this->once()) 195 ->method('write') 196 ->with($this->equalTo('fooContents')); 187 197 $this->assertTrue($this->defaultWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 188 198 } … … 190 200 /** 191 201 * assure that a missing cache entry leads to nothing set in the response 192 */ 193 public function testStore() 194 { 195 $this->mockResponse->expectOnce('getData'); 196 $this->mockResponse->setReturnValue('getData', 'fooContents'); 197 $this->mockCacheContainer->expectOnce('put', array('foo', 'fooContents')); 198 $this->mockCacheContainer->setReturnValue('put', 11); 202 * 203 * @test 204 */ 205 public function store() 206 { 207 $this->mockResponse->expects($this->once()) 208 ->method('getData') 209 ->will($this->returnValue('fooContents')); 210 $this->mockCacheContainer->expects($this->once()) 211 ->method('put') 212 ->with($this->equalTo('foo'), $this->equalTo('fooContents')) 213 ->will($this->returnValue(11)); 199 214 $this->assertTrue($this->defaultWebsiteCache->store($this->mockRequest, $this->mockResponse, 'foo')); 200 215 } trunk/src/test/php/net/stubbles/websites/cache/stubGzipWebsiteCacheTestCase.php
r1231 r1252 8 8 */ 9 9 stubClassLoader::load('net::stubbles::websites::cache::stubGzipWebsiteCache'); 10 Mock::generate('stubRequest');11 Mock::generate('stubSession');12 Mock::generate('stubResponse');13 Mock::generate('stubCacheContainer');14 Mock::generate('stubWebsiteCache');15 10 /** 16 11 * Helper class for unit test to access some methods without using implementation … … 63 58 * @subpackage websites_cache_test 64 59 */ 65 class stubGzipWebsiteCacheTestCase extends UnitTestCase60 class stubGzipWebsiteCacheTestCase extends PHPUnit_Framework_TestCase 66 61 { 67 62 /** … … 74 69 * mocked decorated website cache 75 70 * 76 * @var SimpleMock71 * @var PHPUnit_Framework_MockObject_MockObject 77 72 */ 78 73 protected $mockWebsiteCache; … … 80 75 * mocked cache container instance 81 76 * 82 * @var SimpleMock77 * @var PHPUnit_Framework_MockObject_MockObject 83 78 */ 84 79 protected $mockCacheContainer; … … 86 81 * mocked request instance 87 82 * 88 * @var SimpleMock83 * @var PHPUnit_Framework_MockObject_MockObject 89 84 */ 90 85 protected $mockRequest; … … 92 87 * mocked session instance 93 88 * 94 * @var SimpleMock89 * @var PHPUnit_Framework_MockObject_MockObject 95 90 */ 96 91 protected $mockSession; … … 98 93 * mocked response instance 99 94 * 100 * @var SimpleMock95 * @var PHPUnit_Framework_MockObject_MockObject 101 96 */ 102 97 protected $mockResponse; … … 107 102 public function setUp() 108 103 { 109 $this->mockWebsiteCache = new MockstubWebsiteCache();110 $this->mockCacheContainer = new MockstubCacheContainer();111 $this->mockWebsiteCache-> setReturnValue('getCacheContainer', $this->mockCacheContainer);104 $this->mockWebsiteCache = $this->getMock('stubWebsiteCache'); 105 $this->mockCacheContainer = $this->getMock('stubCacheContainer'); 106 $this->mockWebsiteCache->expects($this->any())->method('getCacheContainer')->will($this->returnValue($this->mockCacheContainer)); 112 107 $this->gzipWebsiteCache = new TeststubGzipWebsiteCache($this->mockWebsiteCache); 113 $this->mockRequest = new MockstubRequest();114 $this->mockSession = new MockstubSession();115 $this->mockResponse = new MockstubResponse();108 $this->mockRequest = $this->getMock('stubRequest'); 109 $this->mockSession = $this->getMock('stubSession'); 110 $this->mockResponse = $this->getMock('stubResponse'); 116 111 } 117 112 118 113 /** 119 114 * assert that correct cache container is returned 120 */ 121 public function testCacheContainer() 122 { 123 $this->assertReference($this->gzipWebsiteCache->getCacheContainer(), $this->mockCacheContainer); 115 * 116 * @test 117 */ 118 public function cacheContainer() 119 { 120 $this->assertSame($this->mockCacheContainer, $this->gzipWebsiteCache->getCacheContainer()); 124 121 } 125 122 126 123 /** 127 124 * test that check files switch is handled correct 128 */ 129 public function testCheckFiles() 130 { 131 $this->mockWebsiteCache->expectOnce('setCheckFiles', array(true)); 125 * 126 * @test 127 */ 128 public function checkFiles() 129 { 130 $this->mockWebsiteCache->expects($this->once())->method('setCheckFiles')->with($this->equalTo(true)); 132 131 $this->gzipWebsiteCache->setCheckFiles(true); 133 132 } … … 135 134 /** 136 135 * assert that cache variables are handled correct 137 */ 138 public function testCacheVars() 139 { 140 $this->mockWebsiteCache->expectOnce('addCacheVar', array('foo', 'bar')); 136 * 137 * @test 138 */ 139 public function cacheVars() 140 { 141 $this->mockWebsiteCache->expects($this->once())->method('addCacheVar')->with($this->equalTo('foo'), $this->equalTo('bar')); 141 142 $this->gzipWebsiteCache->addCacheVar('foo', 'bar'); 142 $this->mockWebsiteCache->expect Once('addCacheVars', array(array('foo' => 'bar')));143 $this->mockWebsiteCache->expects($this->once())->method('addCacheVars')->with($this->equalTo((array('foo' => 'bar')))); 143 144 $this->gzipWebsiteCache->addCacheVars(array('foo' => 'bar')); 144 145 } … … 146 147 /** 147 148 * assert that used files are handled correct 148 */ 149 public function testUsedFiles() 150 { 151 $this->mockWebsiteCache->expectOnce('addUsedFile', array('foo.bar')); 149 * 150 * @test 151 */ 152 public function usedFiles() 153 { 154 $this->mockWebsiteCache->expects($this->once())->method('addUsedFile')->with($this->equalTo('foo.bar')); 152 155 $this->gzipWebsiteCache->addUsedFile('foo.bar'); 153 $this->mockWebsiteCache->expect Once('addUsedFiles', array(array('foo.bar')));156 $this->mockWebsiteCache->expects($this->once())->method('addUsedFiles')->with($this->equalTo(array('foo.bar'))); 154 157 $this->gzipWebsiteCache->addUsedFiles(array('foo.bar')); 155 158 } … … 157 160 /** 158 161 * assert that gzip cache is not active when cookies are not accepted 159 */ 160 public function testRetrieveCookiesNotAccepted() 161 { 162 $this->mockRequest->setReturnValue('acceptsCookies', false); 163 $this->mockResponse->expectNever('addHeader'); 164 $this->mockResponse->expectNever('write'); 162 * 163 * @test 164 */ 165 public function retrieveCookiesNotAccepted() 166 { 167 $this->mockRequest->expects($this->once())->method('acceptsCookies')->will($this->returnValue(false)); 168 $this->mockResponse->expects($this->never())->method('addHeader'); 169 $this->mockResponse->expects($this->never())->method('write'); 165 170 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 166 $this->assertEqual ($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept cookies');171 $this->assertEquals('user agent does not accept cookies', $this->gzipWebsiteCache->getMissReason()); 167 172 } 168 173 169 174 /** 170 175 * assert that gzip cache is not active when compression is not accepted 171 */ 172 public function testRetrieveCompressionNotAccepted() 173 { 174 $this->mockRequest->setReturnValue('acceptsCookies', true); 175 $this->mockRequest->setReturnValue('validateValue', false); 176 $this->mockResponse->expectNever('addHeader'); 177 $this->mockResponse->expectNever('write'); 176 * 177 * @test 178 */ 179 public function retrieveCompressionNotAccepted() 180 { 181 $this->mockRequest->expects($this->once())->method('acceptsCookies')->will($this->returnValue(true)); 182 $this->mockRequest->expects($this->any())->method('validateValue')->will($this->returnValue(false)); 183 $this->mockResponse->expects($this->never())->method('addHeader'); 184 $this->mockResponse->expects($this->never())->method('write'); 178 185 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 179 $this->assertEqual ($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept compressed content');186 $this->assertEquals('user agent does not accept compressed content', $this->gzipWebsiteCache->getMissReason()); 180 187 } 181 188 182 189 /** 183 190 * assert that gzip cache returns data in correct compression 184 */ 185 public function testRetrieveXGzipCompression() 186 { 187 $this->mockRequest->setReturnValue('acceptsCookies', true); 188 $this->mockRequest->setReturnValue('validateValue', true); 189 $this->mockResponse->expectOnce('addHeader', array('Content-Encoding', stubGzipWebsiteCache::X_GZIP)); 190 $this->mockResponse->expectCallcount('write', 2); 191 $this->mockResponse->expectAt(0, 'write', array(stubGzipWebsiteCache::HEADER)); 192 $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 193 $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 191 * 192 * @test 193 */ 194 public function retrieveXGzipCompression() 195 { 196 $this->mockRequest->expects($this->once())->method('acceptsCookies')->will($this->returnValue(true)); 197 $this->mockRequest->expects($this->once())->method('validateValue')->will($this->returnValue(true)); 198 $this->mockResponse->expects($this->once())->method('addHeader')->with($this->equalTo('Content-Encoding'), $this->equalTo(stubGzipWebsiteCache::X_GZIP)); 199 $this->mockResponse->expects($this->at(1)) 200 ->method('write') 201 ->with(($this->equalTo(stubGzipWebsiteCache::HEADER))); 202 $this->mockCacheContainer->expects($this->once())->method('get')->will($this->returnValue('cachedContents')); 194 203 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 195 $this->assertEqual ($this->gzipWebsiteCache->getMissReason(), '');204 $this->assertEquals('', $this->gzipWebsiteCache->getMissReason()); 196 205 } 197 206 198 207 /** 199 208 * assert that gzip cache returns data in correct compression 200 */ 201 public function testRetrieveGzipCompression() 202 { 203 $this->mockRequest->setReturnValue('acceptsCookies', true); 204 $this->mockRequest->setReturnValueAt(0, 'validateValue', false); 205 $this->mockRequest->setReturnValueAt(1, 'validateValue', true); 206 $this->mockResponse->expectOnce('addHeader', array('Content-Encoding', stubGzipWebsiteCache::GZIP)); 207 $this->mockResponse->expectCallcount('write', 2); 208 $this->mockResponse->expectAt(0, 'write', array(stubGzipWebsiteCache::HEADER)); 209 $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 210 $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 209 * 210 * @test 211 */ 212 public function retrieveGzipCompression() 213 { 214 $this->mockRequest->expects($this->once())->method('acceptsCookies')->will($this->returnValue(true)); 215 $this->mockRequest->expects($this->exactly(2))->method('validateValue')->will($this->onConsecutiveCalls(false, true)); 216 $this->mockResponse->expects($this->once())->method('addHeader')->with($this->equalTo('Content-Encoding'), $this->equalTo(stubGzipWebsiteCache::GZIP)); 217 $this->mockResponse->expects($this->at(1)) 218 ->method('write') 219 ->with(($this->equalTo(stubGzipWebsiteCache::HEADER))); 220 $this->mockCacheContainer->expects($this->once())->method('get')->will($this->returnValue('cachedContents')); 211 221 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 212 $this->assertEqual ($this->gzipWebsiteCache->getMissReason(), '');222 $this->assertEquals('', $this->gzipWebsiteCache->getMissReason()); 213 223 } 214 224 215 225 /** 216 226 * assert that response data is stored 217 */ 218 public function testStore() 219 { 220 $this->mockResponse->setReturnValue('getData', 'fooContent$SIDbla$SESSION_NAMEblub$SESSION_ID'); 221 $this->mockWebsiteCache->expectOnce('store', array($this->mockRequest, $this->mockResponse, 'foo')); 222 $this->mockWebsiteCache->setReturnValue('store', true); 223 $this->mockCacheContainer->expectOnce('put', array('foo', '*')); 227 * 228 * @test 229 */ 230 public function store() 231 &nbs
