diff options
author | Lukas Reschke <lukas@owncloud.com> | 2015-03-26 13:28:00 +0100 |
---|---|---|
committer | Lukas Reschke <lukas@owncloud.com> | 2015-03-26 13:28:00 +0100 |
commit | e12c76ed666d2646d52e68b65f89acdb6558094f (patch) | |
tree | c822ced2194aaaf2a2598391e78cc99d63234d6c /tests | |
parent | 722faee4c66cb4cbf4ef6f026263bbd7d640c775 (diff) | |
parent | 4c92aafc19944f613cb0a1f2aa1e3bd2020ad6cd (diff) | |
download | nextcloud-server-e12c76ed666d2646d52e68b65f89acdb6558094f.tar.gz nextcloud-server-e12c76ed666d2646d52e68b65f89acdb6558094f.zip |
Merge pull request #15192 from owncloud/stable8-15153
Stable8: Add `getNonExistingName()` to the node api
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/files/node/folder.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/lib/files/node/folder.php b/tests/lib/files/node/folder.php index 54b26ebdfe1..4a88e2acd36 100644 --- a/tests/lib/files/node/folder.php +++ b/tests/lib/files/node/folder.php @@ -679,4 +679,40 @@ class Folder extends \Test\TestCase { $this->assertEquals('/bar/foo/qwerty', $result[0]->getPath()); $this->assertEquals('/bar/foo/asd/foo/qwerty', $result[1]->getPath()); } + + public function uniqueNameProvider() { + return [ + // input, existing, expected + ['foo', [] , 'foo'], + ['foo', ['foo'] , 'foo (2)'], + ['foo', ['foo', 'foo (2)'] , 'foo (3)'] + ]; + } + + /** + * @dataProvider uniqueNameProvider + */ + public function testGetUniqueName($name, $existingFiles, $expected) { + $manager = $this->getMock('\OC\Files\Mount\Manager'); + $folderPath = '/bar/foo'; + /** + * @var \OC\Files\View | \PHPUnit_Framework_MockObject_MockObject $view + */ + $view = $this->getMock('\OC\Files\View'); + $root = $this->getMock('\OC\Files\Node\Root', array('getUser', 'getMountsIn', 'getMount'), array($manager, $view, $this->user)); + + $view->expects($this->any()) + ->method('file_exists') + ->will($this->returnCallback(function ($path) use ($existingFiles, $folderPath) { + foreach ($existingFiles as $existing) { + if ($folderPath . '/' . $existing === $path){ + return true; + } + } + return false; + })); + + $node = new \OC\Files\Node\Folder($root, $view, $folderPath); + $this->assertEquals($expected, $node->getNonExistingName($name)); + } } |