diff --git a/tests/phpunit/Models/Configuration/MarkerTest.php b/tests/phpunit/Models/Configuration/MarkerTest.php new file mode 100644 index 00000000..14fcb97e --- /dev/null +++ b/tests/phpunit/Models/Configuration/MarkerTest.php @@ -0,0 +1,31 @@ +'); + + $this->assertEquals('<', $marker->getStart()); + } + + /** + * @return void + */ + public function testEnd(): void + { + $marker = new Marker('<', '>'); + + $this->assertEquals('>', $marker->getEnd()); + } + +} diff --git a/tests/phpunit/Models/Configuration/ProtectionTest.php b/tests/phpunit/Models/Configuration/ProtectionTest.php new file mode 100644 index 00000000..2b92fac7 --- /dev/null +++ b/tests/phpunit/Models/Configuration/ProtectionTest.php @@ -0,0 +1,51 @@ +addMarker('<', '>'); + $protection->addMarker('[', ']'); + + $this->assertEquals('<', $protection->getMarkers()[0]->getStart()); + $this->assertEquals('[', $protection->getMarkers()[1]->getStart()); + } + + /** + * @return void + */ + public function testAddTerm(): void + { + $protection = new Protection(); + + $protection->addTerm('device'); + + $this->assertEquals('device', $protection->getTerms()[0]); + } + + /** + * @return void + */ + public function testAddTermDuplicateSkipped(): void + { + $protection = new Protection(); + + $protection->addTerm('hardware'); + $protection->addTerm('device'); + $protection->addTerm('device'); + + $this->assertCount(2, $protection->getTerms()); + } + +} \ No newline at end of file diff --git a/tests/phpunit/Models/Configuration/RuleTest.php b/tests/phpunit/Models/Configuration/RuleTest.php new file mode 100644 index 00000000..acee1e58 --- /dev/null +++ b/tests/phpunit/Models/Configuration/RuleTest.php @@ -0,0 +1,31 @@ +assertEquals('color-rule', $rule->getName()); + } + + /** + * @return void + */ + public function testValue(): void + { + $rule = new Rule('color-rule', 'black'); + + $this->assertEquals('black', $rule->getValue()); + } + +} diff --git a/tests/phpunit/Models/Translation/TranslationSetTest.php b/tests/phpunit/Models/Translation/TranslationSetTest.php index 4b96e604..3957c735 100644 --- a/tests/phpunit/Models/Translation/TranslationSetTest.php +++ b/tests/phpunit/Models/Translation/TranslationSetTest.php @@ -7,6 +7,7 @@ use PHPUnuhi\Models\Configuration\Attribute; use PHPUnuhi\Models\Configuration\Filter; use PHPUnuhi\Models\Configuration\Protection; +use PHPUnuhi\Models\Configuration\Rule; use PHPUnuhi\Models\Translation\Locale; use PHPUnuhi\Models\Translation\TranslationSet; @@ -42,6 +43,43 @@ public function testFormat() $this->assertEquals('json', $set->getFormat()); } + /** + * @return void + * @throws \Exception + */ + public function testProtection() + { + $attributes = []; + $filter = new Filter(); + $locales = []; + $protection = new Protection(); + + $protection->addTerm('protected-word'); + + $set = new TranslationSet('storefront', 'json', $protection, $locales, $filter, $attributes, [], []); + + $this->assertEquals('protected-word', $set->getProtection()->getTerms()[0]); + } + + /** + * @return void + * @throws \Exception + */ + public function testRules() + { + $attributes = []; + $filter = new Filter(); + $locales = []; + $protection = new Protection(); + $rules = [ + new Rule('test-rule', true), + ]; + + $set = new TranslationSet('storefront', 'json', $protection, $locales, $filter, $attributes, [], $rules); + + $this->assertEquals('test-rule', $set->getRules()[0]->getName()); + } + /** * @return void */ @@ -191,4 +229,5 @@ public function testFindAnyExistingTranslationNotFound() $set->findAnyExistingTranslation('abc', ''); } + }