Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize route and raw_route, fix empty route as values #3184

Merged
merged 9 commits into from
Feb 8, 2021
3 changes: 2 additions & 1 deletion system/src/Grav/Common/Page/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public function translatedLanguages($onlyPublished = false)
if ($exists) {
$aPage = new Page();
$aPage->init(new SplFileInfo($path), $languageExtension);

$aPage->route($this->route());
$aPage->rawRoute($this->rawRoute());
$route = $aPage->header()->routes['default'] ?? $aPage->rawRoute();
if (!$route) {
$route = $aPage->route();
Expand Down
1 change: 0 additions & 1 deletion system/src/Grav/Common/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,6 @@ public static function pathPrefixedByLangCode($string)
if (count($parts) > 0 && in_array($parts[0], $languages_enabled)) {
return $parts[0];
}

return false;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
$grav = Grav::instance();
$grav['config']->init();

// This must be set first before the other init
$grav['config']->set('system.languages.supported', ['en', 'fr', 'vi']);
$grav['config']->set('system.languages.default_lang', 'en');

foreach (array_keys($grav['setup']->getStreams()) as $stream) {
@stream_wrapper_unregister($stream);
}
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Simple Page avec traduction
---

Simple Page Content in English
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Simple Page avec traduction
---

Page Simple FR
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Simple Page avec traduction
---

Page Simple FR
25 changes: 25 additions & 0 deletions tests/unit/Grav/Common/Page/PagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,31 @@ public function testGetList(): void
self::assertSame('—-▸ Blog', $list['/blog']);
}

public function testTranslatedLanguages(): void
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$folder = $locator->findResource('tests://');

$page = $this->pages->get($folder . '/fake/simple-site/user/pages/04.page-translated');
$this->assertInstanceOf(PageInterface::class, $page);
$translatedLanguages = $page->translatedLanguages();
$this->assertIsArray($translatedLanguages);
$this->assertSame(["en" => "/page-translated", "fr" => "/page-translated"], $translatedLanguages);
}

public function testLongPathTranslatedLanguages(): void
{
/** @var UniformResourceLocator $locator */
$locator = $this->grav['locator'];
$folder = $locator->findResource('tests://');
$page = $this->pages->get($folder . '/fake/simple-site/user/pages/05.translatedlong/part2');
$this->assertInstanceOf(PageInterface::class, $page);
$translatedLanguages = $page->translatedLanguages();
$this->assertIsArray($translatedLanguages);
$this->assertSame(["en" => "/translatedlong/part2", "fr" => "/translatedlong/part2"], $translatedLanguages);
}

public function testGetTypes(): void
{
}
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/Grav/Common/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ public function testPathPrefixedByLangCode(): void
$oneLanguageNotEnabled = reset($languagesNotEnabled);

if (count($languagesEnabled)) {
self::assertTrue(Utils::pathPrefixedByLangCode('/' . $languagesEnabled[0] . '/test'));
$languageCodePathPrefix = Utils::pathPrefixedByLangCode('/' . $languagesEnabled[0] . '/test');
$this->assertIsString($languageCodePathPrefix);
$this->assertTrue(in_array($languageCodePathPrefix, $languagesEnabled));
}

self::assertFalse(Utils::pathPrefixedByLangCode('/' . $oneLanguageNotEnabled . '/test'));
Expand Down