Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Dec 22, 2023
1 parent 83e7064 commit c224313
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/phpunit/Models/Translation/TranslationSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PHPUnuhi\Models\Configuration\Protection;
use PHPUnuhi\Models\Configuration\Rule;
use PHPUnuhi\Models\Translation\Locale;
use PHPUnuhi\Models\Translation\Translation;
use PHPUnuhi\Models\Translation\TranslationSet;

class TranslationSetTest extends TestCase
Expand Down Expand Up @@ -231,6 +232,26 @@ public function testFindAnyExistingTranslationNotFound(): void
$set->findAnyExistingTranslation('abc', '');
}

/**
* @throws Exception
* @return void
*/
public function testFindAnyExistingTranslationThrowsErrorOnEmptyValues(): void
{
$this->expectException(TranslationNotFoundException::class);

$localeEN = new Locale('EN', '', '');
$localeEN->addTranslation('btnCancel', '', '');

$locales = [$localeEN];
$attributes = [];
$filter = new Filter();

$set = new TranslationSet('storefront', 'json', new Protection(), $locales, $filter, $attributes, [], []);

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

/**
* This test verifies that the isCompletelyTranslated() works correctly.
* We start with a EN translation, the DE one is missing, so it's not completely translated.
Expand Down Expand Up @@ -271,4 +292,33 @@ public function testIsCompletelyTranslated(): void
$isTranslated = $set->isCompletelyTranslated('btnCancel');
$this->assertTrue($isTranslated);
}

/**
* @throws TranslationNotFoundException
* @return void
*/
public function testFindAnyExistingTranslationSkipsWrongIDs(): void
{
$attributes = [];
$filter = new Filter();

$localeEN = new Locale('EN', '', '');
$localeEN->addTranslation('1', 'Cancel', '');
$localeEN->addTranslation('2', 'Cancel', '');
$localeEN->addTranslation('3', 'Cancel', '');
$localeEN->addTranslation('btnCancel', 'Cancel', '');

$locales = [$localeEN];

$set = new TranslationSet('storefront', 'json', new Protection(), $locales, $filter, $attributes, [], []);

$existing = $set->findAnyExistingTranslation('btnCancel', 'EN');

$expected = [
'locale' => 'EN',
'translation' => new Translation('btnCancel', 'Cancel', '')
];

$this->assertEquals($expected, $existing);
}
}

0 comments on commit c224313

Please sign in to comment.