financial year setting + new users working time per year report (#2547)
This commit is contained in:
@@ -157,10 +157,12 @@ class SystemConfigurationTest extends TestCase
|
||||
(new Configuration())->setName('timesheet.rules.allow_future_times')->setValue(''),
|
||||
(new Configuration())->setName('saml.activate')->setValue(true),
|
||||
(new Configuration())->setName('theme.color_choices')->setValue(''),
|
||||
(new Configuration())->setName('company.financial_year')->setValue('2020-03-27'),
|
||||
]);
|
||||
$this->assertFalse($sut->find('timesheet.rules.allow_future_times'));
|
||||
$this->assertTrue($sut->isSamlActive());
|
||||
$this->assertNull($sut->getThemeColorChoices());
|
||||
$this->assertEquals('2020-03-27', $sut->getFinancialYearStart());
|
||||
}
|
||||
|
||||
public function testUnknownConfigs()
|
||||
@@ -209,6 +211,7 @@ class SystemConfigurationTest extends TestCase
|
||||
$this->assertEquals('blue', $sut->getUserDefaultTheme());
|
||||
$this->assertEquals('IT', $sut->getUserDefaultLanguage());
|
||||
$this->assertEquals('USD', $sut->getUserDefaultCurrency());
|
||||
$this->assertNull($sut->getFinancialYearStart());
|
||||
}
|
||||
|
||||
public function testFormDefaultWithLoader()
|
||||
|
||||
@@ -35,7 +35,7 @@ class PermissionControllerTest extends ControllerBaseTest
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_SUPER_ADMIN);
|
||||
$this->assertAccessIsGranted($client, '/admin/permissions');
|
||||
$this->assertHasDataTable($client);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 118);
|
||||
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 119);
|
||||
$this->assertPageActions($client, [
|
||||
//'back' => $this->createUrl('/admin/user/'),
|
||||
'create modal-ajax-form' => $this->createUrl('/admin/permissions/roles/create'),
|
||||
|
||||
@@ -34,9 +34,13 @@ class ProfileControllerTest extends ControllerBaseTest
|
||||
$this->request($client, '/profile/' . UserFixtures::USERNAME_USER);
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertHasNoEntriesWithFilter($client);
|
||||
$this->assertHasProfileBox($client, 'John Doe');
|
||||
$this->assertHasAboutMeBox($client, UserFixtures::USERNAME_USER);
|
||||
|
||||
$content = $client->getResponse()->getContent();
|
||||
$year = (new \DateTime())->format('Y');
|
||||
$this->assertStringContainsString('<h3 class="box-title">' . $year . '</h3>', $content);
|
||||
$this->assertStringContainsString('var userProfileChart' . $year . ' = new Chart(', $content);
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
|
||||
@@ -28,6 +28,11 @@ class ReportUsersListControllerTest extends ControllerBaseTest
|
||||
$this->importFixture($fixture);
|
||||
}
|
||||
|
||||
public function testYearlyListIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/yearly_users_list');
|
||||
}
|
||||
|
||||
public function testWeeklyListIsSecure()
|
||||
{
|
||||
$this->assertUrlIsSecured('/reporting/weekly_users_list');
|
||||
@@ -38,6 +43,11 @@ class ReportUsersListControllerTest extends ControllerBaseTest
|
||||
$this->assertUrlIsSecured('/reporting/monthly_users_list');
|
||||
}
|
||||
|
||||
public function testYearlyUsersListIsSecureForUserRole()
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/yearly_users_list');
|
||||
}
|
||||
|
||||
public function testWeeklyUsersListIsSecureForUserRole()
|
||||
{
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/weekly_users_list');
|
||||
@@ -48,6 +58,16 @@ class ReportUsersListControllerTest extends ControllerBaseTest
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/monthly_users_list');
|
||||
}
|
||||
|
||||
public function testYearlyUsersReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$this->importReportingFixture(User::ROLE_TEAMLEAD);
|
||||
$this->assertAccessIsGranted($client, '/reporting/yearly_users_list');
|
||||
self::assertStringContainsString('<div class="box-body yearly-user-list-reporting-box', $client->getResponse()->getContent());
|
||||
$select = $client->getCrawler()->filterXPath("//select[@id='user']");
|
||||
self::assertEquals(0, $select->count());
|
||||
}
|
||||
|
||||
public function testWeeklyUsersReport()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
|
||||
@@ -428,6 +428,9 @@ class ConfigurationTest extends TestCase
|
||||
'connection' => [
|
||||
'organization' => []
|
||||
],
|
||||
],
|
||||
'company' => [
|
||||
'financial_year' => null,
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -29,32 +28,61 @@ class MonthTest extends TestCase
|
||||
self::assertSame(0.0, $sut->getBillableRate());
|
||||
}
|
||||
|
||||
public function testAllowedMonths()
|
||||
public function getTestData()
|
||||
{
|
||||
for ($i = 1; $i < 10; $i++) {
|
||||
new Month('0' . $i);
|
||||
}
|
||||
for ($i = 10; $i < 13; $i++) {
|
||||
new Month((string) $i);
|
||||
}
|
||||
self::assertTrue(true);
|
||||
yield ['01', '01', 1];
|
||||
yield ['02', '02', 2];
|
||||
yield ['03', '03', 3];
|
||||
yield ['04', '04', 4];
|
||||
yield ['05', '05', 5];
|
||||
yield ['06', '06', 6];
|
||||
yield ['07', '07', 7];
|
||||
yield ['08', '08', 8];
|
||||
yield ['09', '09', 9];
|
||||
yield ['10', '10', 10];
|
||||
yield ['11', '11', 11];
|
||||
yield ['12', '12', 12];
|
||||
yield [1, '01', 1];
|
||||
yield [2, '02', 2];
|
||||
yield [3, '03', 3];
|
||||
yield [4, '04', 4];
|
||||
yield [5, '05', 5];
|
||||
yield [6, '06', 6];
|
||||
yield [7, '07', 7];
|
||||
yield [8, '08', 8];
|
||||
yield [9, '09', 9];
|
||||
yield [10, '10', 10];
|
||||
yield [11, '11', 11];
|
||||
yield [12, '12', 12];
|
||||
}
|
||||
|
||||
public function testInvalidMonths()
|
||||
/**
|
||||
* @dataProvider getTestData
|
||||
*/
|
||||
public function testAllowedMonths($init, $month, $number)
|
||||
{
|
||||
foreach (['00', '13', '99', '0.9'] as $month) {
|
||||
$ex = null;
|
||||
try {
|
||||
new Month($month);
|
||||
} catch (Exception $e) {
|
||||
$ex = $e;
|
||||
}
|
||||
self::assertInstanceOf(InvalidArgumentException::class, $ex);
|
||||
self::assertEquals(
|
||||
'Invalid month given. Expected 1-12, received "' . ((int) $month) . '".',
|
||||
$ex->getMessage()
|
||||
);
|
||||
}
|
||||
$sut = new Month($init);
|
||||
self::assertEquals($month, $sut->getMonth());
|
||||
self::assertEquals($number, $sut->getMonthNumber());
|
||||
}
|
||||
|
||||
public function getInvalidTestData()
|
||||
{
|
||||
yield ['00'];
|
||||
yield ['13'];
|
||||
yield ['99'];
|
||||
yield ['0.9'];
|
||||
yield [19];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidTestData
|
||||
*/
|
||||
public function testInvalidMonths($month)
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Invalid month given. Expected 1-12, received "' . ((int) $month) . '".');
|
||||
new Month($month);
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
|
||||
@@ -47,6 +47,6 @@ class ReportingServiceTest extends TestCase
|
||||
$sut = $this->getSut(true);
|
||||
$reports = $sut->getAvailableReports(new User());
|
||||
self::assertIsArray($reports);
|
||||
self::assertCount(6, $reports);
|
||||
self::assertCount(7, $reports);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,4 +169,44 @@ class DateTimeFactoryTest extends TestCase
|
||||
// poor test, but there shouldn't be more than 2 seconds between the creation of two DateTime objects
|
||||
$this->assertTrue(2 >= $difference);
|
||||
}
|
||||
|
||||
public function testCreateStartOfFinancialYearWithoutConfig()
|
||||
{
|
||||
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
||||
$dateTime = $sut->createStartOfFinancialYear();
|
||||
$expected = $sut->createDateTime('01 january this year 00:00:00');
|
||||
self::assertInstanceOf(DateTime::class, $dateTime);
|
||||
self::assertEquals($expected, $dateTime);
|
||||
}
|
||||
|
||||
public function testCreateStartOfFinancialYearWithConfig()
|
||||
{
|
||||
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
||||
|
||||
$future = $sut->createDateTime('+10 days');
|
||||
$past = $sut->createDateTime('-10 days');
|
||||
|
||||
$financial = $sut->createStartOfFinancialYear($future->format('Y-m-d'));
|
||||
|
||||
$future->modify('-1 year');
|
||||
$future->setTime(0, 0, 0);
|
||||
|
||||
self::assertEquals($future, $financial);
|
||||
|
||||
$financial = $sut->createStartOfFinancialYear($past->format('Y-m-d'));
|
||||
|
||||
$past->setTime(0, 0, 0);
|
||||
self::assertEquals($past, $financial);
|
||||
}
|
||||
|
||||
public function testCreateEndOfFinancialYearWithConfig()
|
||||
{
|
||||
$sut = $this->createDateTimeFactory(self::TEST_TIMEZONE);
|
||||
|
||||
$expected = $sut->createDateTime('2021-07-22 23:59:59 ');
|
||||
$financial = $sut->createStartOfFinancialYear('2020-07-23 15:30:00');
|
||||
$end = $sut->createEndOfFinancialYear($financial);
|
||||
|
||||
self::assertEquals($expected, $end);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,6 @@ abstract class AbstractWidgetTypeTest extends TestCase
|
||||
{
|
||||
$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'));
|
||||
@@ -51,7 +49,10 @@ abstract class AbstractWidgetTypeTest extends TestCase
|
||||
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());
|
||||
$options = $sut->getOptions();
|
||||
self::assertEquals('blab', $options['blub']);
|
||||
self::assertEquals('money', $options['dataType']);
|
||||
self::assertEquals('trääääää', $options['föööö']);
|
||||
|
||||
// id
|
||||
$sut->setId('cvbnmyx');
|
||||
|
||||
62
tests/Widget/Type/ActiveUsersYearTest.php
Normal file
62
tests/Widget/Type/ActiveUsersYearTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\ActiveUsersYear;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\SimpleStatisticChart;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\ActiveUsersYear
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
*/
|
||||
class ActiveUsersYearTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
/**
|
||||
* @return CounterYear
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
return new ActiveUsersYear($repository, $configuration);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'dataType' => 'int',
|
||||
'icon' => 'user',
|
||||
'color' => 'yellow',
|
||||
];
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
|
||||
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
|
||||
$sut->setData(10);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
self::assertEquals('activeUsersYear', $sut->getId());
|
||||
}
|
||||
}
|
||||
62
tests/Widget/Type/AmountYearTest.php
Normal file
62
tests/Widget/Type/AmountYearTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\AmountYear;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\SimpleStatisticChart;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\AmountYear
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
*/
|
||||
class AmountYearTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
/**
|
||||
* @return CounterYear
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
return new AmountYear($repository, $configuration);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'dataType' => 'money',
|
||||
'icon' => 'money',
|
||||
'color' => 'yellow',
|
||||
];
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
|
||||
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
|
||||
$sut->setData(10);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
self::assertEquals('amountYear', $sut->getId());
|
||||
}
|
||||
}
|
||||
101
tests/Widget/Type/CounterYearTest.php
Normal file
101
tests/Widget/Type/CounterYearTest.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Entity\User;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\Counter;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
* @covers \App\Widget\Type\SimpleStatisticChart
|
||||
* @covers \App\Widget\Type\SimpleWidget
|
||||
*/
|
||||
class CounterYearTest extends AbstractSimpleStatisticsWidgetTypeTest
|
||||
{
|
||||
public function createSut(?string $financialYear = null): AbstractWidgetType
|
||||
{
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
if (null !== $financialYear) {
|
||||
$configuration->method('getFinancialYearStart')->willReturn($financialYear);
|
||||
}
|
||||
|
||||
$sut = new CounterYear($this->createMock(TimesheetRepository::class), $configuration);
|
||||
$sut->setQuery(TimesheetRepository::STATS_QUERY_ACTIVE);
|
||||
|
||||
return $sut;
|
||||
}
|
||||
|
||||
public function testQueryWithUser()
|
||||
{
|
||||
$user = new User();
|
||||
$user->setAlias('foo');
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->expects($this->once())->method('getStatistic')->willReturnCallback(function (string $type, ?DateTime $begin, ?DateTime $end, ?User $user) {
|
||||
self::assertEquals($type, 'active');
|
||||
self::assertNull($begin);
|
||||
self::assertNull($end);
|
||||
self::assertNull($user);
|
||||
});
|
||||
$sut = new Counter($repository);
|
||||
$sut->setQuery(TimesheetRepository::STATS_QUERY_ACTIVE);
|
||||
$sut->setUser($user);
|
||||
$sut->getData([]);
|
||||
|
||||
$user = new User();
|
||||
$user->setAlias('bar');
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->expects($this->once())->method('getStatistic')->willReturnCallback(function (string $type, ?DateTime $begin, ?DateTime $end, ?User $user) {
|
||||
self::assertEquals($type, 'active');
|
||||
self::assertNull($begin);
|
||||
self::assertNull($end);
|
||||
self::assertNotNull($user);
|
||||
self::assertEquals('bar', $user->getAlias());
|
||||
});
|
||||
$sut = new Counter($repository);
|
||||
$sut->setQuery(TimesheetRepository::STATS_QUERY_ACTIVE);
|
||||
$sut->setUser($user);
|
||||
$sut->setQueryWithUser(true);
|
||||
$sut->getData([]);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return ['dataType' => 'int'];
|
||||
}
|
||||
|
||||
public function testExtendsSimpleWidget()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleWidget::class, $sut);
|
||||
}
|
||||
|
||||
public function testTemplateName()
|
||||
{
|
||||
/** @var Counter $sut */
|
||||
$sut = $this->createSut();
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
}
|
||||
|
||||
public function testTemplateNameWithFinancialYear()
|
||||
{
|
||||
/** @var Counter $sut */
|
||||
$sut = $this->createSut('2020-01-01');
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
}
|
||||
}
|
||||
62
tests/Widget/Type/DurationYearTest.php
Normal file
62
tests/Widget/Type/DurationYearTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\DurationYear;
|
||||
use App\Widget\Type\SimpleStatisticChart;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\DurationYear
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
*/
|
||||
class DurationYearTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
/**
|
||||
* @return CounterYear
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
return new DurationYear($repository, $configuration);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'dataType' => 'duration',
|
||||
'icon' => 'duration',
|
||||
'color' => 'yellow',
|
||||
];
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
|
||||
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
|
||||
$sut->setData(10);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
self::assertEquals('durationYear', $sut->getId());
|
||||
}
|
||||
}
|
||||
199
tests/Widget/Type/PaginatedWorkingTimeChartTest.php
Normal file
199
tests/Widget/Type/PaginatedWorkingTimeChartTest.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\PaginatedWorkingTimeChart;
|
||||
use App\Widget\Type\SimpleWidget;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\PaginatedWorkingTimeChart
|
||||
* @covers \App\Widget\Type\SimpleWidget
|
||||
* @covers \App\Widget\Type\AbstractWidgetType
|
||||
* @covers \App\Repository\TimesheetRepository
|
||||
*/
|
||||
class PaginatedWorkingTimeChartTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @return PaginatedWorkingTimeChart
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
$sut = new PaginatedWorkingTimeChart($repository, $configuration);
|
||||
$sut->setUser(new User());
|
||||
|
||||
return $sut;
|
||||
}
|
||||
|
||||
public function testExtendsSimpleWidget()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleWidget::class, $sut);
|
||||
}
|
||||
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(AbstractWidgetType::class, $sut);
|
||||
self::assertEquals('PaginatedWorkingTimeChart', $sut->getId());
|
||||
self::assertEquals('stats.yourWorkingHours', $sut->getTitle());
|
||||
//self::assertNull($sut->getOption('begin', 'xxx'));
|
||||
// self::assertNull($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::assertEquals('bar', $options['type']);
|
||||
}
|
||||
|
||||
public function testGetData()
|
||||
{
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(42);
|
||||
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(4711);
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->expects($this->once())->method('getDailyStats')->willReturnCallback(function ($user, $begin, $end) use ($activity, $project) {
|
||||
return [
|
||||
[
|
||||
'year' => $begin->format('Y'),
|
||||
'month' => $begin->format('n'),
|
||||
'day' => $begin->format('j'),
|
||||
'rate' => 13.75,
|
||||
'duration' => 1234,
|
||||
'billable' => 1234,
|
||||
'details' => [
|
||||
[
|
||||
'activity' => $activity,
|
||||
'project' => $project,
|
||||
'billable' => 1234,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
});
|
||||
|
||||
$expectedKeys = [
|
||||
'begin', 'end', 'stats', 'thisMonth', 'lastWeekInYear', 'lastWeekInLastYear', 'day', 'week', 'month', 'year', 'financial', 'financialBegin'
|
||||
];
|
||||
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
$configuration->expects($this->once())->method('getFinancialYearStart')->willReturn(null);
|
||||
|
||||
$sut = new PaginatedWorkingTimeChart($repository, $configuration);
|
||||
|
||||
$sut->setUser(new User());
|
||||
$data = $sut->getData([]);
|
||||
|
||||
self::assertCount(\count($expectedKeys), $data);
|
||||
foreach ($expectedKeys as $key) {
|
||||
self::assertArrayHasKey($key, $data);
|
||||
}
|
||||
self::assertNull($data['financialBegin']);
|
||||
}
|
||||
|
||||
public function testGetDataWithFinancialYear()
|
||||
{
|
||||
$activity = $this->createMock(Activity::class);
|
||||
$activity->method('getId')->willReturn(42);
|
||||
|
||||
$project = $this->createMock(Project::class);
|
||||
$project->method('getId')->willReturn(4711);
|
||||
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$repository->expects($this->once())->method('getDailyStats')->willReturnCallback(function ($user, $begin, $end) use ($activity, $project) {
|
||||
return [
|
||||
[
|
||||
'year' => $begin->format('Y'),
|
||||
'month' => $begin->format('n'),
|
||||
'day' => $begin->format('j'),
|
||||
'rate' => 13.75,
|
||||
'duration' => 1234,
|
||||
'billable' => 1234,
|
||||
'details' => [
|
||||
[
|
||||
'activity' => $activity,
|
||||
'project' => $project,
|
||||
'billable' => 1234,
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
});
|
||||
|
||||
$expectedKeys = [
|
||||
'begin', 'end', 'stats', 'thisMonth', 'lastWeekInYear', 'lastWeekInLastYear', 'day', 'week', 'month', 'year', 'financial', 'financialBegin'
|
||||
];
|
||||
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
$configuration->expects($this->once())->method('getFinancialYearStart')->willReturn('2020-01-01');
|
||||
|
||||
$sut = new PaginatedWorkingTimeChart($repository, $configuration);
|
||||
|
||||
$sut->setUser(new User());
|
||||
$data = $sut->getData([]);
|
||||
|
||||
self::assertCount(\count($expectedKeys), $data);
|
||||
foreach ($expectedKeys as $key) {
|
||||
self::assertArrayHasKey($key, $data);
|
||||
}
|
||||
self::assertInstanceOf(\DateTime::class, $data['financialBegin']);
|
||||
}
|
||||
}
|
||||
62
tests/Widget/Type/UserAmountYearTest.php
Normal file
62
tests/Widget/Type/UserAmountYearTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\SimpleStatisticChart;
|
||||
use App\Widget\Type\UserAmountYear;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\UserAmountYear
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
*/
|
||||
class UserAmountYearTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
/**
|
||||
* @return CounterYear
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
return new UserAmountYear($repository, $configuration);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'dataType' => 'money',
|
||||
'icon' => 'money',
|
||||
'color' => 'yellow',
|
||||
];
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
|
||||
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
|
||||
$sut->setData(10);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
self::assertEquals('userAmountYear', $sut->getId());
|
||||
}
|
||||
}
|
||||
62
tests/Widget/Type/UserDurationYearTest.php
Normal file
62
tests/Widget/Type/UserDurationYearTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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\Configuration\SystemConfiguration;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Widget\Type\AbstractWidgetType;
|
||||
use App\Widget\Type\CounterYear;
|
||||
use App\Widget\Type\SimpleStatisticChart;
|
||||
use App\Widget\Type\UserDurationYear;
|
||||
|
||||
/**
|
||||
* @covers \App\Widget\Type\UserDurationYear
|
||||
* @covers \App\Widget\Type\CounterYear
|
||||
*/
|
||||
class UserDurationYearTest extends AbstractWidgetTypeTest
|
||||
{
|
||||
/**
|
||||
* @return CounterYear
|
||||
*/
|
||||
public function createSut(): AbstractWidgetType
|
||||
{
|
||||
$repository = $this->createMock(TimesheetRepository::class);
|
||||
$configuration = $this->createMock(SystemConfiguration::class);
|
||||
|
||||
return new UserDurationYear($repository, $configuration);
|
||||
}
|
||||
|
||||
public function getDefaultOptions(): array
|
||||
{
|
||||
return [
|
||||
'dataType' => 'duration',
|
||||
'icon' => 'duration',
|
||||
'color' => 'yellow',
|
||||
];
|
||||
}
|
||||
|
||||
public function testData()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Cannot set data on instances of SimpleStatisticChart');
|
||||
|
||||
$sut = $this->createSut();
|
||||
self::assertInstanceOf(SimpleStatisticChart::class, $sut);
|
||||
$sut->setData(10);
|
||||
}
|
||||
|
||||
public function testSettings()
|
||||
{
|
||||
$sut = $this->createSut();
|
||||
|
||||
self::assertEquals('widget/widget-counter.html.twig', $sut->getTemplateName());
|
||||
self::assertEquals('userDurationYear', $sut->getId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user