| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/web_cache/src/lmbFullPageCacheWriter.class.php'); 10 lmb_require('limb/fs/src/lmbFs.class.php'); 11 12 class lmbFullPageCacheWriterTest extends UnitTestCase 13 { 14 protected $writer; 15 16 var $cache_dir; 17 18 function setUp() 19 { 20 $this->cache_dir = LIMB_VAR_DIR . '/fpcache/'; 21 lmbFs :: mkdir($this->cache_dir); 22 $this->writer = new lmbFullPageCacheWriter($this->cache_dir); 23 } 24 25 function tearDown() 26 { 27 lmbFs :: rm($this->cache_dir); 28 } 29 30 function testGetFailed() 31 { 32 $this->assertIdentical(false, $this->writer->get($cache = '123')); 33 } 34 35 function testGetOk() 36 { 37 $cache = '1/2/3'; 38 $this->_writeFile($this->cache_dir . '/' . $cache . '/' . $this->writer->getCacheFile(), 39 $content = 'something'); 40 $this->assertIdentical($content, $this->writer->get($cache)); 41 } 42 43 function testSave() 44 { 45 $cache = '1/2/3'; 46 $this->writer->save($cache, $content = 'whatever'); 47 48 $this->assertEqual($this->writer->get($cache), $content); 49 $this->assertTrue(file_exists($this->cache_dir . '/' . $cache . '/' . $this->writer->getCacheFile())); 50 } 51 52 function testSaveWithPossibleNameClashes() 53 { 54 $this->writer->save($cache1 = '1/2/3', 'foo'); 55 $this->writer->save($cache2 = '1/2', 'bar'); 56 $this->writer->save($cache3 = '1', 'zoo'); 57 58 //directory name conflicts with cache file name 59 $this->writer->save($cache4 = '1/2/3/' . $this->writer->getCacheFile(), 'bar'); 60 61 $this->assertEqual($this->writer->get($cache1), 'foo'); 62 $this->assertEqual($this->writer->get($cache2), 'bar'); 63 $this->assertEqual($this->writer->get($cache3), 'zoo'); 64 $this->assertFalse($this->writer->get($cache4)); 65 } 66 67 function testFlushOk() 68 { 69 $cache = '1/2/3'; 70 $this->writer->save($cache, $content = 'whatever'); 71 72 $this->assertTrue($this->writer->flush($cache)); 73 $this->assertFalse(file_exists($this->cache_dir . '/' . $cache . '/' . $this->writer->getCacheFile())); 74 } 75 76 function testFlushFailed() 77 { 78 $this->assertFalse($this->writer->flush('123')); 79 } 80 81 function testFlushAll() 82 { 83 $this->writer->save('1/2/3', 'whatever3'); 84 $this->writer->save('1', 'whatever1'); 85 $this->writer->save('1/2', 'whatever2'); 86 87 $this->writer->flushAll(); 88 89 $this->assertFalse(file_exists($this->cache_dir)); 90 } 91 92 function testGetCacheSize() 93 { 94 $this->writer->save('1/2', $c1 = 'da'); 95 $this->writer->save('1/2/3', $c2 = 'zoo'); 96 $this->writer->save('1', $c3 = 'ba-ba'); 97 98 $this->assertEqual($this->writer->getCacheSize(), strlen($c1 . $c2 . $c3)); 99 } 100 101 function _writeFile($file, $content = '') 102 { 103 lmbFs :: mkdir(dirname($file)); 104 $fh = fopen($file, 'w'); 105 fwrite($fh, $content); 106 fclose($fh); 107 } 108 } 109 110 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Dec 1 03:56:46 2008 | Cross-referenced by PHPXref 0.7 |