Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
namespace App\Tests\Twig\Runtime;
|
||||
|
||||
use App\Configuration\ConfigLoaderInterface;
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use App\Twig\Runtime\MarkdownExtension;
|
||||
use App\Utils\Markdown;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -23,7 +23,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
public function testMarkdownToHtml()
|
||||
{
|
||||
$loader = $this->createMock(ConfigLoaderInterface::class);
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$config = SystemConfigurationFactory::create($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
$this->assertEquals('<p><em>test</em></p>', $sut->markdownToHtml('*test*'));
|
||||
$this->assertEquals('<h1>foobar</h1>', $sut->markdownToHtml('# foobar'));
|
||||
@@ -36,7 +36,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
public function testTimesheetContent()
|
||||
{
|
||||
$loader = $this->createMock(ConfigLoaderInterface::class);
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => ['markdown_content' => false]]);
|
||||
$config = SystemConfigurationFactory::create($loader, ['timesheet' => ['markdown_content' => false]]);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
$this->assertEquals(
|
||||
"- test<br />\n- foo",
|
||||
@@ -48,7 +48,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
$this->assertEquals('## foobar', $sut->timesheetContent('## foobar'));
|
||||
$this->assertEquals('### foobar', $sut->timesheetContent('### foobar'));
|
||||
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$config = SystemConfigurationFactory::create($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
$this->assertEquals(
|
||||
"<ul>\n<li>test</li>\n<li>foo</li>\n</ul>\n<p>foo <strong>bar</strong></p>",
|
||||
@@ -63,7 +63,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
public function testCommentContent()
|
||||
{
|
||||
$loader = $this->createMock(ConfigLoaderInterface::class);
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => ['markdown_content' => false]]);
|
||||
$config = SystemConfigurationFactory::create($loader, ['timesheet' => ['markdown_content' => false]]);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
$this->assertEquals(
|
||||
"<p>- test<br />\n- foo</p>",
|
||||
@@ -88,7 +88,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
$this->assertEquals('<p>' . $loremIpsum . '</p>', $sut->commentContent($loremIpsum));
|
||||
$this->assertEquals($loremIpsumShort, $sut->commentContent($loremIpsum, false));
|
||||
|
||||
$config = new SystemConfiguration($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$config = SystemConfigurationFactory::create($loader, ['timesheet' => ['markdown_content' => true]]);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
$this->assertEquals(
|
||||
"<ul>\n<li>test</li>\n<li>foo</li>\n</ul>\n<p>foo <strong>bar</strong></p>",
|
||||
@@ -103,7 +103,7 @@ class MarkdownExtensionTest extends TestCase
|
||||
public function testCommentOneLiner()
|
||||
{
|
||||
$loader = $this->createMock(ConfigLoaderInterface::class);
|
||||
$config = new SystemConfiguration($loader, []);
|
||||
$config = SystemConfigurationFactory::create($loader, []);
|
||||
$sut = new MarkdownExtension(new Markdown(), $config);
|
||||
|
||||
$loremIpsum = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.';
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace App\Tests\Twig\Runtime;
|
||||
|
||||
use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\Configuration;
|
||||
use App\Entity\User;
|
||||
use App\Event\ThemeEvent;
|
||||
use App\Tests\Configuration\TestConfigLoader;
|
||||
use App\Tests\Event\ThemeJavascriptTranslationsEventTest;
|
||||
use App\Tests\Mocks\SystemConfigurationFactory;
|
||||
use App\Twig\Runtime\ThemeExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bridge\Twig\AppVariable;
|
||||
@@ -33,9 +33,6 @@ class ThemeEventExtensionTest extends TestCase
|
||||
{
|
||||
return [
|
||||
'theme' => [
|
||||
'active_warning' => 3,
|
||||
'box_color' => 'green',
|
||||
'select_type' => null,
|
||||
'show_about' => true,
|
||||
'chart' => [
|
||||
'background_color' => 'rgba(0,115,183,0.7)',
|
||||
@@ -45,9 +42,7 @@ class ThemeEventExtensionTest extends TestCase
|
||||
],
|
||||
'branding' => [
|
||||
'logo' => null,
|
||||
'mini' => null,
|
||||
'company' => null,
|
||||
'title' => null,
|
||||
],
|
||||
],
|
||||
];
|
||||
@@ -62,11 +57,9 @@ class ThemeEventExtensionTest extends TestCase
|
||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||
$translator->method('trans')->willReturn('foo');
|
||||
|
||||
$configs = [
|
||||
(new Configuration())->setName('theme.branding.title')->setValue($title)
|
||||
];
|
||||
$configs = [];
|
||||
$loader = new TestConfigLoader($configs);
|
||||
$configuration = new SystemConfiguration($loader, $this->getDefaultSettings());
|
||||
$configuration = SystemConfigurationFactory::create($loader, $this->getDefaultSettings());
|
||||
|
||||
return new ThemeExtension($dispatcher, $translator, $configuration);
|
||||
}
|
||||
@@ -108,41 +101,41 @@ class ThemeEventExtensionTest extends TestCase
|
||||
{
|
||||
$sut = $this->getSut();
|
||||
$values = $sut->getJavascriptTranslations();
|
||||
self::assertCount(24, $values);
|
||||
self::assertCount(ThemeJavascriptTranslationsEventTest::COUNTER, $values);
|
||||
}
|
||||
|
||||
public function getProgressbarColors()
|
||||
{
|
||||
yield ['progress-bar-danger', 100, false];
|
||||
yield ['progress-bar-danger', 91, false];
|
||||
yield ['progress-bar-warning', 90, false];
|
||||
yield ['progress-bar-warning', 80, false];
|
||||
yield ['progress-bar-warning', 71, false];
|
||||
yield ['progress-bar-success', 70, false];
|
||||
yield ['progress-bar-success', 60, false];
|
||||
yield ['progress-bar-success', 51, false];
|
||||
yield ['progress-bar-primary', 50, false];
|
||||
yield ['progress-bar-primary', 40, false];
|
||||
yield ['progress-bar-primary', 31, false];
|
||||
yield ['progress-bar-info', 30, false];
|
||||
yield ['progress-bar-info', 20, false];
|
||||
yield ['progress-bar-info', 10, false];
|
||||
yield ['progress-bar-info', 0, false];
|
||||
yield ['progress-bar-primary', 100, true];
|
||||
yield ['progress-bar-primary', 91, true];
|
||||
yield ['progress-bar-success', 90, true];
|
||||
yield ['progress-bar-success', 80, true];
|
||||
yield ['progress-bar-success', 71, true];
|
||||
yield ['progress-bar-warning', 70, true];
|
||||
yield ['progress-bar-warning', 60, true];
|
||||
yield ['progress-bar-warning', 51, true];
|
||||
yield ['progress-bar-danger', 50, true];
|
||||
yield ['progress-bar-danger', 40, true];
|
||||
yield ['progress-bar-danger', 31, true];
|
||||
yield ['progress-bar-info', 30, true];
|
||||
yield ['progress-bar-info', 20, true];
|
||||
yield ['progress-bar-info', 10, true];
|
||||
yield ['progress-bar-info', 0, true];
|
||||
yield ['bg-red', 100, false];
|
||||
yield ['bg-red', 91, false];
|
||||
yield ['bg-warning', 90, false];
|
||||
yield ['bg-warning', 80, false];
|
||||
yield ['bg-warning', 71, false];
|
||||
yield ['bg-green', 70, false];
|
||||
yield ['bg-green', 60, false];
|
||||
yield ['bg-green', 51, false];
|
||||
yield ['bg-green', 50, false];
|
||||
yield ['bg-green', 40, false];
|
||||
yield ['bg-green', 31, false];
|
||||
yield ['', 30, false];
|
||||
yield ['', 20, false];
|
||||
yield ['', 10, false];
|
||||
yield ['', 0, false];
|
||||
yield ['bg-green', 100, true];
|
||||
yield ['bg-green', 91, true];
|
||||
yield ['bg-green', 90, true];
|
||||
yield ['bg-green', 80, true];
|
||||
yield ['bg-green', 71, true];
|
||||
yield ['bg-warning', 70, true];
|
||||
yield ['bg-warning', 60, true];
|
||||
yield ['bg-warning', 51, true];
|
||||
yield ['bg-red', 50, true];
|
||||
yield ['bg-red', 40, true];
|
||||
yield ['bg-red', 31, true];
|
||||
yield ['', 30, true];
|
||||
yield ['', 20, true];
|
||||
yield ['', 10, true];
|
||||
yield ['', 0, true];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,20 +159,9 @@ class ThemeEventExtensionTest extends TestCase
|
||||
public function testGetBrandedTitle()
|
||||
{
|
||||
$sut = $this->getSut(false, 'MyCompany');
|
||||
$this->assertEquals('MyCompany – foo', $sut->generateTitle());
|
||||
$this->assertEquals('sdfsdf | MyCompany – foo', $sut->generateTitle('sdfsdf | '));
|
||||
$this->assertEquals('<b>MyCompany</b> ... foo', $sut->generateTitle('<b>', '</b> ... '));
|
||||
$this->assertEquals('MyCompany | foo', $sut->generateTitle(null, ' | '));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testThemeConfig()
|
||||
{
|
||||
$sut = $this->getSut(false);
|
||||
self::assertEquals(3, $sut->getThemeConfig('active_warning'));
|
||||
self::assertEquals('green', $sut->getThemeConfig('box_color'));
|
||||
self::assertFalse($sut->getThemeConfig('auto_reload_datatable'));
|
||||
$this->assertEquals('Kimai – foo', $sut->generateTitle());
|
||||
$this->assertEquals('sdfsdf | Kimai – foo', $sut->generateTitle('sdfsdf | '));
|
||||
$this->assertEquals('<b>Kimai</b> ... foo', $sut->generateTitle('<b>', '</b> ... '));
|
||||
$this->assertEquals('Kimai | foo', $sut->generateTitle(null, ' | '));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace App\Tests\Twig\Runtime;
|
||||
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Repository\BookmarkRepository;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\FavoriteRecordService;
|
||||
use App\Twig\Runtime\TimesheetExtension;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -20,14 +22,43 @@ use PHPUnit\Framework\TestCase;
|
||||
*/
|
||||
class TimesheetExtensionTest extends TestCase
|
||||
{
|
||||
public function testGetExporter()
|
||||
public function testActiveEntries()
|
||||
{
|
||||
$entries = [new Timesheet(), new Timesheet()];
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->method('getActiveEntries')->willReturn($entries);
|
||||
|
||||
$sut = new TimesheetExtension($repository);
|
||||
$bookmarks = $this->createMock(BookmarkRepository::class);
|
||||
$service = new FavoriteRecordService($repository, $bookmarks);
|
||||
|
||||
$sut = new TimesheetExtension($repository, $service);
|
||||
self::assertEquals($entries, $sut->activeEntries(new User()));
|
||||
}
|
||||
|
||||
public function testRecentEntries()
|
||||
{
|
||||
$timesheet1 = $this->createMock(Timesheet::class);
|
||||
$timesheet1->method('getId')->willReturn(1);
|
||||
|
||||
$timesheet2 = $this->createMock(Timesheet::class);
|
||||
$timesheet2->method('getId')->willReturn(2);
|
||||
|
||||
$entries = [$timesheet1, $timesheet2];
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->method('findTimesheetsById')->willReturn($entries);
|
||||
$repository->method('getRecentActivityIds')->willReturn([1, 2]);
|
||||
|
||||
$bookmarks = $this->createMock(BookmarkRepository::class);
|
||||
$service = new FavoriteRecordService($repository, $bookmarks);
|
||||
|
||||
$sut = new TimesheetExtension($repository, $service);
|
||||
$favorites = $sut->favoriteEntries(new User());
|
||||
self::assertCount(2, $favorites);
|
||||
self::assertEquals($entries[0], $favorites[0]->getTimesheet());
|
||||
self::assertFalse($favorites[0]->isFavorite());
|
||||
self::assertEquals($entries[1], $favorites[1]->getTimesheet());
|
||||
self::assertFalse($favorites[1]->isFavorite());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,19 +9,23 @@
|
||||
|
||||
namespace App\Tests\Twig\Runtime;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Twig\Runtime\WidgetExtension;
|
||||
use App\Widget\Type\More;
|
||||
use App\Widget\WidgetInterface;
|
||||
use App\Widget\WidgetRendererInterface;
|
||||
use App\Widget\WidgetService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @covers \App\Twig\Runtime\WidgetExtension
|
||||
*/
|
||||
class WidgetExtensionTest extends TestCase
|
||||
{
|
||||
protected function getSut($hasWidget = null, $getWidget = null, $renderer = null): WidgetExtension
|
||||
protected function getSut($hasWidget = null, $getWidget = null): WidgetExtension
|
||||
{
|
||||
$service = $this->createMock(WidgetService::class);
|
||||
if (null !== $hasWidget) {
|
||||
@@ -30,21 +34,42 @@ class WidgetExtensionTest extends TestCase
|
||||
if (null !== $getWidget) {
|
||||
$service->expects($this->once())->method('getWidget')->willReturn($getWidget);
|
||||
}
|
||||
if (null !== $renderer) {
|
||||
$service->expects($this->once())->method('findRenderer')->willReturn($renderer);
|
||||
}
|
||||
|
||||
return new WidgetExtension($service);
|
||||
$interface = $this->createMock(TokenInterface::class);
|
||||
$interface->expects($this->any())->method('getUser')->willReturn(new User());
|
||||
$storage = $this->createMock(TokenStorageInterface::class);
|
||||
$storage->expects($this->any())->method('getToken')->willReturn($interface);
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container->expects($this->any())->method('get')->willReturn($storage);
|
||||
|
||||
$security = new Security($container);
|
||||
|
||||
return new WidgetExtension($service, $security);
|
||||
}
|
||||
|
||||
private function getEnvironment(): Environment
|
||||
{
|
||||
$env = $this->createMock(Environment::class);
|
||||
$env->expects($this->any())->method('render')->willReturnCallback(function (string $template, array $options) {
|
||||
self::assertArrayHasKey('data', $options);
|
||||
self::assertArrayHasKey('options', $options);
|
||||
self::assertArrayHasKey('title', $options);
|
||||
self::assertArrayHasKey('widget', $options);
|
||||
|
||||
return json_encode($options['options']);
|
||||
});
|
||||
|
||||
return $env;
|
||||
}
|
||||
|
||||
public function testRenderWidgetForInvalidValue()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Widget must either implement WidgetInterface or be a string');
|
||||
$this->expectExceptionMessage('Widget must be either a WidgetInterface or a string');
|
||||
|
||||
$sut = $this->getSut();
|
||||
/* @phpstan-ignore-next-line */
|
||||
$sut->renderWidget(true);
|
||||
$sut->renderWidget($this->getEnvironment(), true);
|
||||
}
|
||||
|
||||
public function testRenderWidgetForUnknownWidget()
|
||||
@@ -53,15 +78,16 @@ class WidgetExtensionTest extends TestCase
|
||||
$this->expectExceptionMessage('Unknown widget "test" requested');
|
||||
|
||||
$sut = $this->getSut(false);
|
||||
$sut->renderWidget('test');
|
||||
$sut->renderWidget($this->getEnvironment(), 'test');
|
||||
}
|
||||
|
||||
public function testRenderWidgetByString()
|
||||
{
|
||||
$widget = new More();
|
||||
$sut = $this->getSut(true, $widget, new TestRenderer());
|
||||
$widget->setId('test');
|
||||
$sut = $this->getSut(true, $widget);
|
||||
$options = ['foo' => 'bar', 'dataType' => 'blub'];
|
||||
$result = $sut->renderWidget('test', $options);
|
||||
$result = $sut->renderWidget($this->getEnvironment(), 'test', $options);
|
||||
$data = json_decode($result, true);
|
||||
$this->assertEquals($options, $data);
|
||||
}
|
||||
@@ -69,23 +95,10 @@ class WidgetExtensionTest extends TestCase
|
||||
public function testRenderWidgetObject()
|
||||
{
|
||||
$widget = new More();
|
||||
$sut = $this->getSut(null, null, new TestRenderer());
|
||||
$sut = $this->getSut(null, null);
|
||||
$options = ['foo' => 'bar', 'dataType' => 'blub'];
|
||||
$result = $sut->renderWidget($widget, $options);
|
||||
$result = $sut->renderWidget($this->getEnvironment(), $widget, $options);
|
||||
$data = json_decode($result, true);
|
||||
$this->assertEquals($options, $data);
|
||||
}
|
||||
}
|
||||
|
||||
class TestRenderer implements WidgetRendererInterface
|
||||
{
|
||||
public function supports(WidgetInterface $widget): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function render(WidgetInterface $widget, array $options = []): string
|
||||
{
|
||||
return json_encode($widget->getOptions($options));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user