diff options
author | icewind1991 <icewind1991@gmail.com> | 2013-05-31 14:00:02 -0700 |
---|---|---|
committer | icewind1991 <icewind1991@gmail.com> | 2013-05-31 14:00:02 -0700 |
commit | 94a6622bcd3c4a77aa2af8fd09920f8ac1e0245f (patch) | |
tree | f95ad6e96bcaa8908b911ed326de8700c3b1a8ae /tests | |
parent | 1656cc2e7c70288e705dc47db9c618149ab79111 (diff) | |
parent | adcafbde34b8f4c75dbf724e929766a1f7d964d4 (diff) | |
download | nextcloud-server-94a6622bcd3c4a77aa2af8fd09920f8ac1e0245f.tar.gz nextcloud-server-94a6622bcd3c4a77aa2af8fd09920f8ac1e0245f.zip |
Merge pull request #3459 from owncloud/fix_for_2377
fix problems with german "Umlaut" in folder name
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/cache/cache.php | 85 | ||||
-rw-r--r-- | tests/lib/files/filesystem.php | 2 |
2 files changed, 86 insertions, 1 deletions
diff --git a/tests/lib/files/cache/cache.php b/tests/lib/files/cache/cache.php index d8b6541bd0c..f272655925b 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(); @@ -262,6 +264,89 @@ 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() { + // folder name "Schön" with U+00F6 (normalized) + $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e"; + + // folder name "Schön" with U+0308 (un-normalized) + $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'); + + // put root folder + $this->assertFalse($cacheMock->get('folder')); + $this->assertGreaterThan(0, $cacheMock->put('folder', $data)); + + // put un-normalized folder + $this->assertFalse($cacheMock->get('folder/' .$folderWith0308)); + $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith0308, $data)); + + // get un-normalized folder by name + $unNormalizedFolderName = $cacheMock->get('folder/' .$folderWith0308); + + // check if database layer normalized the folder name (this should not happen) + $this->assertEquals($folderWith0308, $unNormalizedFolderName['name']); + + // put normalized folder + $this->assertFalse($cacheMock->get('folder/' . $folderWith00F6)); + $this->assertGreaterThan(0, $cacheMock->put('folder/' .$folderWith00F6, $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('Patchwork\PHP\Shim\Normalizer')) { + $this->markTestSkipped('The 3rdparty Normalizer extension is not available.'); + return; + } + + // folder name "Schön" with U+00F6 (normalized) + $folderWith00F6 = "\x53\x63\x68\xc3\xb6\x6e"; + + // folder name "Schön" with U+0308 (un-normalized) + $folderWith0308 = "\x53\x63\x68\x6f\xcc\x88\x6e"; + + $data = array('size' => 100, 'mtime' => 50, 'mimetype' => 'httpd/unix-directory'); + + // put root folder + $this->assertFalse($this->cache->get('folder')); + $this->assertGreaterThan(0, $this->cache->put('folder', $data)); + + // put un-normalized folder + $this->assertFalse($this->cache->get('folder/' .$folderWith0308)); + $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith0308, $data)); + + // get un-normalized folder by name + $unNormalizedFolderName = $this->cache->get('folder/' .$folderWith0308); + + // check if folder name was normalized + $this->assertEquals($folderWith00F6, $unNormalizedFolderName['name']); + + // put normalized folder + $this->assertTrue(is_array($this->cache->get('folder/' . $folderWith00F6))); + $this->assertGreaterThan(0, $this->cache->put('folder/' .$folderWith00F6, $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(); } diff --git a/tests/lib/files/filesystem.php b/tests/lib/files/filesystem.php index 6ce45e6178a..bef70cc725b 100644 --- a/tests/lib/files/filesystem.php +++ b/tests/lib/files/filesystem.php @@ -72,7 +72,7 @@ class Filesystem extends \PHPUnit_Framework_TestCase { $this->assertEquals('/path', \OC\Files\Filesystem::normalizePath('\path')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo//bar/')); $this->assertEquals('/foo/bar', \OC\Files\Filesystem::normalizePath('/foo////bar')); - if (class_exists('Normalizer')) { + if (class_exists('Patchwork\PHP\Shim\Normalizer')) { $this->assertEquals("/foo/bar\xC3\xBC", \OC\Files\Filesystem::normalizePath("/foo/baru\xCC\x88")); } } |