added project detail report (#2651)

- avatars via css only
- random colors for entities
- improves print view
- added colors for teams
- added color to tag
This commit is contained in:
Kevin Papst
2021-07-06 22:01:20 +02:00
committed by GitHub
parent cc6031bfde
commit 9ddb87a6fd
122 changed files with 2736 additions and 1549 deletions

View File

@@ -1,67 +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\AvatarExtension;
use App\Utils\AvatarService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\PackageInterface;
use Symfony\Component\Asset\Packages;
use Twig\TwigFunction;
/**
* @covers \App\Twig\AvatarExtension
*/
class AvatarExtensionTest extends TestCase
{
protected function getSut(int $packagesGetUrlCount): AvatarExtension
{
$default = $this->getMockBuilder(PackageInterface::class)->getMock();
$default->expects(self::exactly($packagesGetUrlCount))->method('getUrl')->willReturnCallback(function ($argument) {
return 'http://www.example.com/' . $argument;
});
$service = $this->getMockBuilder(AvatarService::class)->disableOriginalConstructor()->getMock();
$packages = new Packages();
$packages->setDefaultPackage($default);
return new AvatarExtension($service, $packages);
}
public function testGetFunctions()
{
$functions = ['avatar'];
$sut = $this->getSut(0);
$twigFunctions = $sut->getFunctions();
self::assertCount(\count($functions), $twigFunctions);
$i = 0;
/** @var TwigFunction $filter */
foreach ($twigFunctions as $filter) {
self::assertInstanceOf(TwigFunction::class, $filter);
self::assertEquals($functions[$i++], $filter->getName());
}
}
public function testGetAvatarWithoutUserReturnsDefault()
{
$sut = $this->getSut(1);
self::assertEquals('http://www.example.com/blub', $sut->getAvatarUrl(null, 'blub'));
}
public function testGetAvatarWithUserProfileReturnsNullOnNullFromAvatarService()
{
$sut = $this->getSut(1);
$user = new User();
self::assertEquals('http://www.example.com/test', $sut->getAvatarUrl($user, 'test'));
}
}

View File

@@ -30,7 +30,7 @@ class ExtensionsTest extends TestCase
public function testGetFilters()
{
$filters = ['docu_link', 'multiline_indent', 'color', 'font_contrast', 'nl2str'];
$filters = ['docu_link', 'multiline_indent', 'color', 'font_contrast', 'default_color', 'nl2str'];
$sut = $this->getSut();
$twigFilters = $sut->getFilters();
$this->assertCount(\count($filters), $twigFilters);
@@ -42,14 +42,14 @@ class ExtensionsTest extends TestCase
}
// make sure that the nl2str filters does proper escaping
self::assertEquals('nl2str', $twigFilters[4]->getName());
self::assertEquals('html', $twigFilters[4]->getPreEscape());
self::assertEquals(['html'], $twigFilters[4]->getSafe(new Node()));
self::assertEquals('nl2str', $twigFilters[5]->getName());
self::assertEquals('html', $twigFilters[5]->getPreEscape());
self::assertEquals(['html'], $twigFilters[5]->getSafe(new Node()));
}
public function testGetFunctions()
{
$functions = ['class_name', 'iso_day_by_name'];
$functions = ['class_name', 'iso_day_by_name', 'random_color'];
$sut = $this->getSut();
$twigFunctions = $sut->getFunctions();
$this->assertCount(\count($functions), $twigFunctions);
@@ -189,4 +189,31 @@ sdfsdf' . PHP_EOL . "\n" .
self::assertEquals($expected, $sut->replaceNewline($input, $replacer));
}
public function testGetRandomColor()
{
$sut = $this->getSut();
$this->assertIsValidColor($sut->randomColor());
$fooColor = $sut->randomColor('foo-bar');
self::assertIsValidColor($fooColor);
self::assertEquals($fooColor, $sut->randomColor('foo-bar'));
}
public function testGetDefaultColor()
{
$sut = $this->getSut();
self::assertEquals('#123456', $sut->defaultColor('#123456'));
self::assertEquals(Constants::DEFAULT_COLOR, $sut->defaultColor(null));
self::assertEquals(Constants::DEFAULT_COLOR, $sut->defaultColor());
self::assertEquals('', $sut->defaultColor(''));
}
private static function assertIsValidColor(string $color)
{
self::assertStringStartsWith('#', $color);
self::assertEquals(7, \strlen($color));
}
}

View File

@@ -52,7 +52,7 @@ class LocaleFormatExtensionsTest extends TestCase
{
$filters = [
'month_name', 'day_name', 'date_short', 'date_time', 'date_full', 'date_format', 'time', 'hour24',
'duration', 'duration_decimal', 'money', 'currency', 'country', 'language', 'amount'
'duration', 'chart_duration', 'duration_decimal', 'money', 'currency', 'country', 'language', 'amount'
];
$i = 0;
@@ -68,7 +68,7 @@ class LocaleFormatExtensionsTest extends TestCase
public function testGetFunctions()
{
$functions = ['get_format_duration', 'create_date', 'locales'];
$functions = ['get_format_duration', 'create_date', 'locales', 'month_names'];
$i = 0;
$sut = $this->getSut('de', []);
@@ -458,6 +458,15 @@ class LocaleFormatExtensionsTest extends TestCase
$this->assertEquals('0', $sut->duration(null, true));
}
public function testDurationChart()
{
$sut = $this->getSut('en', $this->localeEn);
self::assertEquals(0.34, $sut->durationChart(1234));
self::assertEquals(3.43, $sut->durationChart(12345));
self::assertEquals(34.29, $sut->durationChart(123456));
self::assertEquals(342.94, $sut->durationChart(1234567));
}
public function testDurationDecimal()
{
$record = $this->getTimesheet(9437);

View File

@@ -22,7 +22,7 @@ class RuntimeExtensionsTest extends TestCase
{
public function testGetFilters()
{
$expected = ['md2html', 'desc2html', 'comment2html', 'comment1line'];
$expected = ['md2html', 'desc2html', 'comment2html', 'comment1line', 'colorize'];
$i = 0;
$sut = new RuntimeExtensions();