-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff41a1e
commit 4c7d37e
Showing
5 changed files
with
129 additions
and
13 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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Service; | ||
|
||
/* | ||
* (c) 2022 Tomas Norre Mikkelsen <[email protected]> | ||
* | ||
* This file is part of the TYPO3 Crawler Extension. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* @internal since v11.0.3 | ||
*/ | ||
class ProcessInstructionService | ||
{ | ||
public function isAllowed(string $processInstruction, array $incoming): bool | ||
{ | ||
if (empty($incoming)) { | ||
return true; | ||
} | ||
|
||
foreach ($incoming as $pi) { | ||
if (GeneralUtility::inList($processInstruction, $pi)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AOE\Crawler\Tests\Unit\Service; | ||
|
||
/* | ||
* (c) 2022 Tomas Norre Mikkelsen <[email protected]> | ||
* | ||
* This file is part of the TYPO3 Crawler Extension. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
use AOE\Crawler\Service\ProcessInstructionService; | ||
|
||
#[\PHPUnit\Framework\Attributes\CoversClass(\AOE\Crawler\Service\ProcessInstructionService::class)] | ||
class ProcessInstructionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase | ||
{ | ||
private ProcessInstructionService $processInstructionService; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->processInstructionService = new ProcessInstructionService(); | ||
} | ||
|
||
#[\PHPUnit\Framework\Attributes\Test] | ||
#[\PHPUnit\Framework\Attributes\DataProvider('isAllowedDataProvider')] | ||
public function isAllowReturnsExpectedBoolValue( | ||
string $piString, | ||
array $incomingProcInstructions, | ||
bool $expected | ||
): void { | ||
self::assertEquals( | ||
$expected, | ||
$this->processInstructionService->isAllowed($piString, $incomingProcInstructions) | ||
); | ||
} | ||
|
||
public static function isAllowedDataProvider(): iterable | ||
{ | ||
yield 'Not in list' => [ | ||
'piString' => 'tx_indexedsearch_reindex,tx_esetcache_clean_main', | ||
'incomingProcInstructions' => ['tx_unknown_extension_instruction'], | ||
'expected' => false, | ||
]; | ||
yield 'In list' => [ | ||
'piString' => 'tx_indexedsearch_reindex,tx_esetcache_clean_main', | ||
'incomingProcInstructions' => ['tx_indexedsearch_reindex'], | ||
'expected' => true, | ||
]; | ||
yield 'Twice in list' => [ | ||
'piString' => 'tx_indexedsearch_reindex,tx_esetcache_clean_main', | ||
'incomingProcInstructions' => ['tx_indexedsearch_reindex', 'tx_indexedsearch_reindex'], | ||
'expected' => true, | ||
]; | ||
yield 'Empty incomingProcInstructions' => [ | ||
'piString' => '', | ||
'incomingProcInstructions' => [], | ||
'expected' => true, | ||
]; | ||
yield 'In list CAPITALIZED' => [ | ||
'piString' => 'tx_indexedsearch_reindex,tx_esetcache_clean_main', | ||
'incomingProcInstructions' => ['TX_INDEXEDSEARCH_REINDES'], | ||
'expected' => false, | ||
]; | ||
} | ||
} |
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