allow to select reports as initial view (#2403)

This commit is contained in:
Kevin Papst
2021-03-06 12:59:13 +01:00
committed by GitHub
parent 5583caa9e4
commit 70f7f35009
7 changed files with 134 additions and 59 deletions

View File

@@ -1,62 +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\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(3, $reports);
}
}

View File

@@ -0,0 +1,43 @@
<?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\Runtime;
use App\Entity\User;
use App\Reporting\ReportingService;
use App\Twig\Runtime\ReportingExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
/**
* @covers \App\Twig\Runtime\ReportingExtension
*/
class ReportingExtensionTest extends TestCase
{
protected function getSut(bool $isGranted): ReportingExtension
{
$eventDispatcher = new EventDispatcher();
$authorization = $this->createMock(AuthorizationCheckerInterface::class);
$authorization->expects($this->any())->method('isGranted')->willReturn($isGranted);
$service = new ReportingService($eventDispatcher, $authorization);
return new ReportingExtension($service);
}
public function testRenderWidgetForInvalidValue()
{
$sut = $this->getSut(true);
$reports = $sut->getAvailableReports(new User());
$this->assertCount(3, $reports);
}
}

View File

@@ -37,7 +37,17 @@ class RuntimeExtensionsTest extends TestCase
public function testGetFunctions()
{
$expected = ['trigger', 'actions', 'javascript_translations', 'timesheet_exporter', 'active_timesheets', 'encore_entry_css_source', 'render_widget'];
$expected = [
'trigger',
'actions',
'javascript_translations',
'timesheet_exporter',
'active_timesheets',
'encore_entry_css_source',
'render_widget',
'available_reports'
];
$i = 0;
$sut = new RuntimeExtensions();