Changeset 1138
- Timestamp:
- 12/11/07 15:57:23 (10 months ago)
- Files:
-
- trunk/src/main/php/net/stubbles/websites/cache/stubAbstractWebsiteCache.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/cache/stubDefaultWebsiteCache.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/cache/stubGzipWebsiteCache.php (modified) (3 diffs)
- trunk/src/main/php/net/stubbles/websites/cache/stubWebsiteCache.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php (modified) (3 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubAbstractWebsiteCacheTestCase.php (modified) (11 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheTestCase.php (modified) (5 diffs)
- trunk/src/test/php/net/stubbles/websites/cache/stubGzipWebsiteCacheTestCase.php (modified) (9 diffs)
- trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/websites/cache/stubAbstractWebsiteCache.php
r1112 r1138 47 47 * 48 48 * @param stubRequest $request 49 * @param stubSession $session 49 50 * @param stubResponse $response 50 51 * @param string $page name of the page to be cached 51 52 * @return bool true if data was retrieved from cache, else false 52 53 */ 53 public function retrieve(stubRequest $request, stub Response $response, $page)54 public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 54 55 { 55 56 $cacheKey = $this->generateCacheKey($page); … … 63 64 } 64 65 65 if ($this->doRetrieve($request, $ response, $cacheKey) === true) {66 if ($this->doRetrieve($request, $session, $response, $cacheKey) === true) { 66 67 $this->log($page, $cacheKey, stubWebsiteCache::HIT); 67 68 return true; … … 76 77 * 77 78 * @param stubRequest $request 79 * @param stubSession $session 78 80 * @param stubResponse $response 79 81 * @param string $cacheKey 80 82 * @return bool true if data was retrieved from cache, else false 81 83 */ 82 protected abstract function doRetrieve(stubRequest $request, stub Response $response, $cacheKey);84 protected abstract function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey); 83 85 84 86 /** trunk/src/main/php/net/stubbles/websites/cache/stubDefaultWebsiteCache.php
r1112 r1138 104 104 * 105 105 * @param stubRequest $request 106 * @param stubSession $session 106 107 * @param stubResponse $response 107 108 * @param string $cacheKey 108 109 * @return bool true if successfully retrieved, else false 109 110 */ 110 protected function doRetrieve(stubRequest $request, stub Response $response, $cacheKey)111 protected function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey) 111 112 { 112 $response->write($this->cache->get($cacheKey)); 113 $contents = $this->cache->get($cacheKey); 114 $contents = str_replace('$SID', $session->getName() . '=' . $session->getId(), $contents); 115 $contents = str_replace('$SESSION_NAME', $session->getName(), $contents); 116 $contents = str_replace('$SESSION_ID', $session->getId(), $contents); 117 $response->write($contents); 113 118 return true; 114 119 } trunk/src/main/php/net/stubbles/websites/cache/stubGzipWebsiteCache.php
r1130 r1138 113 113 * 114 114 * @param stubRequest $request 115 * @param stubSession $session 115 116 * @param stubResponse $response 116 117 * @param string $page name of the page to be cached 117 118 * @return bool true if data was retrieved from cache, else false 118 119 */ 119 public function retrieve(stubRequest $request, stub Response $response, $page)120 { 121 if (parent::retrieve($request, $ response, $page) === true) {120 public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 121 { 122 if (parent::retrieve($request, $session, $response, $page) === true) { 122 123 return true; 123 124 } 124 125 125 return $this->websiteCache->retrieve($request, $ response, $page);126 return $this->websiteCache->retrieve($request, $session, $response, $page); 126 127 } 127 128 … … 130 131 * 131 132 * @param stubRequest $request 133 * @param stubSession $session 132 134 * @param stubResponse $response 133 135 * @param string $cacheKey 134 136 * @return bool true if data was retrieved from cache, else false 135 137 */ 136 protected function doRetrieve(stubRequest $request, stub Response $response, $cacheKey)138 protected function doRetrieve(stubRequest $request, stubSession $session, stubResponse $response, $cacheKey) 137 139 { 138 140 // we do not use gzipped content because we probably have to insert … … 199 201 { 200 202 $data = $response->getData(); 203 $data = str_replace('$SID', '', $data); 204 $data = str_replace('$SESSION_NAME', '', $data); 205 $data = str_replace('$SESSION_ID', '', $data); 201 206 $size = strlen($data); 202 207 $crc32 = crc32($data); trunk/src/main/php/net/stubbles/websites/cache/stubWebsiteCache.php
r1109 r1138 74 74 * 75 75 * @param stubRequest $request 76 * @param stubSession $session 76 77 * @param stubResponse $response 77 78 * @param string $page name of the page to be cached 78 79 * @return bool true if data was retrieved from cache, else false 79 80 */ 80 public function retrieve(stubRequest $request, stub Response $response, $page);81 public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page); 81 82 82 83 /** trunk/src/main/php/net/stubbles/websites/memphis/stubMemphisProcessor.php
r1137 r1138 110 110 if (null !== $this->cache) { 111 111 $this->processCacheVars($prefixRequest, $elements, $pageName, $frameId, $context); 112 if ($this->cache->retrieve($this->request, $this-> response, $pageName) === true) {112 if ($this->cache->retrieve($this->request, $this->session, $this->response, $pageName) === true) { 113 113 return; 114 114 } … … 122 122 if (null !== $this->cache) { 123 123 $this->cache->store($this->request, $this->response, $pageName); 124 $contents = str_replace('$SID', $this->session->getName() . '=' . $this->session->getId(), $this->response->getData()); 125 $contents = str_replace('$SESSION_NAME', $this->session->getName(), $contents); 126 $this->response->replaceData(str_replace('$SESSION_ID', $this->session->getId(), $contents)); 124 127 } 125 128 } … … 283 286 $this->template->addGlobalVar('PAGE_NAME', $pageName); 284 287 $this->template->addGlobalVar('VARIANT', $this->session->getValue('net.stubbles.websites.variantmanager.variant', '')); 285 $this->template->addGlobalVar('SID', $this->session->getName() . '=' . $this->session->getId()); 286 $this->template->addGlobalVar('SESSION_NAME', $this->session->getName()); 287 $this->template->addGlobalVar('SESSION_ID', $this->session->getId()); 288 if (null === $this->cache) { 289 $this->template->addGlobalVar('SID', $this->session->getName() . '=' . $this->session->getId()); 290 $this->template->addGlobalVar('SESSION_NAME', $this->session->getName()); 291 $this->template->addGlobalVar('SESSION_ID', $this->session->getId()); 292 } else { 293 $this->template->addGlobalVar('SID', '$SID'); 294 $this->template->addGlobalVar('SESSION_NAME', '$SESSION_NAME'); 295 $this->template->addGlobalVar('SESSION_ID', '$SESSION_ID'); 296 } 288 297 289 298 // check for user data trunk/src/test/php/net/stubbles/websites/cache/stubAbstractWebsiteCacheTestCase.php
r1123 r1138 24 24 ); 25 25 Mock::generate('stubRequest'); 26 Mock::generate('stubSession'); 26 27 Mock::generate('stubResponse'); 27 28 Mock::generate('stubCacheContainer'); … … 81 82 protected $mockRequest; 82 83 /** 84 * mocked session instance 85 * 86 * @var SimpleMock 87 */ 88 protected $mockSession; 89 /** 83 90 * mocked response instance 84 91 * … … 97 104 $this->abstractWebsiteCache->setReturnValue('getCacheVars', array('foo' => 'bar')); 98 105 $this->mockRequest = new MockstubRequest(); 106 $this->mockSession = new MockstubSession(); 99 107 $this->mockResponse = new MockstubResponse(); 100 108 } … … 111 119 $this->mockResponse->expectNever('addHeader'); 112 120 $this->mockCacheContainer->expectNever('has'); 113 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'baz'));121 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 114 122 $this->assertEqual($this->abstractWebsiteCache->getMissReason(), 'disabled'); 115 123 stubMode::setCurrent($currentMode); … … 126 134 $this->mockCacheContainer->expectOnce('has'); 127 135 $this->mockCacheContainer->setReturnValue('has', false); 128 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'baz'));136 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 129 137 $this->assertEqual($this->abstractWebsiteCache->getMissReason(), 'no cache file'); 130 138 } … … 136 144 { 137 145 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::MISS)); 138 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mock Response, '*'));146 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 139 147 $this->abstractWebsiteCache->setReturnValue('doRetrieve', false); 140 148 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); … … 143 151 $this->mockCacheContainer->expectOnce('has'); 144 152 $this->mockCacheContainer->setReturnValue('has', true); 145 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'baz'));153 $this->assertFalse($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 146 154 $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 147 155 } … … 153 161 { 154 162 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 155 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mock Response, '*'));163 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 156 164 $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 157 165 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); … … 160 168 $this->mockCacheContainer->expectOnce('has'); 161 169 $this->mockCacheContainer->setReturnValue('has', true); 162 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'baz'));170 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 163 171 $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 164 172 } … … 172 180 stubMode::setCurrent(stubMode::$TEST); 173 181 $this->abstractWebsiteCache->expectOnce('log', array('baz', '*', stubWebsiteCache::HIT)); 174 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mock Response, '*'));182 $this->abstractWebsiteCache->expectOnce('doRetrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, '*')); 175 183 $this->abstractWebsiteCache->setReturnValue('doRetrieve', true); 176 184 $this->abstractWebsiteCache->setReturnValue('isUsedFilesCheckEnabled', false); … … 179 187 $this->mockCacheContainer->expectOnce('has'); 180 188 $this->mockCacheContainer->setReturnValue('has', true); 181 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'baz'));189 $this->assertTrue($this->abstractWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'baz')); 182 190 $this->assertEqual($this->abstractWebsiteCache->getMissReason(), ''); 183 191 stubMode::setCurrent($currentMode); trunk/src/test/php/net/stubbles/websites/cache/stubDefaultWebsiteCacheTestCase.php
r1129 r1138 9 9 stubClassLoader::load('net.stubbles.websites.cache.stubDefaultWebsiteCache'); 10 10 Mock::generate('stubRequest'); 11 Mock::generate('stubSession'); 11 12 Mock::generate('stubResponse'); 12 13 Mock::generate('stubCacheContainer'); … … 24 25 * 25 26 * @param stubRequest $request 27 * @param stubSession $session 26 28 * @param stubResponse $response 27 29 * @param string $page name of the page to be cached 28 30 * @return bool true if data was retrieved from cache, else false 29 31 */ 30 public function retrieve(stubRequest $request, stub Response $response, $page)31 { 32 return $this->doRetrieve($request, $ response, $page);32 public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 33 { 34 return $this->doRetrieve($request, $session, $response, $page); 33 35 } 34 36 … … 103 105 protected $mockRequest; 104 106 /** 107 * mocked session instance 108 * 109 * @var SimpleMock 110 */ 111 protected $mockSession; 112 /** 105 113 * mocked response instance 106 114 * … … 117 125 $this->defaultWebsiteCache = new TeststubDefaultWebsiteCache($this->mockCacheContainer); 118 126 $this->mockRequest = new MockstubRequest(); 127 $this->mockSession = new MockstubSession(); 119 128 $this->mockResponse = new MockstubResponse(); 120 129 } … … 176 185 $this->mockCacheContainer->setReturnValue('get', 'fooContents'); 177 186 $this->mockResponse->expectOnce('write', array('fooContents')); 178 $this->assertTrue($this->defaultWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'foo'));187 $this->assertTrue($this->defaultWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 179 188 } 180 189 trunk/src/test/php/net/stubbles/websites/cache/stubGzipWebsiteCacheTestCase.php
r1130 r1138 9 9 stubClassLoader::load('net.stubbles.websites.cache.stubGzipWebsiteCache'); 10 10 Mock::generate('stubRequest'); 11 Mock::generate('stubSession'); 11 12 Mock::generate('stubResponse'); 12 13 Mock::generate('stubCacheContainer'); … … 25 26 * 26 27 * @param stubRequest $request 28 * @param stubSession $session 27 29 * @param stubResponse $response 28 30 * @param string $page name of the page to be cached 29 31 * @return bool true if data was retrieved from cache, else false 30 32 */ 31 public function retrieve(stubRequest $request, stub Response $response, $page)32 { 33 return $this->doRetrieve($request, $ response, $page);33 public function retrieve(stubRequest $request, stubSession $session, stubResponse $response, $page) 34 { 35 return $this->doRetrieve($request, $session, $response, $page); 34 36 } 35 37 … … 88 90 protected $mockRequest; 89 91 /** 92 * mocked session instance 93 * 94 * @var SimpleMock 95 */ 96 protected $mockSession; 97 /** 90 98 * mocked response instance 91 99 * … … 104 112 $this->gzipWebsiteCache = new TeststubGzipWebsiteCache($this->mockWebsiteCache); 105 113 $this->mockRequest = new MockstubRequest(); 114 $this->mockSession = new MockstubSession(); 106 115 $this->mockResponse = new MockstubResponse(); 107 116 } … … 154 163 $this->mockResponse->expectNever('addHeader'); 155 164 $this->mockResponse->expectNever('write'); 156 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'foo'));165 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 157 166 $this->assertEqual($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept cookies'); 158 167 } … … 167 176 $this->mockResponse->expectNever('addHeader'); 168 177 $this->mockResponse->expectNever('write'); 169 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'foo'));178 $this->assertFalse($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 170 179 $this->assertEqual($this->gzipWebsiteCache->getMissReason(), 'user agent does not accept compressed content'); 171 180 } … … 183 192 $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 184 193 $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 185 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'foo'));194 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 186 195 $this->assertEqual($this->gzipWebsiteCache->getMissReason(), ''); 187 196 } … … 200 209 $this->mockResponse->expectAt(1, 'write', array('cachedContents')); 201 210 $this->mockCacheContainer->setReturnValue('get', 'cachedContents'); 202 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mock Response, 'foo'));211 $this->assertTrue($this->gzipWebsiteCache->retrieve($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 203 212 $this->assertEqual($this->gzipWebsiteCache->getMissReason(), ''); 204 213 } … … 209 218 public function testStore() 210 219 { 211 $this->mockResponse->setReturnValue('getData', 'fooContent ');220 $this->mockResponse->setReturnValue('getData', 'fooContent$SIDbla$SESSION_NAMEblub$SESSION_ID'); 212 221 $this->mockWebsiteCache->expectOnce('store', array($this->mockRequest, $this->mockResponse, 'foo')); 213 222 $this->mockWebsiteCache->setReturnValue('store', true); trunk/src/test/php/net/stubbles/websites/memphis/stubMemphisProcessorTestCase.php
r1137 r1138 332 332 $memphisProcessor->expectOnce('setTemplateVars', array('*', 'foo', 'bar')); 333 333 $memphisProcessor->expectOnce('processPageElements', array('*', array('baz' => $mockPageElement), '*')); 334 $this->mockResponse->expectNever('getData'); 335 $this->mockResponse->expectNever('replaceData'); 334 336 $memphisProcessor->callDoProcess(); 335 337 } … … 355 357 $memphisProcessor->expectOnce('processPageElements', array('*', array('baz' => $mockPageElement), '*')); 356 358 $mockCache = new MockstubWebsiteCache(); 357 $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mock Response, 'foo'));359 $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 358 360 $mockCache->setReturnValue('retrieve', false); 359 361 $mockCache->expectOnce('store', array($this->mockRequest, $this->mockResponse, 'foo')); 360 362 $memphisProcessor->setWebsiteCache($mockCache); 363 $this->mockResponse->expectOnce('getData'); 364 $this->mockResponse->setReturnValue('getData', '$SID$SESSION_NAME$SESSION_ID'); 365 $this->mockSession->setReturnValue('getId', 'id'); 366 $this->mockSession->setReturnValue('getName', 'name'); 367 $this->mockResponse->expectOnce('replaceData', array('name=idnameid')); 361 368 $memphisProcessor->callDoProcess(); 362 369 } … … 381 388 $memphisProcessor->expectNever('processPageElements'); 382 389 $mockCache = new MockstubWebsiteCache(); 383 $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mock Response, 'foo'));390 $mockCache->expectOnce('retrieve', array($this->mockRequest, $this->mockSession, $this->mockResponse, 'foo')); 384 391 $mockCache->setReturnValue('retrieve', true); 385 392 $mockCache->expectNever('store'); 386 393 $memphisProcessor->setWebsiteCache($mockCache); 394 $this->mockResponse->expectNever('getData'); 395 $this->mockResponse->expectNever('replaceData'); 387 396 $memphisProcessor->callDoProcess(); 388 397 } … … 706 715 public function testSetTemplateVars2() 707 716 { 717 $mockCache = new MockstubWebsiteCache(); 718 $this->memphisProcessor->setWebsiteCache($mockCache); 708 719 $this->mockMemphisConfig->setReturnValue('getMetaTags', array()); 709 720 $this->mockMemphisTemplate->expectAt(0, 'addGlobalVar', array('UCUO_FRAME', 'foo')); … … 711 722 $this->mockMemphisTemplate->expectAt(2, 'addGlobalVar', array('PAGE_NAME', 'baz')); 712 723 $this->mockMemphisTemplate->expectAt(3, 'addGlobalVar', array('VARIANT', 'variant')); 713 $this->mockMemphisTemplate->expectAt(4, 'addGlobalVar', array('SID', ' sessionid=313'));714 $this->mockMemphisTemplate->expectAt(5, 'addGlobalVar', array('SESSION_NAME', ' sessionid'));715 $this->mockMemphisTemplate->expectAt(6, 'addGlobalVar', array('SESSION_ID', 313));724 $this->mockMemphisTemplate->expectAt(4, 'addGlobalVar', array('SID', '$SID')); 725 $this->mockMemphisTemplate->expectAt(5, 'addGlobalVar', array('SESSION_NAME', '$SESSION_NAME')); 726 $this->mockMemphisTemplate->expectAt(6, 'addGlobalVar', array('SESSION_ID', '$SESSION_ID')); 716 727 $this->mockMemphisTemplate->expectAt(7, 'addGlobalVar', array('SSL_MODE', 'yes')); 717 728 $this->mockMemphisTemplate->expectNever('addVar');
