-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Partially implements #27591 Signed-off-by: Robin Windey <[email protected]>
- Loading branch information
Showing
8 changed files
with
146 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
namespace OCA\WorkflowEngine\Check; | ||
|
||
use OCA\WorkflowEngine\Entity\File; | ||
use OCP\IL10N; | ||
use OCP\WorkflowEngine\IFileCheck; | ||
|
||
class Directory extends AbstractStringCheck implements IFileCheck { | ||
use TFileCheck; | ||
|
||
/** | ||
* @param IL10N $l | ||
*/ | ||
public function __construct( | ||
IL10N $l, | ||
) { | ||
parent::__construct($l); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getActualValue(): string { | ||
if ($this->path === null) { | ||
return ''; | ||
} | ||
// files/some/path -> some/path | ||
return preg_replace('/^files\//', '', pathinfo($this->path, PATHINFO_DIRNAME)); | ||
} | ||
|
||
/** | ||
* @param string $operator | ||
* @param string $checkValue | ||
* @param string $actualValue | ||
* @return bool | ||
*/ | ||
protected function executeStringCheck($operator, $checkValue, $actualValue) { | ||
if ($operator === 'is' || $operator === '!is') { | ||
$checkValue = ltrim(rtrim($checkValue, '/'), '/'); | ||
} | ||
return parent::executeStringCheck($operator, $checkValue, $actualValue); | ||
} | ||
|
||
public function supportedEntities(): array { | ||
return [ File::class ]; | ||
} | ||
|
||
public function isAvailableForScope(int $scope): bool { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
]; | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.