diff --git a/src/Panel/Ui/Buttons/LanguagesButton.php b/src/Panel/Ui/Buttons/LanguagesButton.php index a521eaf55d..b077ce3d24 100644 --- a/src/Panel/Ui/Buttons/LanguagesButton.php +++ b/src/Panel/Ui/Buttons/LanguagesButton.php @@ -35,16 +35,16 @@ class: 'k-view-languages-button', ); } - protected function option(Language $language): array + public function option(Language $language): array { return [ 'text' => $language->name(), 'code' => $language->code(), - 'current' => $language->code() === $this->kirby->language()->code(), + 'current' => $language->code() === $this->kirby->language()?->code(), ]; } - protected function options(): array + public function options(): array { $languages = $this->kirby->languages(); $options = []; diff --git a/tests/Panel/Ui/Buttons/LanguagesButtonTest.php b/tests/Panel/Ui/Buttons/LanguagesButtonTest.php index 509054b30c..914c428052 100644 --- a/tests/Panel/Ui/Buttons/LanguagesButtonTest.php +++ b/tests/Panel/Ui/Buttons/LanguagesButtonTest.php @@ -2,6 +2,7 @@ namespace Kirby\Panel\Ui\Buttons; +use Kirby\Cms\Language; use Kirby\Panel\Areas\AreaTestCase; /** @@ -11,29 +12,37 @@ class LanguagesButtonTest extends AreaTestCase { /** - * @covers ::render + * @covers ::option */ - public function testSingleLang() + public function testOption() { - $button = new LanguagesButton(); - $this->assertNull($button->render()); + $language = new Language(['name' => 'Deutsch', 'code' => 'de']); + $button = new LanguagesButton(); + $this->assertSame([ + 'text' => 'Deutsch', + 'code' => 'de', + 'current' => false + ], $button->option($language)); + } + + /** + * @covers ::options + */ + public function testOptionsSingleLang() + { + $button = new LanguagesButton(); + $this->assertSame([], $button->options()); } /** - * @covers ::option * @covers ::options - * @covers ::props - * @covers ::render */ - public function tesMultiLang() + public function testOptionsMultiLang() { $this->enableMultilang(); $this->installLanguages(); - $button = new LanguagesButton(); - $this->assertSame('k-view-languages-button', $button->component); - $this->assertSame('k-view-languages-button', $button->class); - $this->assertSame('translate', $button->icon); + $button = new LanguagesButton(); $this->assertSame([ [ 'text' => 'English', @@ -46,7 +55,32 @@ public function tesMultiLang() 'code' => 'de', 'current' => false ] - ], $button->options); + ], $button->options()); + } + + /** + * @covers ::render + */ + public function testRenderSingleLang() + { + $button = new LanguagesButton(); + $this->assertNull($button->render()); + } + + /** + * @covers ::props + * @covers ::render + */ + public function testRenderMultiLang() + { + $this->enableMultilang(); + $this->installLanguages(); + + $button = new LanguagesButton(); + $this->assertSame('k-view-languages-button', $button->component); + $this->assertSame('k-view-languages-button', $button->class); + $this->assertSame('translate', $button->icon); + $this->assertCount(3, $button->options); $this->assertSame('text', $button->responsive); $this->assertSame('EN', $button->text);