added reporting screen (#1805)

This commit is contained in:
Kevin Papst
2020-07-12 14:05:14 +02:00
committed by GitHub
parent b97d9f692d
commit 164af7ae02
44 changed files with 1294 additions and 79 deletions

View File

@@ -33,7 +33,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', 112);
$this->assertDataTableRowCount($client, 'datatable_user_admin_permissions', 113);
$this->assertPageActions($client, [
'back' => $this->createUrl('/admin/user/'),
'roles modal-ajax-form' => $this->createUrl('/admin/permissions/roles/create'),

View File

@@ -0,0 +1,47 @@
<?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\Controller;
use App\Entity\User;
/**
* @group integration
*/
class ReportingControllerTest extends ControllerBaseTest
{
public function testIsSecure()
{
$this->assertUrlIsSecured('/reporting');
}
public function testMonthlyListIsSecure()
{
$this->assertUrlIsSecured('/reporting/monthly_users_list');
}
public function testMonthlyUsersListIsSecureForUserRole()
{
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/reporting/monthly_users_list');
}
public function testDefaultUsersMonthReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_USER);
$this->assertAccessIsGranted($client, '/reporting/');
self::assertStringContainsString('<div class="box-body user-month-reporting-box', $client->getResponse()->getContent());
}
public function testMonthlyUsersReport()
{
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
$this->assertAccessIsGranted($client, '/reporting/monthly_users_list');
self::assertStringContainsString('<div class="box-body monthly-user-list-reporting-box', $client->getResponse()->getContent());
}
}

View File

@@ -30,13 +30,15 @@ class EnhancedChoiceTypeExtensionTest extends TestCase
$resolver = new OptionsResolver();
$sut = new EnhancedChoiceTypeExtension();
$sut->configureOptions($resolver);
self::assertEquals(['selectpicker', 'search'], $resolver->getDefinedOptions());
self::assertEquals(['selectpicker', 'width', 'search'], $resolver->getDefinedOptions());
self::assertTrue($resolver->hasDefault('selectpicker'));
self::assertTrue($resolver->hasDefault('width'));
self::assertTrue($resolver->hasDefault('search'));
self::assertFalse($resolver->isRequired('selectpicker'));
self::assertFalse($resolver->isRequired('width'));
self::assertFalse($resolver->isRequired('search'));
$result = $resolver->resolve([]);
self::assertEquals(['selectpicker' => true, 'search' => true], $result);
self::assertEquals(['selectpicker' => true, 'width' => '100%', 'search' => true], $result);
}
}

View File

@@ -37,7 +37,7 @@ class CurrentUserFactory extends AbstractMockFactory
$repository = $this->getMockBuilder(UserRepository::class)->onlyMethods(['getUserById'])->disableOriginalConstructor()->getMock();
$repository->expects(TestCase::atMost(1))->method('getUserById')->willReturn($user);
$token = $this->getMockBuilder(UsernamePasswordToken::class)->onlyMethods(['getUser'])->disableOriginalConstructor()->getMock();
$token->expects(TestCase::atLeast(1))->method('getUser')->willReturn($user);
$token->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);

View File

@@ -24,6 +24,7 @@ class DayTest extends TestCase
$sut = new Day($date, 12340, 197.25956);
$this->assertSame($date, $sut->getDay());
$this->assertEquals([], $sut->getDetails());
$this->assertEquals(12340, $sut->getTotalDuration());
$this->assertEquals(197.25956, $sut->getTotalRate());
}
@@ -39,4 +40,13 @@ class DayTest extends TestCase
$this->assertEquals(999, $sut->getTotalDuration());
$this->assertEquals(0.123456789, $sut->getTotalRate());
}
public function testSetDetails()
{
$sut = new Day(new DateTime(), 12340, 197.25956);
$sut->setDetails(['foo' => ['bar' => '1212e'], 'hello' => 'world']);
$this->assertEquals(['foo' => ['bar' => '1212e'], 'hello' => 'world'], $sut->getDetails());
}
}

View 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\Reporting;
use App\Reporting\Report;
use App\Reporting\ReportInterface;
use PHPUnit\Framework\TestCase;
/**
* @covers \App\Reporting\Report
*/
class ReportTest extends TestCase
{
public function testEmptyObject()
{
$report = new Report('id', 'route', 'label');
self::assertInstanceOf(ReportInterface::class, $report);
self::assertEquals('id', $report->getId());
self::assertEquals('route', $report->getRoute());
self::assertEquals('label', $report->getLabel());
}
}

View File

@@ -120,17 +120,19 @@ class DateExtensionsTest extends TestCase
/**
* @dataProvider getDayNameTestData
*/
public function testDayName(string $locale, string $date, string $expectedName)
public function testDayName(string $locale, string $date, string $expectedName, bool $short)
{
$sut = $this->getSut($locale, []);
self::assertEquals($expectedName, $sut->dayName(new \DateTime($date)));
self::assertEquals($expectedName, $sut->dayName(new \DateTime($date), $short));
}
public function getDayNameTestData()
{
return [
['de', '2020-07-09 12:00:00', 'Donnerstag'],
['en', '2020-07-09 12:00:00', 'Thursday']
['de', '2020-07-09 12:00:00', 'Donnerstag', false],
['en', '2020-07-09 12:00:00', 'Thursday', false],
['de', '2020-07-09 12:00:00', 'Do.', true],
['en', '2020-07-09 12:00:00', 'Thu', true],
];
}

View File

@@ -39,7 +39,7 @@ class IconExtensionTest extends TestCase
'delete', 'repeat', 'edit', 'manual', 'help', 'start', 'start-small', 'stop', 'stop-small', 'filter',
'create', 'list', 'print', 'visibility', 'calendar', 'money', 'duration', 'download', 'copy', 'settings',
'export', 'pdf', 'csv', 'ods', 'xlsx', 'on', 'off', 'audit', 'home', 'shop', 'about', 'debug', 'profile-stats',
'profile', 'warning', 'permissions', 'back', 'tag', 'avatar', 'timesheet-team', 'plugin', 'configuration'
'profile', 'warning', 'permissions', 'back', 'tag', 'avatar', 'timesheet-team', 'plugin', 'configuration', 'reporting'
];
// test pre-defined icons

View 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\Twig;
use App\Entity\User;
use App\Twig\ReportingExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Twig\TwigFunction;
/**
* @covers \App\Twig\ReportingExtension
*/
class ReportingExtensionTest extends TestCase
{
protected function getSut(bool $isGranted = false): ReportingExtension
{
$dispatcher = $this->createMock(EventDispatcherInterface::class);
$security = $this->createMock(AuthorizationCheckerInterface::class);
$security->method('isGranted')->willReturn($isGranted);
return new ReportingExtension($dispatcher, $security);
}
public function testGetFunctions()
{
$sut = $this->getSut();
$functions = ['available_reports'];
$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());
}
}
public function testGetAvailableReports()
{
$sut = $this->getSut();
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
self::assertEmpty($reports);
}
public function testGetAvailableReportsWithPermission()
{
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
self::assertIsArray($reports);
self::assertCount(2, $reports);
}
}

View File

@@ -0,0 +1,48 @@
<?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\Export\ServiceExport;
use App\Twig\TimesheetExtension;
use PHPUnit\Framework\TestCase;
use Twig\TwigFunction;
/**
* @covers \App\Twig\TimesheetExtension
*/
class TimesheetExtensionTest extends TestCase
{
protected function getSut(): TimesheetExtension
{
$service = new ServiceExport();
return new TimesheetExtension($service);
}
public function testGetFunctions()
{
$sut = $this->getSut();
$functions = ['timesheet_exporter'];
$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());
}
}
public function testGetExporter()
{
$sut = $this->getSut();
self::assertEquals([], $sut->getTimesheetExporter());
}
}

View File

@@ -103,7 +103,7 @@ class DailyWorkingTimeChartTest extends TestCase
$repository = $this->getMockBuilder(TimesheetRepository::class)->disableOriginalConstructor()->onlyMethods(['getDailyData'])->getMock();
$repository->expects($this->once())->method('getDailyData')->willReturnCallback(function ($begin, $end, $user) {
return [
['year' => $begin->format('Y'), 'month' => $begin->format('n'), 'day' => $begin->format('j'), 'rate' => 13.75, 'duration' => 1234]
['year' => $begin->format('Y'), 'month' => $begin->format('n'), 'day' => $begin->format('j'), 'rate' => 13.75, 'duration' => 1234, 'details' => []]
];
});