summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2013-07-16 12:06:53 -0700
committerBart Visscher <bartv@thisnet.nl>2013-07-16 12:06:53 -0700
commit285f288cf344625dbddd3c6e4bacb9df1ddb6ce0 (patch)
treed433f1c2b6cdc3e48fc1fe538dc9e6d858a2c26a /tests
parentd673d8c25310f0ea73927b8b252e6823a11087f4 (diff)
parent22c29eb64b67ee18beacf126eecb78fd4a02608c (diff)
downloadnextcloud-server-285f288cf344625dbddd3c6e4bacb9df1ddb6ce0.tar.gz
nextcloud-server-285f288cf344625dbddd3c6e4bacb9df1ddb6ce0.zip
Merge pull request #3959 from owncloud/buildNotExistingFileNameForView
Fix renaming using parenthesis
Diffstat (limited to 'tests')
-rw-r--r--tests/lib/helper.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/lib/helper.php b/tests/lib/helper.php
index 6acb0dfaa6b..67b5a3d43ec 100644
--- a/tests/lib/helper.php
+++ b/tests/lib/helper.php
@@ -146,4 +146,64 @@ class Test_Helper extends PHPUnit_Framework_TestCase {
$result = OC_Helper::recursiveArraySearch($haystack, "NotFound");
$this->assertFalse($result);
}
+
+ function testBuildNotExistingFileNameForView() {
+ $viewMock = $this->getMock('\OC\Files\View', array(), array(), '', false);
+ $this->assertEquals('/filename', OC_Helper::buildNotExistingFileNameForView('/', 'filename', $viewMock));
+ $this->assertEquals('dir/filename.ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename.ext exists
+ $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename.ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename.ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (1).ext exists
+ $this->assertEquals('dir/filename (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $this->assertEquals('dir/filename (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (2).ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename (3).ext exists
+ $this->assertEquals('dir/filename (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename (2).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1).ext exists
+ $this->assertEquals('dir/filename(2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (1).ext exists
+ $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (1).ext exists
+ $viewMock->expects($this->at(1))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (2).ext exists
+ $this->assertEquals('dir/filename(1) (3).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock));
+
+ $viewMock->expects($this->at(0))
+ ->method('file_exists')
+ ->will($this->returnValue(true)); // filename(1) (2) (3).ext exists
+ $this->assertEquals('dir/filename(1) (2) (4).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (2) (3).ext', $viewMock));
+ }
}