diff options
author | Bart Visscher <bartv@thisnet.nl> | 2013-03-08 14:22:04 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2013-07-05 13:03:01 +0200 |
commit | 424ec94680e69a3082a3d3f7c1ceefd7eeae15d2 (patch) | |
tree | 829468c3a7e567f44c2550c252ed52f47618e6fd /tests/lib/helper.php | |
parent | 9c855f7b3d97b312095ba53a08fe45b71ca06c98 (diff) | |
download | nextcloud-server-424ec94680e69a3082a3d3f7c1ceefd7eeae15d2.tar.gz nextcloud-server-424ec94680e69a3082a3d3f7c1ceefd7eeae15d2.zip |
Make buildNotExistingFileName testable and write unittests
Diffstat (limited to 'tests/lib/helper.php')
-rw-r--r-- | tests/lib/helper.php | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/lib/helper.php b/tests/lib/helper.php index 6acb0dfaa6b..410117a9e67 100644 --- a/tests/lib/helper.php +++ b/tests/lib/helper.php @@ -146,4 +146,46 @@ 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)); + $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)); + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); + $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)); + $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)); + $viewMock->expects($this->at(1)) + ->method('file_exists') + ->will($this->returnValue(true)); + $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)); + $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)); + $this->assertEquals('dir/filename(1) (2).ext', OC_Helper::buildNotExistingFileNameForView('dir', 'filename(1) (1).ext', $viewMock)); + } } |