|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 6 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | + */ |
| 8 | + |
| 9 | +namespace OCA\WorkflowEngine\Tests\Check; |
| 10 | + |
| 11 | +use OCA\WorkflowEngine\Check\Directory; |
| 12 | +use OCA\WorkflowEngine\Entity\File; |
| 13 | +use OCP\Files\Storage\IStorage; |
| 14 | +use OCP\IL10N; |
| 15 | +use Test\TestCase; |
| 16 | + |
| 17 | +class DirectoryTest extends TestCase { |
| 18 | + /** @var IL10N */ |
| 19 | + private $l10n; |
| 20 | + |
| 21 | + /** @var IStorage */ |
| 22 | + private $storage; |
| 23 | + |
| 24 | + /** @var Directory */ |
| 25 | + private $directory; |
| 26 | + |
| 27 | + protected function setUp(): void { |
| 28 | + parent::setUp(); |
| 29 | + $this->l10n = $this->createMock(IL10N::class); |
| 30 | + $this->storage = $this->createMock(IStorage::class); |
| 31 | + $this->directory = new Directory($this->l10n); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @dataProvider dataProviderCheck |
| 36 | + */ |
| 37 | + public function testExecuteStringCheck(string $operator, string $configuredDirectoryPath, string $filePath, bool $expectedResult): void { |
| 38 | + $this->directory->setFileInfo($this->storage, $filePath); |
| 39 | + |
| 40 | + $result = $this->directory->executeCheck($operator, $configuredDirectoryPath); |
| 41 | + |
| 42 | + $this->assertEquals($expectedResult, $result); |
| 43 | + } |
| 44 | + |
| 45 | + public function testSupportedEntities(): void { |
| 46 | + $this->assertSame([File::class], $this->directory->supportedEntities()); |
| 47 | + } |
| 48 | + |
| 49 | + public function testIsAvailableForScope(): void { |
| 50 | + $this->assertTrue($this->directory->isAvailableForScope(1)); |
| 51 | + } |
| 52 | + |
| 53 | + public function dataProviderCheck(): array { |
| 54 | + return [ |
| 55 | + ['is', 'some/path', 'files/some/path/file.txt', true], |
| 56 | + ['is', '/some/path/', 'files/some/path/file.txt', true], |
| 57 | + |
| 58 | + ['!is', 'some/path', 'files/some/path/file.txt', false], |
| 59 | + ['!is', 'some/path/', 'files/someother/path/file.txt', true], |
| 60 | + |
| 61 | + ['matches', '/^some\/path\/.+$/i', 'files/SomE/PATH/subfolder/file.txt', true], |
| 62 | + ['matches', '/some\/path\/.*\/sub2/', 'files/some/path/subfolder1/sub2/anotherfile.pdf', true], |
| 63 | + |
| 64 | + ['!matches', '/some\/path/', 'files/some/path/file.txt', false], |
| 65 | + ['!matches', '/some\/path/', 'files/another/path/file.txt', true], |
| 66 | + ]; |
| 67 | + } |
| 68 | +} |
0 commit comments