2021-01-03 21:41:15 +00:00
|
|
|
<?php
|
|
|
|
/** @license MIT
|
|
|
|
* Copyright 2017 J. King, Dustin Wilson et al.
|
|
|
|
* See LICENSE and AUTHORS files for details */
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2021-04-14 15:17:01 +00:00
|
|
|
|
2021-01-03 21:41:15 +00:00
|
|
|
namespace JKingWeb\Arsse\TestCase\Misc;
|
|
|
|
|
|
|
|
use JKingWeb\Arsse\Rule\Rule;
|
|
|
|
|
|
|
|
/** @covers \JKingWeb\Arsse\Rule\Rule */
|
|
|
|
class TestRule extends \JKingWeb\Arsse\Test\AbstractTest {
|
|
|
|
public function testPrepareAPattern(): void {
|
|
|
|
$exp = "`\\`..\\`..\\`..\\\\\\`..`u";
|
2021-01-04 03:15:39 +00:00
|
|
|
$this->assertTrue(Rule::validate("`..`..\\`..\\\\`.."));
|
2021-01-03 21:41:15 +00:00
|
|
|
$this->assertSame($exp, Rule::prep("`..`..\\`..\\\\`.."));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPrepareAnInvalidPattern(): void {
|
2021-01-04 03:15:39 +00:00
|
|
|
$this->assertFalse(Rule::validate("["));
|
2021-01-03 21:41:15 +00:00
|
|
|
$this->assertException("invalidPattern", "Rule");
|
|
|
|
Rule::prep("[");
|
|
|
|
}
|
2021-01-04 03:15:39 +00:00
|
|
|
|
2021-01-08 19:17:46 +00:00
|
|
|
public function testPrepareAnEmptyPattern(): void {
|
|
|
|
$this->assertTrue(Rule::validate(""));
|
|
|
|
$this->assertSame("", Rule::prep(""));
|
|
|
|
}
|
|
|
|
|
2021-01-04 03:15:39 +00:00
|
|
|
/** @dataProvider provideApplications */
|
|
|
|
public function testApplyRules(string $keepRule, string $blockRule, string $title, array $categories, $exp): void {
|
2021-01-08 19:17:46 +00:00
|
|
|
$keepRule = Rule::prep($keepRule);
|
|
|
|
$blockRule = Rule::prep($blockRule);
|
2021-01-08 20:47:19 +00:00
|
|
|
$this->assertSame($exp, Rule::apply($keepRule, $blockRule, $title, $categories));
|
2021-01-04 03:15:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function provideApplications(): iterable {
|
|
|
|
return [
|
2021-01-07 20:08:50 +00:00
|
|
|
["", "", "Title", ["Dummy", "Category"], true],
|
|
|
|
["^Title$", "", "Title", ["Dummy", "Category"], true],
|
|
|
|
["^Category$", "", "Title", ["Dummy", "Category"], true],
|
|
|
|
["^Naught$", "", "Title", ["Dummy", "Category"], false],
|
|
|
|
["", "^Title$", "Title", ["Dummy", "Category"], false],
|
|
|
|
["", "^Category$", "Title", ["Dummy", "Category"], false],
|
|
|
|
["", "^Naught$", "Title", ["Dummy", "Category"], true],
|
|
|
|
["^Category$", "^Category$", "Title", ["Dummy", "Category"], false],
|
|
|
|
["", "^A B C$", "A B\nC", ["X\n Y \t \r Z"], false],
|
|
|
|
["", "^X Y Z$", "A B\nC", ["X\n Y \t \r Z"], false],
|
2021-01-04 03:15:39 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|