users weekly stats as bar-chart in dashboard (#847)
This commit is contained in:
@@ -97,6 +97,12 @@ class AppExtensionTest extends TestCase
|
||||
'box_color' => 'green',
|
||||
'select_type' => null,
|
||||
'show_about' => true,
|
||||
'chart' => [
|
||||
'background_color' => 'rgba(0,115,183,0.7)',
|
||||
'border_color' => '#3b8bba',
|
||||
'grid_color' => 'rgba(0,0,0,.05)',
|
||||
'height' => '200'
|
||||
]
|
||||
],
|
||||
'kimai.theme.select_type' => null,
|
||||
'kimai.theme.show_about' => true,
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace App\Tests\Event;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Event\DashboardEvent;
|
||||
use App\Model\DashboardSection;
|
||||
use App\Widget\Type\CompoundRow;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ class DashboardEventTest extends TestCase
|
||||
$this->assertEquals($user, $sut->getUser());
|
||||
$this->assertEquals([], $sut->getSections());
|
||||
|
||||
$section = new DashboardSection('foo');
|
||||
$section = new CompoundRow();
|
||||
$sut->addSection($section);
|
||||
|
||||
$this->assertEquals([$section], $sut->getSections());
|
||||
|
||||
@@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
* @covers \App\Export\Renderer\CsvRenderer
|
||||
* @covers \App\Export\Renderer\AbstractSpreadsheetRenderer
|
||||
* @covers \App\Export\Renderer\RendererTrait
|
||||
* @group integration
|
||||
*/
|
||||
class CsvRendererTest extends AbstractRendererTest
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ use Twig\Environment;
|
||||
/**
|
||||
* @covers \App\Export\Renderer\HtmlRenderer
|
||||
* @covers \App\Export\Renderer\RendererTrait
|
||||
* @group integration
|
||||
*/
|
||||
class HtmlRendererTest extends AbstractRendererTest
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
* @covers \App\Export\Renderer\OdsRenderer
|
||||
* @covers \App\Export\Renderer\AbstractSpreadsheetRenderer
|
||||
* @covers \App\Export\Renderer\RendererTrait
|
||||
* @group integration
|
||||
*/
|
||||
class OdsRendererTest extends AbstractRendererTest
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ use Twig\Environment;
|
||||
/**
|
||||
* @covers \App\Export\Renderer\PDFRenderer
|
||||
* @covers \App\Export\Renderer\RendererTrait
|
||||
* @group integration
|
||||
*/
|
||||
class PdfRendererTest extends AbstractRendererTest
|
||||
{
|
||||
|
||||
@@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
* @covers \App\Export\Renderer\XlsxRenderer
|
||||
* @covers \App\Export\Renderer\AbstractSpreadsheetRenderer
|
||||
* @covers \App\Export\Renderer\RendererTrait
|
||||
* @group integration
|
||||
*/
|
||||
class XlsxRendererTest extends AbstractRendererTest
|
||||
{
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?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\Model;
|
||||
|
||||
use App\Model\DashboardSection;
|
||||
use App\Model\Widget;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\DashboardSection
|
||||
*/
|
||||
class DashboardSectionTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new DashboardSection('test');
|
||||
$this->assertEquals('test', $sut->getTitle());
|
||||
$this->assertEquals(0, $sut->getOrder());
|
||||
$this->assertEquals([], $sut->getWidgets());
|
||||
$this->assertEquals(DashboardSection::TYPE_SIMPLE, $sut->getType());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new DashboardSection('hello-world');
|
||||
$sut->setType(DashboardSection::TYPE_CHART);
|
||||
$sut->setOrder(13);
|
||||
$sut->addWidget(new Widget('bar', []));
|
||||
|
||||
$this->assertCount(1, $sut->getWidgets());
|
||||
$this->assertEquals(DashboardSection::TYPE_CHART, $sut->getType());
|
||||
$this->assertEquals(13, $sut->getOrder());
|
||||
$this->assertEquals('bar', $sut->getWidgets()[0]->getTitle());
|
||||
}
|
||||
}
|
||||
42
tests/Model/Statistic/DayTest.php
Normal file
42
tests/Model/Statistic/DayTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?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\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Day;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Day
|
||||
*/
|
||||
class DayTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new Day($date, 12340, 197.25956);
|
||||
|
||||
$this->assertSame($date, $sut->getDay());
|
||||
$this->assertEquals(12340, $sut->getTotalDuration());
|
||||
$this->assertEquals(197.25956, $sut->getTotalRate());
|
||||
}
|
||||
|
||||
public function testAllowedMonths()
|
||||
{
|
||||
$date = new DateTime('-8 hours');
|
||||
$sut = new Day($date, 12340, 197.25956);
|
||||
|
||||
$sut->setTotalDuration(999.27);
|
||||
$sut->setTotalRate(0.123456789);
|
||||
|
||||
$this->assertEquals(999, $sut->getTotalDuration());
|
||||
$this->assertEquals(0.123456789, $sut->getTotalRate());
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -42,12 +44,12 @@ class MonthTest extends TestCase
|
||||
$ex = null;
|
||||
try {
|
||||
new Month($month);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
$ex = $e;
|
||||
}
|
||||
$this->assertInstanceOf(\InvalidArgumentException::class, $ex);
|
||||
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
|
||||
$this->assertEquals(
|
||||
'Invalid month given, expected 01-12 but given: ' . ((int) $month),
|
||||
'Invalid month given. Expected 1-12, received "' . ((int) $month) . '".',
|
||||
$ex->getMessage()
|
||||
);
|
||||
}
|
||||
@@ -59,7 +61,7 @@ class MonthTest extends TestCase
|
||||
$sut->setTotalDuration(999.27);
|
||||
$sut->setTotalRate(0.123456789);
|
||||
|
||||
$this->assertEquals(999.27, $sut->getTotalDuration());
|
||||
$this->assertEquals(999, $sut->getTotalDuration());
|
||||
$this->assertEquals(0.123456789, $sut->getTotalRate());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Model\Widget;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Repository\WidgetRepository;
|
||||
use App\Security\CurrentUser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
@@ -22,8 +22,9 @@ class WidgetRepositoryTest extends TestCase
|
||||
public function testHasWidget()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => []]);
|
||||
|
||||
$this->assertFalse($sut->has('foo'));
|
||||
$this->assertTrue($sut->has('test'));
|
||||
@@ -31,14 +32,41 @@ class WidgetRepositoryTest extends TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Cannot find widget: foo
|
||||
* @expectedExceptionMessage Cannot find widget "foo".
|
||||
*/
|
||||
public function testGetWidgetThrowsExceptionOnNonExistingWidget()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => []]);
|
||||
$sut->get('foo', null);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => []]);
|
||||
$sut->get('foo');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \App\Widget\WidgetException
|
||||
* @expectedExceptionMessage Unknown widget type "\App\Widget\Type\FooBar"
|
||||
*/
|
||||
public function testGetWidgetThrowsExceptionOnInvalidType()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => ['type' => 'FooBar', 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \App\Widget\WidgetException
|
||||
* @expectedExceptionMessage Invalid widget type "\App\Widget\Type\CompoundChart" does not extend AbstractWidgetType
|
||||
*/
|
||||
public function testGetWidgetTriggersExceptionOnWrongClass()
|
||||
{
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => ['type' => 'CompoundChart', 'user' => false]]);
|
||||
$sut->get('test');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,6 +77,8 @@ class WidgetRepositoryTest extends TestCase
|
||||
$repoMock = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$repoMock->method('getStatistic')->willReturn($data);
|
||||
|
||||
$userMock = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$widget = [
|
||||
'color' => 'sunny',
|
||||
'icon' => 'far fa-test',
|
||||
@@ -59,24 +89,25 @@ class WidgetRepositoryTest extends TestCase
|
||||
'title' => 'Test widget',
|
||||
];
|
||||
|
||||
$sut = new WidgetRepository($repoMock, ['test' => $widget]);
|
||||
$widget = $sut->get('test', null);
|
||||
$sut = new WidgetRepository($repoMock, $userMock, ['test' => $widget]);
|
||||
$widget = $sut->get('test');
|
||||
|
||||
$options = $widget->getOptions();
|
||||
$this->assertEquals('Test widget', $widget->getTitle());
|
||||
$this->assertEquals($data, $widget->getData());
|
||||
$this->assertEquals('sunny', $widget->getColor());
|
||||
$this->assertEquals('far fa-test', $widget->getIcon());
|
||||
$this->assertEquals($dataType, $widget->getDataType());
|
||||
$this->assertEquals('sunny', $options['color']);
|
||||
$this->assertEquals('far fa-test', $options['icon']);
|
||||
$this->assertEquals($dataType, $options['dataType']);
|
||||
}
|
||||
|
||||
public function getWidgetData()
|
||||
{
|
||||
return [
|
||||
[12, TimesheetRepository::STATS_QUERY_DURATION, Widget::DATA_TYPE_DURATION],
|
||||
[112233, TimesheetRepository::STATS_QUERY_AMOUNT, Widget::DATA_TYPE_INT],
|
||||
[37, TimesheetRepository::STATS_QUERY_ACTIVE, Widget::DATA_TYPE_INT],
|
||||
[375, TimesheetRepository::STATS_QUERY_RATE, Widget::DATA_TYPE_MONEY],
|
||||
[['test' => 'foo'], TimesheetRepository::STATS_QUERY_USER, Widget::DATA_TYPE_INT],
|
||||
[12, TimesheetRepository::STATS_QUERY_DURATION, 'duration'],
|
||||
[112233, TimesheetRepository::STATS_QUERY_AMOUNT, 'int'],
|
||||
[37, TimesheetRepository::STATS_QUERY_ACTIVE, 'int'],
|
||||
[375, TimesheetRepository::STATS_QUERY_RATE, 'money'],
|
||||
[['test' => 'foo'], TimesheetRepository::STATS_QUERY_USER, 'int'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
107
tests/Twig/WidgetExtensionTest.php
Normal file
107
tests/Twig/WidgetExtensionTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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\Twig;
|
||||
|
||||
use App\Twig\WidgetExtension;
|
||||
use App\Widget\Type\Counter;
|
||||
use App\Widget\WidgetInterface;
|
||||
use App\Widget\WidgetRendererInterface;
|
||||
use App\Widget\WidgetService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
/**
|
||||
* @covers \App\Twig\WidgetExtension
|
||||
*/
|
||||
class WidgetExtensionTest extends TestCase
|
||||
{
|
||||
protected function getSut($hasWidget = null, $getWidget = null, $renderer = null): WidgetExtension
|
||||
{
|
||||
$service = $this->getMockBuilder(WidgetService::class)->disableOriginalConstructor()->setMethods(['hasWidget', 'getWidget', 'findRenderer'])->getMock();
|
||||
if (null !== $hasWidget) {
|
||||
$service->expects($this->once())->method('hasWidget')->willReturn($hasWidget);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
public function testGetFunctions()
|
||||
{
|
||||
$functions = ['render_widget'];
|
||||
$sut = $this->getSut();
|
||||
$twigFunctions = $sut->getFunctions();
|
||||
$this->assertCount(count($functions), $twigFunctions);
|
||||
$i = 0;
|
||||
/** @var TwigFunction $function */
|
||||
foreach ($twigFunctions as $function) {
|
||||
$this->assertInstanceOf(TwigFunction::class, $function);
|
||||
$this->assertEquals($functions[$i++], $function->getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Widget must either implement WidgetInterface or be a string
|
||||
*/
|
||||
public function testRenderWidgetForInvalidValue()
|
||||
{
|
||||
$sut = $this->getSut();
|
||||
$sut->renderWidget(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Unknown widget "test" requested
|
||||
*/
|
||||
public function testRenderWidgetForUnknownWidget()
|
||||
{
|
||||
$sut = $this->getSut(false);
|
||||
$sut->renderWidget('test');
|
||||
}
|
||||
|
||||
public function testRenderWidgetByString()
|
||||
{
|
||||
$widget = new Counter();
|
||||
$sut = $this->getSut(true, $widget, new TestRenderer());
|
||||
$options = ['foo' => 'bar', 'dataType' => 'blub'];
|
||||
$result = $sut->renderWidget('test', $options);
|
||||
$data = json_decode($result, true);
|
||||
$this->assertEquals($options, $data);
|
||||
}
|
||||
|
||||
public function testRenderWidgetObject()
|
||||
{
|
||||
$widget = new Counter();
|
||||
$sut = $this->getSut(null, null, new TestRenderer());
|
||||
$options = ['foo' => 'bar', 'dataType' => 'blub'];
|
||||
$result = $sut->renderWidget($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));
|
||||
}
|
||||
}
|
||||
54
tests/Widget/Renderer/CompoundChartRendererTest.php
Normal file
54
tests/Widget/Renderer/CompoundChartRendererTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Widget\Renderer;
|
||||
|
||||
use App\Widget\Renderer\CompoundChartRenderer;
|
||||
use App\Widget\Type\CompoundChart;
|
||||
use App\Widget\Type\CompoundRow;
|
||||
use App\Widget\Type\Counter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Renderer\CompoundChartRenderer
|
||||
* @covers \App\Widget\Renderer\AbstractTwigRenderer
|
||||
*/
|
||||
class CompoundChartRendererTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
|
||||
$sut = new CompoundChartRenderer($twig);
|
||||
self::assertTrue($sut->supports(new CompoundChart()));
|
||||
self::assertFalse($sut->supports(new CompoundRow()));
|
||||
}
|
||||
|
||||
public function testRenderWithCounter()
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->setMethods(['render'])->getMock();
|
||||
$twig->expects($this->once())->method('render')->willReturnCallback(function ($name, $options) {
|
||||
return json_encode([$name, $options]);
|
||||
});
|
||||
|
||||
$sut = new CompoundChartRenderer($twig);
|
||||
$row = new CompoundChart();
|
||||
$row->setTitle('foo-bar');
|
||||
$row->addWidget(new Counter());
|
||||
|
||||
$result = $sut->render($row);
|
||||
$result = json_decode($result, true);
|
||||
self::assertEquals('widget/section-chart.html.twig', $result[0]);
|
||||
self::assertArrayHasKey('title', $result[1]);
|
||||
self::assertEquals('foo-bar', $result[1]['title']);
|
||||
self::assertArrayHasKey('widgets', $result[1]);
|
||||
self::assertIsArray($result[1]['widgets']);
|
||||
self::assertCount(1, $result[1]['widgets']);
|
||||
}
|
||||
}
|
||||
54
tests/Widget/Renderer/CompoundRowRendererTest.php
Normal file
54
tests/Widget/Renderer/CompoundRowRendererTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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\Widget\Renderer;
|
||||
|
||||
use App\Widget\Renderer\CompoundRowRenderer;
|
||||
use App\Widget\Type\CompoundChart;
|
||||
use App\Widget\Type\CompoundRow;
|
||||
use App\Widget\Type\Counter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Renderer\CompoundRowRenderer
|
||||
* @covers \App\Widget\Renderer\AbstractTwigRenderer
|
||||
*/
|
||||
class CompoundRowRendererTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
|
||||
$sut = new CompoundRowRenderer($twig);
|
||||
self::assertTrue($sut->supports(new CompoundRow()));
|
||||
self::assertFalse($sut->supports(new CompoundChart()));
|
||||
}
|
||||
|
||||
public function testRenderWithCounter()
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->setMethods(['render'])->getMock();
|
||||
$twig->expects($this->once())->method('render')->willReturnCallback(function ($name, $options) {
|
||||
return json_encode([$name, $options]);
|
||||
});
|
||||
|
||||
$sut = new CompoundRowRenderer($twig);
|
||||
$row = new CompoundRow();
|
||||
$row->setTitle('foo-bar');
|
||||
$row->addWidget(new Counter());
|
||||
|
||||
$result = $sut->render($row);
|
||||
$result = json_decode($result, true);
|
||||
self::assertEquals('widget/section-simple.html.twig', $result[0]);
|
||||
self::assertArrayHasKey('title', $result[1]);
|
||||
self::assertEquals('foo-bar', $result[1]['title']);
|
||||
self::assertArrayHasKey('widgets', $result[1]);
|
||||
self::assertIsArray($result[1]['widgets']);
|
||||
self::assertCount(1, $result[1]['widgets']);
|
||||
}
|
||||
}
|
||||
67
tests/Widget/Renderer/SimpleWidgetRendererTest.php
Normal file
67
tests/Widget/Renderer/SimpleWidgetRendererTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\Widget\Renderer;
|
||||
|
||||
use App\Widget\Renderer\SimpleWidgetRenderer;
|
||||
use App\Widget\Type\Counter;
|
||||
use App\Widget\Type\More;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Renderer\SimpleWidgetRenderer
|
||||
* @covers \App\Widget\Renderer\AbstractTwigRenderer
|
||||
*/
|
||||
class SimpleWidgetRendererTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->getMock();
|
||||
$sut = new SimpleWidgetRenderer($twig);
|
||||
self::assertTrue($sut->supports(new SimpleWidget()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getSimpleWidgetsData
|
||||
*/
|
||||
public function testRenderWithCounter(SimpleWidget $widget, $template, $color)
|
||||
{
|
||||
$twig = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->setMethods(['render'])->getMock();
|
||||
$twig->expects($this->once())->method('render')->willReturnCallback(function ($name, $options) {
|
||||
return json_encode([$name, $options]);
|
||||
});
|
||||
|
||||
$sut = new SimpleWidgetRenderer($twig);
|
||||
|
||||
$data = uniqid(get_class($widget));
|
||||
$widget->setData($data);
|
||||
$result = $sut->render($widget, ['color' => $color]);
|
||||
$result = json_decode($result, true);
|
||||
|
||||
self::assertEquals($template, $result[0]);
|
||||
self::assertArrayHasKey('data', $result[1]);
|
||||
self::assertEquals($data, $result[1]['data']);
|
||||
self::assertArrayHasKey('title', $result[1]);
|
||||
self::assertArrayHasKey('options', $result[1]);
|
||||
self::assertIsArray($result[1]['options']);
|
||||
self::assertArrayHasKey('color', $result[1]['options']);
|
||||
self::assertEquals($color, $result[1]['options']['color']);
|
||||
}
|
||||
|
||||
public function getSimpleWidgetsData()
|
||||
{
|
||||
return [
|
||||
[new SimpleWidget(), 'widget/widget-simplewidget.html.twig', 'yellow'],
|
||||
[new Counter(), 'widget/widget-counter.html.twig', 'asdfgh'],
|
||||
[new More(), 'widget/widget-more.html.twig', '#123456'],
|
||||
];
|
||||
}
|
||||
}
|
||||
67
tests/Widget/Type/AbstractContainerTest.php
Normal file
67
tests/Widget/Type/AbstractContainerTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractContainer;
|
||||
use App\Widget\Type\More;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\AbstractContainer
|
||||
*/
|
||||
abstract class AbstractContainerTest extends TestCase
|
||||
{
|
||||
abstract public function createSut(): AbstractContainer;
|
||||
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertInstanceOf(AbstractContainer::class, $sut);
|
||||
|
||||
self::assertEquals('', $sut->getId());
|
||||
self::assertEquals('', $sut->getTitle());
|
||||
|
||||
self::assertEquals(0, $sut->getOrder());
|
||||
self::assertEquals([], $sut->getOptions());
|
||||
self::assertEquals([], $sut->getWidgets());
|
||||
self::assertEquals([], $sut->getData());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$widget = (new More())->setTitle('bar')->setId('foo');
|
||||
|
||||
$sut = $this->createSut();
|
||||
$sut->setTitle('hello-world');
|
||||
$sut->setOrder(13);
|
||||
$sut->addWidget($widget);
|
||||
|
||||
self::assertEquals('hello-world', $sut->getTitle());
|
||||
self::assertEquals('hello-world', $sut->getId());
|
||||
|
||||
self::assertCount(1, $sut->getWidgets());
|
||||
self::assertCount(1, $sut->getData());
|
||||
self::assertEquals([$widget], $sut->getWidgets());
|
||||
self::assertEquals([$widget], $sut->getData());
|
||||
|
||||
self::assertEquals(13, $sut->getOrder());
|
||||
self::assertEquals('bar', $sut->getWidgets()[0]->getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testSetOptionNotImplemented()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
$sut->setOption('dfsdf', []);
|
||||
}
|
||||
}
|
||||
69
tests/Widget/Type/AbstractWidgetTypeTest.php
Normal file
69
tests/Widget/Type/AbstractWidgetTypeTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\AbstractWidgetType
|
||||
*/
|
||||
abstract class AbstractWidgetTypeTest extends TestCase
|
||||
{
|
||||
abstract public function createSut(): AbstractWidgetType;
|
||||
|
||||
abstract public function getDefaultOptions(): array;
|
||||
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut);
|
||||
self::assertEquals('', $sut->getId());
|
||||
self::assertEquals('', $sut->getTitle());
|
||||
self::assertEquals($this->getDefaultOptions(), $sut->getOptions());
|
||||
self::assertNull($sut->getData());
|
||||
self::assertEquals('bar', $sut->getOption('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testFluentInterface()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setOptions([]));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setId(''));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setTitle(''));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setData(''));
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
// options
|
||||
$sut->setOption('föööö', 'trääääää');
|
||||
self::assertEquals('trääääää', $sut->getOption('föööö', 'tröööö'));
|
||||
self::assertEquals('trääääää', $sut->getOption('föööö', 'tröööö'));
|
||||
self::assertEquals(array_merge($this->getDefaultOptions(), ['föööö' => 'trääääää']), $sut->getOptions());
|
||||
|
||||
$sut->setOptions(['blub' => 'blab', 'dataType' => 'money']);
|
||||
self::assertEquals(['blub' => 'blab', 'dataType' => 'money', 'föööö' => 'trääääää'], $sut->getOptions());
|
||||
|
||||
// id
|
||||
$sut->setId('cvbnmyx');
|
||||
self::assertEquals('cvbnmyx', $sut->getId());
|
||||
|
||||
// data
|
||||
$sut->setData('slkudfhalksjdhfkljsahdf');
|
||||
self::assertEquals('slkudfhalksjdhfkljsahdf', $sut->getData());
|
||||
|
||||
$data = new \stdClass();
|
||||
$sut->setData($data);
|
||||
self::assertSame($data, $sut->getData());
|
||||
}
|
||||
}
|
||||
25
tests/Widget/Type/CompoundChartTest.php
Normal file
25
tests/Widget/Type/CompoundChartTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractContainer;
|
||||
use App\Widget\Type\CompoundChart;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\CompoundChart
|
||||
* @covers \App\Widget\Type\AbstractContainer
|
||||
*/
|
||||
class CompoundChartTest extends AbstractContainerTest
|
||||
{
|
||||
public function createSut(): AbstractContainer
|
||||
{
|
||||
return new CompoundChart();
|
||||
}
|
||||
}
|
||||
25
tests/Widget/Type/CompoundRowTest.php
Normal file
25
tests/Widget/Type/CompoundRowTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractContainer;
|
||||
use App\Widget\Type\CompoundRow;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\CompoundRow
|
||||
* @covers \App\Widget\Type\AbstractContainer
|
||||
*/
|
||||
class CompoundRowTest extends AbstractContainerTest
|
||||
{
|
||||
public function createSut(): AbstractContainer
|
||||
{
|
||||
return new CompoundRow();
|
||||
}
|
||||
}
|
||||
36
tests/Widget/Type/CounterTest.php
Normal file
36
tests/Widget/Type/CounterTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\Counter;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\Counter
|
||||
*/
|
||||
class CounterTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
return new Counter();
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return ['dataType' => 'int'];
|
||||
}
|
||||
|
||||
public function testExtendsSimpleWidget()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleWidget::class, $sut);
|
||||
}
|
||||
}
|
||||
117
tests/Widget/Type/DailyWorkingTimeChartTest.php
Normal file
117
tests/Widget/Type/DailyWorkingTimeChartTest.php
Normal file
@@ -0,0 +1,117 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Model\Statistic\Day;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Security\CurrentUser;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\DailyWorkingTimeChart;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\DailyWorkingTimeChart
|
||||
* @covers \App\Widget\Type\SimpleWidget
|
||||
* @covers \App\Widget\Type\AbstractWidgetType
|
||||
* @covers \App\Repository\TimesheetRepository
|
||||
*/
|
||||
class DailyWorkingTimeChartTest extends TestCase
|
||||
{
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
$user = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->setMethods(['getUser'])->getMock();
|
||||
$user->expects($this->once())->method('getUser')->willReturn(new User());
|
||||
|
||||
return new DailyWorkingTimeChart($repository, $user);
|
||||
}
|
||||
|
||||
public function testExtendsSimpleWidget()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleWidget::class, $sut);
|
||||
}
|
||||
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut);
|
||||
self::assertEquals('DailyWorkingTimeChart', $sut->getId());
|
||||
self::assertEquals('stats.yourWorkingHours', $sut->getTitle());
|
||||
self::assertEquals('monday this week 00:00:00', $sut->getOption('begin', 'xxx'));
|
||||
self::assertEquals('sunday this week 23:59:59', $sut->getOption('end', 'xxx'));
|
||||
self::assertEquals('', $sut->getOption('color', 'xxx'));
|
||||
self::assertInstanceOf(User::class, $sut->getOption('user', 'xxx'));
|
||||
self::assertEquals('bar', $sut->getOption('type', 'xxx'));
|
||||
}
|
||||
|
||||
public function testFluentInterface()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setOptions([]));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setId(''));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setTitle(''));
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut->setData(''));
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
// options
|
||||
$sut->setOption('föööö', 'trääääää');
|
||||
self::assertEquals('trääääää', $sut->getOption('föööö', 'tröööö'));
|
||||
|
||||
// check default values
|
||||
self::assertEquals('xxxxx', $sut->getOption('blub', 'xxxxx'));
|
||||
self::assertEquals('xxxxx', $sut->getOption('dataType', 'xxxxx'));
|
||||
|
||||
$sut->setOptions(['blub' => 'blab', 'dataType' => 'money']);
|
||||
// check option still exists
|
||||
self::assertEquals('trääääää', $sut->getOption('föööö', 'tröööö'));
|
||||
// check options are now existing
|
||||
self::assertEquals('blab', $sut->getOption('blub', 'xxxxx'));
|
||||
self::assertEquals('money', $sut->getOption('dataType', 'xxxxx'));
|
||||
|
||||
// id
|
||||
$sut->setId('cvbnmyx');
|
||||
self::assertEquals('cvbnmyx', $sut->getId());
|
||||
}
|
||||
|
||||
public function testGetOptions()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
$options = $sut->getOptions(['type' => 'xxx']);
|
||||
self::assertStringStartsWith('DailyWorkingTimeChart_', $options['id']);
|
||||
self::assertEquals('bar', $options['type']);
|
||||
}
|
||||
|
||||
public function testGetData()
|
||||
{
|
||||
$repository = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->setMethods(['getDailyData'])->getMock();
|
||||
$repository->expects($this->once())->method('getDailyData')->willReturnCallback(function ($user, $begin, $end) {
|
||||
return [
|
||||
['year' => '2019', 'month' => '1', 'day' => 1, 'rate' => 13.75, 'duration' => 1234]
|
||||
];
|
||||
});
|
||||
$user = $this->getMockBuilder(CurrentUser::class)->disableOriginalConstructor()->setMethods(['getUser'])->getMock();
|
||||
$user->expects($this->once())->method('getUser')->willReturn((new User())->setUsername('tralalala'));
|
||||
|
||||
$sut = new DailyWorkingTimeChart($repository, $user);
|
||||
$data = $sut->getData([]);
|
||||
self::assertCount(7, $data);
|
||||
foreach ($data as $statObj) {
|
||||
self::assertInstanceOf(Day::class, $statObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
36
tests/Widget/Type/MoreTest.php
Normal file
36
tests/Widget/Type/MoreTest.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\More;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\More
|
||||
*/
|
||||
class MoreTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
return new More();
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return ['dataType' => 'int'];
|
||||
}
|
||||
|
||||
public function testExtendsSimpleWidget()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleWidget::class, $sut);
|
||||
}
|
||||
}
|
||||
29
tests/Widget/Type/SimpleWidgetTest.php
Normal file
29
tests/Widget/Type/SimpleWidgetTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\SimpleWidget
|
||||
*/
|
||||
class SimpleWidgetTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
return new SimpleWidget();
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
29
tests/Widget/Type/YearChartTest.php
Normal file
29
tests/Widget/Type/YearChartTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Widget\Type;
|
||||
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\YearChart;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\YearChart
|
||||
*/
|
||||
class YearChartTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
return new YearChart();
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
25
tests/Widget/WidgetExceptionTest.php
Normal file
25
tests/Widget/WidgetExceptionTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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\Widget;
|
||||
|
||||
use App\Widget\WidgetException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\WidgetException
|
||||
*/
|
||||
class WidgetExceptionTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$ex = new WidgetException();
|
||||
self::assertInstanceOf(\Exception::class, $ex);
|
||||
}
|
||||
}
|
||||
77
tests/Widget/WidgetServiceTest.php
Normal file
77
tests/Widget/WidgetServiceTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\Widget;
|
||||
|
||||
use App\Repository\WidgetRepository;
|
||||
use App\Widget\Renderer\SimpleWidgetRenderer;
|
||||
use App\Widget\Type\More;
|
||||
use App\Widget\WidgetService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Twig\Environment;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\WidgetService
|
||||
*/
|
||||
class WidgetServiceTest extends TestCase
|
||||
{
|
||||
public function testConstruct()
|
||||
{
|
||||
$repository = $this->getMockBuilder(WidgetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetService($repository, []);
|
||||
self::assertFalse($sut->hasWidget('sdfsdf'));
|
||||
self::assertCount(0, $sut->getRenderer());
|
||||
|
||||
$sut = new WidgetService($repository, [
|
||||
new SimpleWidgetRenderer(new Environment(new FilesystemLoader()))
|
||||
]);
|
||||
self::assertCount(1, $sut->getRenderer());
|
||||
}
|
||||
|
||||
public function testFindRenderer()
|
||||
{
|
||||
$repository = $this->getMockBuilder(WidgetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$renderer = new SimpleWidgetRenderer(new Environment(new FilesystemLoader()));
|
||||
$sut = new WidgetService($repository, [$renderer]);
|
||||
$sut->addRenderer(new SimpleWidgetRenderer(new Environment(new FilesystemLoader())));
|
||||
|
||||
self::assertCount(2, $sut->getRenderer());
|
||||
|
||||
$found = $sut->findRenderer(new More());
|
||||
self::assertSame($renderer, $found);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \App\Widget\WidgetException
|
||||
* @expectedExceptionMessage No renderer available for widget "App\Widget\Type\More"
|
||||
*/
|
||||
public function testFindRendererThrowsException()
|
||||
{
|
||||
$repository = $this->getMockBuilder(WidgetRepository::class)->disableOriginalConstructor()->getMock();
|
||||
|
||||
$sut = new WidgetService($repository, []);
|
||||
$sut->findRenderer(new More());
|
||||
}
|
||||
|
||||
public function testHasAndGetWidget()
|
||||
{
|
||||
$widget = new More();
|
||||
|
||||
$repository = $this->getMockBuilder(WidgetRepository::class)->disableOriginalConstructor()->setMethods(['has', 'get'])->getMock();
|
||||
$repository->expects($this->once())->method('has')->willReturn(true);
|
||||
$repository->expects($this->once())->method('get')->willReturn($widget);
|
||||
|
||||
$sut = new WidgetService($repository, []);
|
||||
self::assertTrue($sut->hasWidget('sdfsdf'));
|
||||
self::assertSame($widget, $sut->getWidget('sdfsdf'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user