Skip to content

Commit cbdd71e

Browse files
afboradistantnative
authored andcommitted
Unit test for the exact case
1 parent 6689e57 commit cbdd71e

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

tests/Cms/Languages/LanguageRoutesTest.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class LanguageRoutesTest extends TestCase
88
{
99
protected $app;
10+
public const FIXTURES = __DIR__ . '/fixtures';
1011

1112
public function setUp(): void
1213
{
@@ -67,6 +68,52 @@ public function testFallback()
6768
$this->assertSame($app->language()->code(), 'en');
6869
}
6970

71+
public static function languagePrefixProvider(): array {
72+
return [
73+
['not-exists', 'Erreur'],
74+
['en/not-exists', 'Error']
75+
];
76+
}
77+
78+
/**
79+
* @dataProvider languagePrefixProvider
80+
*/
81+
public function testLanguagePrefix($path, $body)
82+
{
83+
$app = new App([
84+
'roots' => [
85+
'index' => static::FIXTURES,
86+
'languages' => static::FIXTURES . '/languages',
87+
'templates' => static::FIXTURES . '/templates'
88+
],
89+
'site' => [
90+
'children' => [
91+
[
92+
'slug' => 'error',
93+
'template' => 'error',
94+
'translations' => [
95+
[
96+
'code' => 'fr',
97+
'content' => [
98+
'title' => 'Erreur'
99+
]
100+
],
101+
[
102+
'code' => 'en',
103+
'content' => [
104+
'title' => 'Error'
105+
]
106+
]
107+
]
108+
]
109+
]
110+
]
111+
]);
112+
113+
114+
$this->assertSame($body, $app->render($path)->body());
115+
}
116+
70117
public function testNotNextWhenFalsyReturn()
71118
{
72119
$a = $b = $c = $d = $e = 0;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return [
4+
'code' => 'en',
5+
'default' => false,
6+
'direction' => 'ltr',
7+
'locale' => [
8+
'LC_ALL' => 'en_US'
9+
],
10+
'name' => 'English',
11+
'translations' => [
12+
13+
],
14+
'url' => NULL
15+
];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
return [
4+
'code' => 'fr',
5+
'default' => true,
6+
'direction' => 'ltr',
7+
'locale' => [
8+
'LC_ALL' => 'fr_FR'
9+
],
10+
'name' => 'French',
11+
'translations' => [
12+
13+
],
14+
'url' => '/'
15+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?= $page->title();

0 commit comments

Comments
 (0)