Skip to content

Commit

Permalink
Cover static method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Stichoza committed Dec 18, 2023
1 parent e63e407 commit d142619
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tests/TranslationTest.php
Expand Up @@ -31,23 +31,29 @@ public function testTranslationEquality(): void

public function testTranslationKeyExtraction(): void
{
$result = $this->tr->setSource('en')->setTarget('fr')->preserveParameters()->translate('Hello :name, how are :type_of_greeting?');
$resultOne = GoogleTranslate::trans('Hello :name how are :type_of_greeting?', 'fr', 'en', preserveParameters: true);
$resultTwo = $this->tr->setSource('en')->setTarget('fr')->preserveParameters()->translate('Hello :name, how are :type_of_greeting?');

$this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $result, 'Translation should be correct with proper key extraction.');
$this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $resultOne, 'Translation should be correct with proper key extraction.');
$this->assertEquals('Bonjour :name, comment vont :type_of_greeting ?', $resultTwo, 'Translation should be correct with proper key extraction.');
}

public function testCanIgnoreTranslationKeyExtraction(): void
{
$result = $this->tr->setSource('en')->setTarget('fr')->translate('Hello :name how are :greeting?');
$resultOne = GoogleTranslate::trans('Hello :name how are :greeting?', 'fr', 'en');
$resultTwo = $this->tr->setSource('en')->setTarget('fr')->translate('Hello :name how are :greeting?');

$this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $result, 'Translation should be correct and ignores key extraction if not set.');
$this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $resultOne, 'Translation should be correct and ignores key extraction if not set.');
$this->assertEquals('Bonjour :nom, comment allez-vous :salut ?', $resultTwo, 'Translation should be correct and ignores key extraction if not set.');
}

public function testCanCustomizeExtractionPattern(): void
{
$result = $this->tr->setSource('en')->setTarget('fr')->preserveParameters('/\{\{([^}]+)\}\}/')->translate('Hello {{name}}, how are {{type_of_greeting}}?');
$resultOne = GoogleTranslate::trans('Hello {{name}}, how are {{type_of_greeting}}?', 'fr', 'en', preserveParameters: '/\{\{([^}]+)\}\}/');
$resultTwo = $this->tr->setSource('en')->setTarget('fr')->preserveParameters('/\{\{([^}]+)\}\}/')->translate('Hello {{name}}, how are {{type_of_greeting}}?');

$this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $result, 'Translation should be correct and ignores key extraction if not set.');
$this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $resultOne, 'Translation should be correct and ignores key extraction if not set.');
$this->assertEquals('Bonjour {{name}}, comment vont {{type_of_greeting}} ?', $resultTwo, 'Translation should be correct and ignores key extraction if not set.');
}

public function testNewerLanguageTranslation(): void
Expand Down

0 comments on commit d142619

Please sign in to comment.