0
0
Fork 0
mirror of https://github.com/kevinpapst/kimai2.git synced 2025-05-11 12:15:43 +00:00
kevinpapst_kimai2/tests/Export/Renderer/HtmlRendererTest.php

99 lines
3.9 KiB
PHP
Raw Normal View History

2019-02-05 21:37:33 +01:00
<?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\Export\Renderer;
use App\Activity\ActivityStatisticService;
use App\Entity\User;
use App\Export\Base\HtmlRenderer;
use App\Project\ProjectStatisticService;
use Symfony\Bridge\Twig\AppVariable;
use Symfony\Component\EventDispatcher\EventDispatcher;
2019-02-05 21:37:33 +01:00
use Symfony\Component\HttpFoundation\Request;
2024-11-21 22:44:49 +01:00
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2019-04-08 18:38:56 +02:00
use Twig\Environment;
2019-02-05 21:37:33 +01:00
/**
* @covers \App\Export\Base\HtmlRenderer
* @covers \App\Export\Base\RendererTrait
* @group integration
2019-02-05 21:37:33 +01:00
*/
2024-12-22 01:25:30 +01:00
class HtmlRendererTest extends AbstractRendererTestCase
2019-02-05 21:37:33 +01:00
{
2024-02-07 23:47:25 +01:00
public function testConfiguration(): void
2019-02-05 21:37:33 +01:00
{
$sut = new HtmlRenderer(
$this->createMock(Environment::class),
new EventDispatcher(),
$this->createMock(ProjectStatisticService::class),
$this->createMock(ActivityStatisticService::class)
2019-02-05 21:37:33 +01:00
);
2024-12-22 01:25:30 +01:00
self::assertEquals('html', $sut->getId());
self::assertEquals('print', $sut->getTitle());
2019-02-05 21:37:33 +01:00
}
2024-02-07 23:47:25 +01:00
public function testRender(): void
2019-02-05 21:37:33 +01:00
{
2019-04-08 18:38:56 +02:00
/** @var Environment $twig */
$twig = self::getContainer()->get('twig');
$user = $this->createMock(User::class);
$user->method('getId')->willReturn(1);
$user->method('getName')->willReturn('Testing');
$user->method('isAdmin')->willReturn(false);
$user->method('isSuperAdmin')->willReturn(false);
$user->method('getTimezone')->willReturn('America/Edmonton');
$token = $this->createMock(TokenInterface::class);
$token->expects($this->any())->method('getUser')->willReturn($user);
$tokenStorage = new TokenStorage();
$tokenStorage->setToken($token);
/** @var AppVariable $app */
$app = $twig->getGlobals()['app'];
$twig->addGlobal('app', $app);
$app->setTokenStorage($tokenStorage);
2024-11-21 22:44:49 +01:00
/** @var RequestStack $stack */
$stack = self::getContainer()->get('request_stack');
2019-02-05 21:37:33 +01:00
$request = new Request();
$request->setLocale('en');
$stack->push($request);
$sut = new HtmlRenderer(
$twig,
new EventDispatcher(),
$this->createMock(ProjectStatisticService::class),
$this->createMock(ActivityStatisticService::class)
);
2019-02-05 21:37:33 +01:00
$response = $this->render($sut);
$content = $response->getContent();
2024-12-22 01:25:30 +01:00
self::assertStringContainsString('<h2 id="doc-title" contenteditable="true"', $content);
self::assertStringContainsString('<h3 class="card-title" id="doc-summary" contenteditable="true" data-original="Summary">Summary</h3>', $content);
self::assertEquals(1, substr_count($content, 'id="export-summary"'));
self::assertEquals(1, substr_count($content, 'id="export-records"'));
self::assertEquals(1, substr_count($content, 'id="summary-project"'));
self::assertEquals(1, substr_count($content, 'id="summary-activity"'));
2019-02-05 21:37:33 +01:00
2024-12-22 01:25:30 +01:00
self::assertStringContainsString('<td>Customer Name</td>', $content);
self::assertStringContainsString('<td>project name</td>', $content);
self::assertStringContainsString('<span class="duration-format" data-duration-decimal="1.94" data-duration="1:56">1:56</span>', $content);
self::assertStringContainsString('<td class="cost summary-rate">€2,437.12</td>', $content);
self::assertStringContainsString('-€100.92', $content);
2019-02-05 21:37:33 +01:00
2019-05-23 18:19:56 +02:00
// 5 times in the "full list" and once in the "summary with activities"
2024-12-22 01:25:30 +01:00
self::assertEquals(7, substr_count($content, 'activity description'));
self::assertEquals(1, substr_count($content, '<td>activity description</td>'));
2019-02-05 21:37:33 +01:00
}
}