Skip to content

Commit

Permalink
add more unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Oct 28, 2023
1 parent 27a69ed commit c565acf
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/phpunit/Models/Configuration/MarkerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace phpunit\Models\Configuration;

use PHPUnit\Framework\TestCase;
use PHPUnuhi\Models\Configuration\Marker;

class MarkerTest extends TestCase
{

/**
* @return void
*/
public function testStart(): void
{
$marker = new Marker('<', '>');

$this->assertEquals('<', $marker->getStart());
}

/**
* @return void
*/
public function testEnd(): void
{
$marker = new Marker('<', '>');

$this->assertEquals('>', $marker->getEnd());
}

}
51 changes: 51 additions & 0 deletions tests/phpunit/Models/Configuration/ProtectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace phpunit\Models\Configuration;

use PHPUnit\Framework\TestCase;
use PHPUnuhi\Models\Configuration\Protection;

class ProtectionTest extends TestCase
{

/**
* @return void
*/
public function testAddMarker(): void
{
$protection = new Protection();

$protection->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());
}

}
31 changes: 31 additions & 0 deletions tests/phpunit/Models/Configuration/RuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace phpunit\Models\Configuration;

use PHPUnit\Framework\TestCase;
use PHPUnuhi\Models\Configuration\Rule;

class RuleTest extends TestCase
{

/**
* @return void
*/
public function testName(): void
{
$rule = new Rule('color-rule', 'black');

$this->assertEquals('color-rule', $rule->getName());
}

/**
* @return void
*/
public function testValue(): void
{
$rule = new Rule('color-rule', 'black');

$this->assertEquals('black', $rule->getValue());
}

}
39 changes: 39 additions & 0 deletions tests/phpunit/Models/Translation/TranslationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -191,4 +229,5 @@ public function testFindAnyExistingTranslationNotFound()

$set->findAnyExistingTranslation('abc', '');
}

}

0 comments on commit c565acf

Please sign in to comment.