Skip to content

Commit

Permalink
Fix unit tests for LanguagesButton
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Jul 22, 2024
1 parent 445248d commit 60fd7b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/Panel/Ui/Buttons/LanguagesButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
60 changes: 47 additions & 13 deletions tests/Panel/Ui/Buttons/LanguagesButtonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Kirby\Panel\Ui\Buttons;

use Kirby\Cms\Language;
use Kirby\Panel\Areas\AreaTestCase;

/**
Expand All @@ -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',
Expand All @@ -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);

Expand Down

0 comments on commit 60fd7b9

Please sign in to comment.