users weekly stats as bar-chart in dashboard (#847)
This commit is contained in:
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