diff options
Diffstat (limited to 'apps/workflowengine/tests/Check')
5 files changed, 81 insertions, 39 deletions
diff --git a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php index d10fcfb4cc3..26d4ccb8553 100644 --- a/apps/workflowengine/tests/Check/AbstractStringCheckTest.php +++ b/apps/workflowengine/tests/Check/AbstractStringCheckTest.php @@ -50,9 +50,7 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteStringCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteStringCheck')] public function testExecuteStringCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { $check = $this->getCheckMock(); @@ -69,9 +67,7 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] public function testValidateCheck(string $operator, string $value): void { $check = $this->getCheckMock(); @@ -90,9 +86,7 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheckInvalid - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { $check = $this->getCheckMock(); @@ -112,9 +106,7 @@ class AbstractStringCheckTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataMatch - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataMatch')] public function testMatch(string $pattern, string $subject, array $matches, bool $expected): void { $check = $this->getCheckMock(); diff --git a/apps/workflowengine/tests/Check/DirectoryTest.php b/apps/workflowengine/tests/Check/DirectoryTest.php new file mode 100644 index 00000000000..6eef082b5e5 --- /dev/null +++ b/apps/workflowengine/tests/Check/DirectoryTest.php @@ -0,0 +1,68 @@ +<?php + +declare(strict_types=1); +/** + * SPDX-FileCopyrightText: 2025 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], + ]; + } +} diff --git a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php index f2f8026e666..c0e56daefa8 100644 --- a/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php +++ b/apps/workflowengine/tests/Check/RequestRemoteAddressTest.php @@ -44,9 +44,7 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv4 - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] public function testExecuteCheckMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); @@ -57,9 +55,7 @@ class RequestRemoteAddressTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('matchesIPv4', $value)); } - /** - * @dataProvider dataExecuteCheckIPv4 - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv4')] public function testExecuteCheckNotMatchesIPv4(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); @@ -82,9 +78,7 @@ class RequestRemoteAddressTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheckIPv6 - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] public function testExecuteCheckMatchesIPv6(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); @@ -95,9 +89,7 @@ class RequestRemoteAddressTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('matchesIPv6', $value)); } - /** - * @dataProvider dataExecuteCheckIPv6 - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheckIPv6')] public function testExecuteCheckNotMatchesIPv6(string $value, string $ip, bool $expected): void { $check = new RequestRemoteAddress($this->getL10NMock(), $this->request); diff --git a/apps/workflowengine/tests/Check/RequestTimeTest.php b/apps/workflowengine/tests/Check/RequestTimeTest.php index 21127d4d56e..a8439b8b9f4 100644 --- a/apps/workflowengine/tests/Check/RequestTimeTest.php +++ b/apps/workflowengine/tests/Check/RequestTimeTest.php @@ -63,9 +63,7 @@ class RequestTimeTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataExecuteCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] public function testExecuteCheckIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); @@ -76,9 +74,7 @@ class RequestTimeTest extends \Test\TestCase { $this->assertEquals($expected, $check->executeCheck('in', $value)); } - /** - * @dataProvider dataExecuteCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] public function testExecuteCheckNotIn(string $value, int $timestamp, bool $expected): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); @@ -97,9 +93,7 @@ class RequestTimeTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheck')] public function testValidateCheck(string $operator, string $value): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); $check->validateCheck($operator, $value); @@ -118,9 +112,7 @@ class RequestTimeTest extends \Test\TestCase { ]; } - /** - * @dataProvider dataValidateCheckInvalid - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataValidateCheckInvalid')] public function testValidateCheckInvalid(string $operator, string $value, int $exceptionCode, string $exceptionMessage): void { $check = new RequestTime($this->getL10NMock(), $this->timeFactory); diff --git a/apps/workflowengine/tests/Check/RequestUserAgentTest.php b/apps/workflowengine/tests/Check/RequestUserAgentTest.php index 2fe96bf3bdb..09eaea6555b 100644 --- a/apps/workflowengine/tests/Check/RequestUserAgentTest.php +++ b/apps/workflowengine/tests/Check/RequestUserAgentTest.php @@ -82,9 +82,7 @@ class RequestUserAgentTest extends TestCase { ]; } - /** - * @dataProvider dataExecuteCheck - */ + #[\PHPUnit\Framework\Attributes\DataProvider('dataExecuteCheck')] public function testExecuteCheck(string $operation, string $checkValue, string $actualValue, bool $expected): void { $this->request->expects($this->once()) ->method('getHeader') |