Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2022-05-09 19:20:46 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-05-09 19:22:33 +0300
commitc0c29644b51c23824ef86e859e2179e778fef9a6 (patch)
tree4777f9bebc85e5deb0dc1e2dedc62ceb0035f38d /tests
parent6759366d120160b04b50cd12decc65f42df36628 (diff)
refs #2338 improve and test ImageService::getUniqueFileName()
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/TextTest.php37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/TextTest.php b/tests/TextTest.php
index aeaa8d0cc..161446b8c 100644
--- a/tests/TextTest.php
+++ b/tests/TextTest.php
@@ -4,6 +4,7 @@ namespace OCA\Text\Tests;
use OCA\Text\AppInfo\Application;
use OCA\Text\Service\ImageService;
+use OCP\Files\Folder;
class TextTest extends \PHPUnit\Framework\TestCase {
public function testDummy() {
@@ -34,4 +35,40 @@ class TextTest extends \PHPUnit\Framework\TestCase {
$this->assertContains($contentName, $computedNames);
}
}
+
+ public function testGetUniqueFileName() {
+ $fileNameList = [
+ 'foo.png',
+ 'bar',
+ 'plop.png',
+ 'plop (2).png',
+ 'lala.png',
+ 'lala (2).png',
+ 'lala (3).png',
+ 'yay.png',
+ 'yay (2).png',
+ 'yay (3).png',
+ 'yay (5).png',
+ 'file.ext.ext',
+ ];
+
+ $folder = $this->createMock(Folder::class);
+ $folder->expects(self::any())
+ ->method('nodeExists')
+ ->willReturnCallback(function ($name) use ($fileNameList) {
+ return in_array($name, $fileNameList);
+ });
+
+ // files that do not exist yet
+ $this->assertEquals('doesNotExistYet', ImageService::getUniqueFileName($folder, 'doesNotExistYet'));
+ $this->assertEquals('doesNotExistYet.png', ImageService::getUniqueFileName($folder, 'doesNotExistYet.png'));
+
+ // files that already exist
+ $this->assertEquals('foo (2).png', ImageService::getUniqueFileName($folder, 'foo.png'));
+ $this->assertEquals('bar (2)', ImageService::getUniqueFileName($folder, 'bar'));
+ $this->assertEquals('plop (3).png', ImageService::getUniqueFileName($folder, 'plop.png'));
+ $this->assertEquals('lala (4).png', ImageService::getUniqueFileName($folder, 'lala.png'));
+ $this->assertEquals('yay (4).png', ImageService::getUniqueFileName($folder, 'yay.png'));
+ $this->assertEquals('file.ext (2).ext', ImageService::getUniqueFileName($folder, 'file.ext.ext'));
+ }
}