use assertSame and assertNotSame for etag checks

This commit is contained in:
Jörn Friedrich Dreyer 2014-02-27 09:39:34 +01:00
parent 7f05c23231
commit 39f2f564a9
5 changed files with 28 additions and 14 deletions

View File

@ -344,7 +344,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
$this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
$this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
$this->view->unlink($this->userId . '/files/' . $filename);
}
@ -373,7 +373,7 @@ class Test_Encryption_Util extends \PHPUnit_Framework_TestCase {
// check if mtime and etags unchanged
$this->assertEquals($fileInfoEncrypted['mtime'], $fileInfoUnencrypted['mtime']);
$this->assertEquals($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
$this->assertSame($fileInfoEncrypted['etag'], $fileInfoUnencrypted['etag']);
// file should no longer be encrypted
$this->assertEquals(0, $fileInfoUnencrypted['encrypted']);

View File

@ -78,7 +78,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase {
public function testGetEtag() {
$this->childResponse->setEtag('hi');
$this->assertEquals('hi', $this->childResponse->getEtag());
$this->assertSame('hi', $this->childResponse->getEtag());
}

View File

@ -150,13 +150,15 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->cache->put('folder', array('mtime' => $this->storage->filemtime('folder'), 'storage_mtime' => $this->storage->filemtime('folder')));
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertNotEquals($oldData['etag'], $newData['etag']);
$this->assertTrue(is_string($oldData['etag']), 'Expected a string');
$this->assertTrue(is_string($newData['etag']), 'Expected a string');
$this->assertNotSame($oldData['etag'], $newData['etag']);
$this->assertEquals($oldData['size'], $newData['size']);
$oldData = $newData;
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
$newData = $this->cache->get('');
$this->assertEquals($oldData['etag'], $newData['etag']);
$this->assertSame($oldData['etag'], $newData['etag']);
$this->assertEquals(-1, $newData['size']);
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE);
@ -164,17 +166,17 @@ class Scanner extends \PHPUnit_Framework_TestCase {
$this->assertNotEquals(-1, $oldData['size']);
$this->scanner->scanFile('', \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertEquals($oldData['etag'], $newData['etag']);
$this->assertSame($oldData['etag'], $newData['etag']);
$this->assertEquals($oldData['size'], $newData['size']);
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_RECURSIVE, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertEquals($oldData['etag'], $newData['etag']);
$this->assertSame($oldData['etag'], $newData['etag']);
$this->assertEquals($oldData['size'], $newData['size']);
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG + \OC\Files\Cache\Scanner::REUSE_SIZE);
$newData = $this->cache->get('');
$this->assertEquals($oldData['etag'], $newData['etag']);
$this->assertSame($oldData['etag'], $newData['etag']);
$this->assertEquals($oldData['size'], $newData['size']);
}
@ -217,8 +219,11 @@ class Scanner extends \PHPUnit_Framework_TestCase {
// manipulate etag to simulate an empty etag
$this->scanner->scan('', \OC\Files\Cache\Scanner::SCAN_SHALLOW, \OC\Files\Cache\Scanner::REUSE_ETAG);
$data0 = $this->cache->get('folder/bar.txt');
$this->assertTrue(is_string($data0['etag']), 'Expected a string');
$data1 = $this->cache->get('folder');
$this->assertTrue(is_string($data1['etag']), 'Expected a string');
$data2 = $this->cache->get('');
$this->assertTrue(is_string($data2['etag']), 'Expected a string');
$data0['etag'] = '';
$this->cache->put('folder/bar.txt', $data0);
@ -227,10 +232,15 @@ class Scanner extends \PHPUnit_Framework_TestCase {
// verify cache content
$newData0 = $this->cache->get('folder/bar.txt');
$newData1 = $this->cache->get('folder');
$newData2 = $this->cache->get('');
$this->assertTrue(is_string($newData0['etag']), 'Expected a string');
$this->assertNotEmpty($newData0['etag']);
$this->assertNotEquals($data1['etag'], $newData1['etag']);
$this->assertNotEquals($data2['etag'], $newData2['etag']);
$newData1 = $this->cache->get('folder');
$this->assertTrue(is_string($newData1['etag']), 'Expected a string');
$this->assertNotSame($data1['etag'], $newData1['etag']);
$newData2 = $this->cache->get('');
$this->assertTrue(is_string($newData2['etag']), 'Expected a string');
$this->assertNotSame($data2['etag'], $newData2['etag']);
}
}

View File

@ -65,7 +65,11 @@ class EtagTest extends \PHPUnit_Framework_TestCase {
$scanner = new \OC\Files\Utils\Scanner($user1);
$scanner->backgroundScan('/');
$this->assertEquals($originalEtags, $this->getEtags($files));
$newEtags = $this->getEtags($files);
// loop over array and use assertSame over assertEquals to prevent false positives
foreach ($originalEtags as $file => $originalEtag) {
$this->assertSame($originalEtag, $newEtags[$file]);
}
}
/**

View File

@ -563,6 +563,6 @@ class View extends \PHPUnit_Framework_TestCase {
$scanner->scanFile('test', \OC\Files\Cache\Scanner::REUSE_ETAG);
$info2 = $view->getFileInfo('/test/test');
$this->assertEquals($info['etag'], $info2['etag']);
$this->assertSame($info['etag'], $info2['etag']);
}
}