added event to manage javascript translations (#2104)

This commit is contained in:
Kevin Papst
2020-11-09 13:28:22 +01:00
committed by GitHub
parent 66865b553e
commit bd4efad22b
7 changed files with 127 additions and 25 deletions

View File

@@ -0,0 +1,40 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Event;
use App\Event\ThemeJavascriptTranslationsEvent;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Event\ThemeJavascriptTranslationsEvent
*/
class ThemeJavascriptTranslationsEventTest extends TestCase
{
public function testDefaultValues()
{
$sut = new ThemeJavascriptTranslationsEvent();
$this->assertCount(23, $sut->getTranslations());
}
public function testGetterAndSetter()
{
$sut = new ThemeJavascriptTranslationsEvent();
$sut->setTranslation('foo', 'bar');
$sut->setTranslation('hello', 'world', 'testing');
$result = $sut->getTranslations();
self::assertCount(25, $result);
self::assertArrayHasKey('foo', $result);
self::assertEquals(['bar', 'messages'], $result['foo']);
self::assertArrayHasKey('hello', $result);
self::assertEquals(['world', 'testing'], $result['hello']);
}
}

View File

@@ -25,7 +25,7 @@ class EventExtensionsTest extends TestCase
public function testGetFunctions()
{
$functions = ['trigger'];
$functions = ['trigger', 'javascript_translations'];
$sut = $this->getSut();
$twigFunctions = $sut->getFunctions();
self::assertCount(\count($functions), $twigFunctions);

View File

@@ -24,7 +24,7 @@ class ThemeEventExtensionTest extends TestCase
protected function getSut(bool $hasListener = true): ThemeEventExtension
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$dispatcher->expects($this->once())->method('hasListeners')->willReturn($hasListener);
$dispatcher->method('hasListeners')->willReturn($hasListener);
$dispatcher->expects($hasListener ? $this->once() : $this->never())->method('dispatch');
$user = (new CurrentUserFactory($this))->create(new User());
@@ -45,4 +45,11 @@ class ThemeEventExtensionTest extends TestCase
$event = $sut->trigger('foo', []);
self::assertInstanceOf(ThemeEvent::class, $event);
}
public function testJavascriptTranslations()
{
$sut = $this->getSut();
$values = $sut->getJavascriptTranslations();
self::assertCount(23, $values);
}
}