Cache: port test cases to PHPUnit
This commit is contained in:
parent
7237ebf08b
commit
177537dbcc
2 changed files with 47 additions and 47 deletions
42
tests/lib/files/cache/cache.php
vendored
42
tests/lib/files/cache/cache.php
vendored
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace Test\Files\Cache;
|
namespace Test\Files\Cache;
|
||||||
|
|
||||||
class Cache extends \UnitTestCase {
|
class Cache extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Temporary $storage;
|
* @var \OC\Files\Storage\Temporary $storage;
|
||||||
*/
|
*/
|
||||||
|
@ -26,56 +26,56 @@ class Cache extends \UnitTestCase {
|
||||||
$data2 = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
|
$data2 = array('size' => 1000, 'mtime' => 20, 'mimetype' => 'foo/file');
|
||||||
|
|
||||||
$this->assertFalse($this->cache->inCache($file1));
|
$this->assertFalse($this->cache->inCache($file1));
|
||||||
$this->assertEqual($this->cache->get($file1), null);
|
$this->assertEquals($this->cache->get($file1), null);
|
||||||
|
|
||||||
$id1 = $this->cache->put($file1, $data1);
|
$id1 = $this->cache->put($file1, $data1);
|
||||||
$this->assertTrue($this->cache->inCache($file1));
|
$this->assertTrue($this->cache->inCache($file1));
|
||||||
$cacheData1 = $this->cache->get($file1);
|
$cacheData1 = $this->cache->get($file1);
|
||||||
foreach ($data1 as $key => $value) {
|
foreach ($data1 as $key => $value) {
|
||||||
$this->assertEqual($value, $cacheData1[$key]);
|
$this->assertEquals($value, $cacheData1[$key]);
|
||||||
}
|
}
|
||||||
$this->assertEqual($cacheData1['mimepart'], 'foo');
|
$this->assertEquals($cacheData1['mimepart'], 'foo');
|
||||||
$this->assertEqual($cacheData1['fileid'], $id1);
|
$this->assertEquals($cacheData1['fileid'], $id1);
|
||||||
$this->assertEqual($id1, $this->cache->getId($file1));
|
$this->assertEquals($id1, $this->cache->getId($file1));
|
||||||
|
|
||||||
$this->assertFalse($this->cache->inCache($file2));
|
$this->assertFalse($this->cache->inCache($file2));
|
||||||
$id2 = $this->cache->put($file2, $data2);
|
$id2 = $this->cache->put($file2, $data2);
|
||||||
$this->assertTrue($this->cache->inCache($file2));
|
$this->assertTrue($this->cache->inCache($file2));
|
||||||
$cacheData2 = $this->cache->get($file2);
|
$cacheData2 = $this->cache->get($file2);
|
||||||
foreach ($data2 as $key => $value) {
|
foreach ($data2 as $key => $value) {
|
||||||
$this->assertEqual($value, $cacheData2[$key]);
|
$this->assertEquals($value, $cacheData2[$key]);
|
||||||
}
|
}
|
||||||
$this->assertEqual($cacheData1['fileid'], $cacheData2['parent']);
|
$this->assertEquals($cacheData1['fileid'], $cacheData2['parent']);
|
||||||
$this->assertEqual($cacheData2['fileid'], $id2);
|
$this->assertEquals($cacheData2['fileid'], $id2);
|
||||||
$this->assertEqual($id2, $this->cache->getId($file2));
|
$this->assertEquals($id2, $this->cache->getId($file2));
|
||||||
$this->assertEqual($id1, $this->cache->getParentId($file2));
|
$this->assertEquals($id1, $this->cache->getParentId($file2));
|
||||||
|
|
||||||
$newSize = 1050;
|
$newSize = 1050;
|
||||||
$newId2 = $this->cache->put($file2, array('size' => $newSize));
|
$newId2 = $this->cache->put($file2, array('size' => $newSize));
|
||||||
$cacheData2 = $this->cache->get($file2);
|
$cacheData2 = $this->cache->get($file2);
|
||||||
$this->assertEqual($newId2, $id2);
|
$this->assertEquals($newId2, $id2);
|
||||||
$this->assertEqual($cacheData2['size'], $newSize);
|
$this->assertEquals($cacheData2['size'], $newSize);
|
||||||
$this->assertEqual($cacheData1, $this->cache->get($file1));
|
$this->assertEquals($cacheData1, $this->cache->get($file1));
|
||||||
|
|
||||||
$this->cache->remove($file2);
|
$this->cache->remove($file2);
|
||||||
$this->assertFalse($this->cache->inCache($file2));
|
$this->assertFalse($this->cache->inCache($file2));
|
||||||
$this->assertEqual($this->cache->get($file2), null);
|
$this->assertEquals($this->cache->get($file2), null);
|
||||||
$this->assertTrue($this->cache->inCache($file1));
|
$this->assertTrue($this->cache->inCache($file1));
|
||||||
|
|
||||||
$this->assertEqual($cacheData1, $this->cache->get($id1));
|
$this->assertEquals($cacheData1, $this->cache->get($id1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPartial() {
|
public function testPartial() {
|
||||||
$file1 = 'foo';
|
$file1 = 'foo';
|
||||||
|
|
||||||
$this->cache->put($file1, array('size' => 10));
|
$this->cache->put($file1, array('size' => 10));
|
||||||
$this->assertEqual(array('size' => 10), $this->cache->get($file1));
|
$this->assertEquals(array('size' => 10), $this->cache->get($file1));
|
||||||
|
|
||||||
$this->cache->put($file1, array('mtime' => 15));
|
$this->cache->put($file1, array('mtime' => 15));
|
||||||
$this->assertEqual(array('size' => 10, 'mtime' => 15), $this->cache->get($file1));
|
$this->assertEquals(array('size' => 10, 'mtime' => 15), $this->cache->get($file1));
|
||||||
|
|
||||||
$this->cache->put($file1, array('size' => 12));
|
$this->cache->put($file1, array('size' => 12));
|
||||||
$this->assertEqual(array('size' => 12, 'mtime' => 15), $this->cache->get($file1));
|
$this->assertEquals(array('size' => 12, 'mtime' => 15), $this->cache->get($file1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFolder() {
|
public function testFolder() {
|
||||||
|
@ -92,11 +92,11 @@ class Cache extends \UnitTestCase {
|
||||||
$this->cache->put($file3, $fileData['foo']);
|
$this->cache->put($file3, $fileData['foo']);
|
||||||
|
|
||||||
$content = $this->cache->getFolderContents($file1);
|
$content = $this->cache->getFolderContents($file1);
|
||||||
$this->assertEqual(count($content), 2);
|
$this->assertEquals(count($content), 2);
|
||||||
foreach ($content as $cachedData) {
|
foreach ($content as $cachedData) {
|
||||||
$data = $fileData[$cachedData['name']];
|
$data = $fileData[$cachedData['name']];
|
||||||
foreach ($data as $name => $value) {
|
foreach ($data as $name => $value) {
|
||||||
$this->assertEqual($value, $cachedData[$name]);
|
$this->assertEquals($value, $cachedData[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
52
tests/lib/files/cache/scanner.php
vendored
52
tests/lib/files/cache/scanner.php
vendored
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
namespace Test\Files\Cache;
|
namespace Test\Files\Cache;
|
||||||
|
|
||||||
class Scanner extends \UnitTestCase {
|
class Scanner extends \PHPUnit_Framework_TestCase {
|
||||||
/**
|
/**
|
||||||
* @var \OC\Files\Storage\Storage $storage
|
* @var \OC\Files\Storage\Storage $storage
|
||||||
*/
|
*/
|
||||||
|
@ -29,20 +29,20 @@ class Scanner extends \UnitTestCase {
|
||||||
$this->storage->file_put_contents('foo.txt', $data);
|
$this->storage->file_put_contents('foo.txt', $data);
|
||||||
$this->scanner->scanFile('foo.txt');
|
$this->scanner->scanFile('foo.txt');
|
||||||
|
|
||||||
$this->assertEqual($this->cache->inCache('foo.txt'), true);
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
||||||
$cachedData = $this->cache->get('foo.txt');
|
$cachedData = $this->cache->get('foo.txt');
|
||||||
$this->assertEqual($cachedData['size'], strlen($data));
|
$this->assertEquals($cachedData['size'], strlen($data));
|
||||||
$this->assertEqual($cachedData['mimetype'], 'text/plain');
|
$this->assertEquals($cachedData['mimetype'], 'text/plain');
|
||||||
$this->assertNotEqual($cachedData['parent'], -1); //parent folders should be scanned automatically
|
$this->assertNotEquals($cachedData['parent'], -1); //parent folders should be scanned automatically
|
||||||
|
|
||||||
$data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
$data = file_get_contents(\OC::$SERVERROOT . '/core/img/logo.png');
|
||||||
$this->storage->file_put_contents('foo.png', $data);
|
$this->storage->file_put_contents('foo.png', $data);
|
||||||
$this->scanner->scanFile('foo.png');
|
$this->scanner->scanFile('foo.png');
|
||||||
|
|
||||||
$this->assertEqual($this->cache->inCache('foo.png'), true);
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
||||||
$cachedData = $this->cache->get('foo.png');
|
$cachedData = $this->cache->get('foo.png');
|
||||||
$this->assertEqual($cachedData['size'], strlen($data));
|
$this->assertEquals($cachedData['size'], strlen($data));
|
||||||
$this->assertEqual($cachedData['mimetype'], 'image/png');
|
$this->assertEquals($cachedData['mimetype'], 'image/png');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fillTestFolders() {
|
private function fillTestFolders() {
|
||||||
|
@ -58,11 +58,11 @@ class Scanner extends \UnitTestCase {
|
||||||
$this->fillTestFolders();
|
$this->fillTestFolders();
|
||||||
|
|
||||||
$this->scanner->scan('');
|
$this->scanner->scan('');
|
||||||
$this->assertEqual($this->cache->inCache(''), true);
|
$this->assertEquals($this->cache->inCache(''), true);
|
||||||
$this->assertEqual($this->cache->inCache('foo.txt'), true);
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
||||||
$this->assertEqual($this->cache->inCache('foo.png'), true);
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
||||||
$this->assertEqual($this->cache->inCache('folder'), true);
|
$this->assertEquals($this->cache->inCache('folder'), true);
|
||||||
$this->assertEqual($this->cache->inCache('folder/bar.txt'), true);
|
$this->assertEquals($this->cache->inCache('folder/bar.txt'), true);
|
||||||
|
|
||||||
$cachedDataText = $this->cache->get('foo.txt');
|
$cachedDataText = $this->cache->get('foo.txt');
|
||||||
$cachedDataText2 = $this->cache->get('foo.txt');
|
$cachedDataText2 = $this->cache->get('foo.txt');
|
||||||
|
@ -70,38 +70,38 @@ class Scanner extends \UnitTestCase {
|
||||||
$cachedDataFolder = $this->cache->get('');
|
$cachedDataFolder = $this->cache->get('');
|
||||||
$cachedDataFolder2 = $this->cache->get('folder');
|
$cachedDataFolder2 = $this->cache->get('folder');
|
||||||
|
|
||||||
$this->assertEqual($cachedDataImage['parent'], $cachedDataText['parent']);
|
$this->assertEquals($cachedDataImage['parent'], $cachedDataText['parent']);
|
||||||
$this->assertEqual($cachedDataFolder['fileid'], $cachedDataImage['parent']);
|
$this->assertEquals($cachedDataFolder['fileid'], $cachedDataImage['parent']);
|
||||||
$this->assertEqual($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
|
$this->assertEquals($cachedDataFolder['size'], $cachedDataImage['size'] + $cachedDataText['size'] + $cachedDataText2['size']);
|
||||||
$this->assertEqual($cachedDataFolder2['size'], $cachedDataText2['size']);
|
$this->assertEquals($cachedDataFolder2['size'], $cachedDataText2['size']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testShallow() {
|
function testShallow() {
|
||||||
$this->fillTestFolders();
|
$this->fillTestFolders();
|
||||||
|
|
||||||
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||||
$this->assertEqual($this->cache->inCache(''), true);
|
$this->assertEquals($this->cache->inCache(''), true);
|
||||||
$this->assertEqual($this->cache->inCache('foo.txt'), true);
|
$this->assertEquals($this->cache->inCache('foo.txt'), true);
|
||||||
$this->assertEqual($this->cache->inCache('foo.png'), true);
|
$this->assertEquals($this->cache->inCache('foo.png'), true);
|
||||||
$this->assertEqual($this->cache->inCache('folder'), true);
|
$this->assertEquals($this->cache->inCache('folder'), true);
|
||||||
$this->assertEqual($this->cache->inCache('folder/bar.txt'), false);
|
$this->assertEquals($this->cache->inCache('folder/bar.txt'), false);
|
||||||
|
|
||||||
$cachedDataFolder = $this->cache->get('');
|
$cachedDataFolder = $this->cache->get('');
|
||||||
$cachedDataFolder2 = $this->cache->get('folder');
|
$cachedDataFolder2 = $this->cache->get('folder');
|
||||||
|
|
||||||
$this->assertEqual(-1, $cachedDataFolder['size']);
|
$this->assertEquals(-1, $cachedDataFolder['size']);
|
||||||
$this->assertEqual(-1, $cachedDataFolder2['size']);
|
$this->assertEquals(-1, $cachedDataFolder2['size']);
|
||||||
|
|
||||||
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
$this->scanner->scan('folder', \OC\Files\Cache\Scanner::SCAN_SHALLOW);
|
||||||
|
|
||||||
$cachedDataFolder2 = $this->cache->get('folder');
|
$cachedDataFolder2 = $this->cache->get('folder');
|
||||||
|
|
||||||
$this->assertNotEqual($cachedDataFolder2['size'], -1);
|
$this->assertNotEquals($cachedDataFolder2['size'], -1);
|
||||||
|
|
||||||
$this->cache->correctFolderSize('folder');
|
$this->cache->correctFolderSize('folder');
|
||||||
|
|
||||||
$cachedDataFolder = $this->cache->get('');
|
$cachedDataFolder = $this->cache->get('');
|
||||||
$this->assertNotEqual($cachedDataFolder['size'], -1);
|
$this->assertNotEquals($cachedDataFolder['size'], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testBackgroundScan(){
|
function testBackgroundScan(){
|
||||||
|
|
Loading…
Reference in a new issue