summaryrefslogtreecommitdiffstats
path: root/tests/lib/files/cache/cache.php
diff options
context:
space:
mode:
authorFlorin Peter <github@florin-peter.de>2013-05-23 20:29:46 +0200
committerFlorin Peter <github@florin-peter.de>2013-05-23 20:29:46 +0200
commitd4b700ef4ebfa9aba9bcadda864ed5a2a92174ed (patch)
treedd5c32ef990fdc38bc9ed3c31ffb1c74e3077507 /tests/lib/files/cache/cache.php
parent85e0c78166d45b0ef9d00b1fd2164e4969ee9b83 (diff)
downloadnextcloud-server-d4b700ef4ebfa9aba9bcadda864ed5a2a92174ed.tar.gz
nextcloud-server-d4b700ef4ebfa9aba9bcadda864ed5a2a92174ed.zip
revert previous fix and added normalizer to cache class
Diffstat (limited to 'tests/lib/files/cache/cache.php')
-rw-r--r--tests/lib/files/cache/cache.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php
index 1612a673838..2b1e5a56212 100644
--- a/tests/lib/files/cache/cache.php
+++ b/tests/lib/files/cache/cache.php
@@ -8,6 +8,8 @@
namespace Test\Files\Cache;
+use PHPUnit_Framework_MockObject_MockObject;
+
class LongId extends \OC\Files\Storage\Temporary {
public function getId() {
return 'long:' . str_repeat('foo', 50) . parent::getId();
@@ -237,6 +239,71 @@ class Cache extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(md5($storageId), 'foo'), \OC\Files\Cache\Cache::getById($id));
}
+ /**
+ * @brief this test show the bug resulting if we have no normalizer installed
+ */
+ public function testWithoutNormalizer() {
+ // create folder Schön with U+00F6
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // create folder Schön with U+0308
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ /**
+ * @var \OC\Files\Cache\Cache | PHPUnit_Framework_MockObject_MockObject $cacheMock
+ */
+ $cacheMock = $this->getMock('\OC\Files\Cache\Cache', array('normalize'), array($this->storage), '', true);
+
+ $cacheMock->expects($this->any())
+ ->method('normalize')
+ ->will($this->returnArgument(0));
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->assertFalse($cacheMock->get('folder'));
+ $this->assertGreaterThan(0, $cacheMock->put('folder', $data));
+
+ $this->assertFalse($cacheMock->get('folder/' . $folderWith00F6));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith00F6, $data));
+
+ $this->assertFalse($cacheMock->get('folder/' .$folderWith0308));
+ $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith0308, $data));
+
+ // this is our bug, we have two different hashes with the same name (Schön)
+ $this->assertEquals(2, count($cacheMock->getFolderContents('folder')));
+ }
+
+ /**
+ * @brief this test shows that there is no bug if we use the normalizer
+ */
+ public function testWithNormalizer() {
+
+ if(!class_exists('Normalizer')) {
+ $this->markTestSkipped('The Normalizer extension is not available.');
+ return;
+ }
+
+ // folder name Schön with U+00F6
+ $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e";
+
+ // folder name Schön with U+0308
+ $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e";
+
+ $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory');
+
+ $this->assertFalse($this->cache->get('folder'));
+ $this->assertGreaterThan(0, $this->cache->put('folder', $data));
+
+ $this->assertFalse($this->cache->get('folder/' . $folderWith00F6));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith00F6, $data));
+
+ $this->assertTrue(is_array($this->cache->get('folder/' .$folderWith0308)));
+ $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith0308, $data));
+
+ // at this point we should have only one folder named "Schön"
+ $this->assertEquals(1, count($this->cache->getFolderContents('folder')));
+ }
+
public function tearDown() {
$this->cache->clear();
}