Skip to content

Commit

Permalink
Fixup some test cases that throw warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
williamdes committed Feb 13, 2025
1 parent d5d8954 commit 7f0152b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
12 changes: 5 additions & 7 deletions tests/I18nTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function testPluralTranslation(): void
' array("%nbr%" => ($context["nbr"] ?? null), ));',
$generatedCode
);
$html = $template->render(['nbr' => 5]);
$html = $template->render(['nbr' => 5, 'nbr_persons' => 0]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}
Expand All @@ -258,7 +258,7 @@ public function testPluralTranslationWithComment(): void
'// l10n: Number of users',
$generatedCode
);
$html = $template->render(['nbr' => 5]);
$html = $template->render(['nbr' => 5, 'nbr_persons' => 0]);
$this->assertEquals('one user likes this.', $html);
$this->assertNotEmpty($html);
}
Expand All @@ -277,15 +277,13 @@ public function testSimplePluralTranslation(): void
'yield \Wdes\phpI18nL10n\Launcher::getPlugin()->ngettext("One person", "persons", abs( // line 1' . "\n" . '($context["a"] ?? null)));',
$generatedCode
);
$html = $template->render(['nbr' => 5]);
$html = $template->render(['nbr' => 5, 'a' => 0]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}

/**
* Test simple plural translation using count
* @return void
*/
public function testSimplePluralTranslationCount(): void
Expand All @@ -300,7 +298,7 @@ public function testSimplePluralTranslationCount(): void
'($context["a"] ?? null), "count", [], "any", false, false, false, 1)));',
$generatedCode
);
$html = $template->render(['a' => ['1', '2']]);
$html = $template->render(['a' => [1, 2]]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}
Expand All @@ -323,7 +321,7 @@ public function testSimplePluralTranslationCountAndVars(): void
' $this->source, ($context["a"] ?? null), "count", [], "any", false, false, false, 1)), ));',
$generatedCode
);
$html = $template->render(['a' => ['1', '2'], 'nbrdogs' => 3]);
$html = $template->render(['a' => [1, 2], 'nbrdogs' => 3]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}
Expand Down
26 changes: 7 additions & 19 deletions tests/I18nTestNoData.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class I18nTestNoData extends TestCase
/**
* Set up the instance
*
* @return void
*/
public function setUp(): void
{
Expand All @@ -56,7 +55,6 @@ public function setUp(): void

/**
* Test simple translation using get and set
* @return void
*/
public function testSimpleTranslationGetSetTranslations(): void
{
Expand Down Expand Up @@ -90,7 +88,6 @@ public function testSimpleTranslationGetSetTranslations(): void

/**
* Test simple translation
* @return void
*/
public function testSimpleTranslation(): void
{
Expand All @@ -104,7 +101,6 @@ public function testSimpleTranslation(): void

/**
* Test simple translation with a comment
* @return void
*/
public function testSimpleTranslationWithComment(): void
{
Expand All @@ -118,7 +114,6 @@ public function testSimpleTranslationWithComment(): void

/**
* Test simple translation with context
* @return void
*/
public function testSimpleTranslationWithContext(): void
{
Expand All @@ -132,7 +127,6 @@ public function testSimpleTranslationWithContext(): void

/**
* Test simple translation with context and a variable
* @return void
*/
public function testSimpleTranslationWithContextAndVariable(): void
{
Expand All @@ -150,7 +144,6 @@ public function testSimpleTranslationWithContextAndVariable(): void

/**
* Test simple translation with context and some variables
* @return void
*/
public function testSimpleTranslationWithContextAndVariables(): void
{
Expand All @@ -169,43 +162,40 @@ public function testSimpleTranslationWithContextAndVariables(): void

/**
* Test plural translation
* @return void
*/
public function testPluralTranslation(): void
{
$template = $this->twig->createTemplate(
'{% trans %}One person{% plural nbr_persons %}{{ nbr }} persons{% endtrans %}'
);
$html = $template->render(['nbr' => 5]);
$html = $template->render(['nbr' => 5, 'nbr_persons' => 0]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}

/**
* Test plural translation with comment
* @return void
*/
public function testPluralTranslationWithComment(): void
{
$template = $this->twig->createTemplate(
'{% trans %}one user likes this.{% plural nbr_persons %}{{ nbr }} users likes this.{% notes %}Number of users{% endtrans %}'
);
$html = $template->render(['nbr' => 5]);
$html = $template->render(['nbr' => 5, 'nbr_persons' => 0]);
$this->assertEquals('one user likes this.', $html);
$this->assertNotEmpty($html);
}

/**
* Test simple plural translation
* @return void
*/
public function testSimplePluralTranslation(): void
{
$template = $this->twig->createTemplate(
'{% trans %}One person{% plural a %}persons{% endtrans %}'
'{% trans %}One person{% plural nbr %}persons{% endtrans %}'
);
$html = $template->render(['nbr' => 5]);
$this->assertEquals('One person', $html);
$this->assertEquals('persons', $html);
$this->assertNotEmpty($html);
}

Expand All @@ -220,28 +210,26 @@ public function testSimplePluralTranslationCount(): void
$template = $this->twig->createTemplate(
'{% trans %}One person{% plural a.count %}persons{% endtrans %}'
);
$html = $template->render(['a' => ['1', '2']]);
$html = $template->render(['a' => [1, 2]]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}

/**
* Test simple plural translation using count and vars
* @return void
*/
public function testSimplePluralTranslationCountAndVars(): void
{
$template = $this->twig->createTemplate(
'{% trans %}One person{% plural a.count %}persons and {{ count }} dogs{% endtrans %}'
'{% trans %}One person{% plural a.count %}persons and {{ nbrdogs }} dogs{% endtrans %}'
);
$html = $template->render(['a' => ['1', '2'], 'nbrdogs' => 3]);
$html = $template->render(['a' => [1, 2], 'nbrdogs' => 3]);
$this->assertEquals('One person', $html);
$this->assertNotEmpty($html);
}

/**
* Test simple plural translation using count and vars
* @return void
*/
public function testExtensionI18nGetName(): void
{
Expand Down

0 comments on commit 7f0152b

Please sign in to comment.