diff options
author | Robin Windey <ro.windey@gmail.com> | 2025-01-18 17:38:39 +0000 |
---|---|---|
committer | Robin Windey <ro.windey@gmail.com> | 2025-01-18 17:38:39 +0000 |
commit | 4654ddbaca0a35e0ba7637b148f9888ed252019e (patch) | |
tree | b175482aaf49425e0043f14c5dbea0fdd5cd0716 /apps/workflowengine/tests/Check/DirectoryTest.php | |
parent | 0d3edd28b17acb59c1ea512cad5db5ea85444813 (diff) | |
download | nextcloud-server-feat/add-directory-check-workflowengine.tar.gz nextcloud-server-feat/add-directory-check-workflowengine.zip |
Implement Directory Checkfeat/add-directory-check-workflowengine
* Partially implements #27591
Signed-off-by: Robin Windey <ro.windey@gmail.com>
Diffstat (limited to 'apps/workflowengine/tests/Check/DirectoryTest.php')
-rw-r--r-- | apps/workflowengine/tests/Check/DirectoryTest.php | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/apps/workflowengine/tests/Check/DirectoryTest.php b/apps/workflowengine/tests/Check/DirectoryTest.php new file mode 100644 index 00000000000..c8a8316e9cb --- /dev/null +++ b/apps/workflowengine/tests/Check/DirectoryTest.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +namespace OCA\WorkflowEngine\Tests\Check; + +use OCA\WorkflowEngine\Check\Directory; +use OCA\WorkflowEngine\Entity\File; +use OCP\Files\Storage\IStorage; +use OCP\IL10N; +use Test\TestCase; + +class DirectoryTest extends TestCase { + /** @var IL10N */ + private $l10n; + + /** @var IStorage */ + private $storage; + + /** @var Directory */ + private $directory; + + protected function setUp(): void { + parent::setUp(); + $this->l10n = $this->createMock(IL10N::class); + $this->storage = $this->createMock(IStorage::class); + $this->directory = new Directory($this->l10n); + } + + /** + * @dataProvider dataProviderCheck + */ + public function testExecuteStringCheck(string $operator, string $configuredDirectoryPath, string $filePath, bool $expectedResult): void { + $this->directory->setFileInfo($this->storage, $filePath); + + $result = $this->directory->executeCheck($operator, $configuredDirectoryPath); + + $this->assertEquals($expectedResult, $result); + } + + public function testSupportedEntities(): void { + $this->assertSame([File::class], $this->directory->supportedEntities()); + } + + public function testIsAvailableForScope(): void { + $this->assertTrue($this->directory->isAvailableForScope(1)); + } + + public function dataProviderCheck(): array { + return [ + ['is', 'some/path', 'files/some/path/file.txt', true], + ['is', '/some/path/', 'files/some/path/file.txt', true], + + ['!is', 'some/path', 'files/some/path/file.txt', false], + ['!is', 'some/path/', 'files/someother/path/file.txt', true], + + ['matches', '/^some\/path\/.+$/i', 'files/SomE/PATH/subfolder/file.txt', true], + ['matches', '/some\/path\/.*\/sub2/', 'files/some/path/subfolder1/sub2/anotherfile.pdf', true], + + ['!matches', '/some\/path/', 'files/some/path/file.txt', false], + ['!matches', '/some\/path/', 'files/another/path/file.txt', true], + ]; + } +} |