Skip to content

Commit

Permalink
Unit test for the exact case
Browse files Browse the repository at this point in the history
  • Loading branch information
afbora authored and distantnative committed Sep 12, 2024
1 parent 6689e57 commit cbdd71e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/Cms/Languages/LanguageRoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class LanguageRoutesTest extends TestCase
{
protected $app;
public const FIXTURES = __DIR__ . '/fixtures';

public function setUp(): void
{
Expand Down Expand Up @@ -67,6 +68,52 @@ public function testFallback()
$this->assertSame($app->language()->code(), 'en');
}

public static function languagePrefixProvider(): array {
return [
['not-exists', 'Erreur'],
['en/not-exists', 'Error']
];
}

/**
* @dataProvider languagePrefixProvider
*/
public function testLanguagePrefix($path, $body)
{
$app = new App([
'roots' => [
'index' => static::FIXTURES,
'languages' => static::FIXTURES . '/languages',
'templates' => static::FIXTURES . '/templates'
],
'site' => [
'children' => [
[
'slug' => 'error',
'template' => 'error',
'translations' => [
[
'code' => 'fr',
'content' => [
'title' => 'Erreur'
]
],
[
'code' => 'en',
'content' => [
'title' => 'Error'
]
]
]
]
]
]
]);


$this->assertSame($body, $app->render($path)->body());
}

public function testNotNextWhenFalsyReturn()
{
$a = $b = $c = $d = $e = 0;
Expand Down
15 changes: 15 additions & 0 deletions tests/Cms/Languages/fixtures/languages/en.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

return [
'code' => 'en',
'default' => false,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'en_US'
],
'name' => 'English',
'translations' => [

],
'url' => NULL
];
15 changes: 15 additions & 0 deletions tests/Cms/Languages/fixtures/languages/fr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

return [
'code' => 'fr',
'default' => true,
'direction' => 'ltr',
'locale' => [
'LC_ALL' => 'fr_FR'
],
'name' => 'French',
'translations' => [

],
'url' => '/'
];
1 change: 1 addition & 0 deletions tests/Cms/Languages/fixtures/templates/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?= $page->title();

0 comments on commit cbdd71e

Please sign in to comment.