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;
|
|
|
|
|
2021-08-06 18:38:41 +02:00
|
|
|
use App\Activity\ActivityStatisticService;
|
2021-11-14 18:18:26 +01:00
|
|
|
use App\Entity\User;
|
2024-12-22 18:36:47 +01:00
|
|
|
use App\Export\Base\HtmlRenderer;
|
2021-04-29 11:50:48 +02:00
|
|
|
use App\Project\ProjectStatisticService;
|
2021-11-14 18:18:26 +01:00
|
|
|
use Symfony\Bridge\Twig\AppVariable;
|
2019-09-19 20:28:31 +02:00
|
|
|
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;
|
2021-11-14 18:18:26 +01:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2019-11-08 16:10:38 +01:00
|
|
|
* @covers \App\Export\Base\HtmlRenderer
|
|
|
|
* @covers \App\Export\Base\RendererTrait
|
2019-06-13 18:38:49 +02:00
|
|
|
* @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(
|
2019-11-08 16:10:38 +01:00
|
|
|
$this->createMock(Environment::class),
|
2020-03-23 01:51:02 +01:00
|
|
|
new EventDispatcher(),
|
2021-08-06 18:38:41 +02:00
|
|
|
$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 */
|
2022-12-31 21:19:55 +01:00
|
|
|
$twig = self::getContainer()->get('twig');
|
2021-11-14 18:18:26 +01:00
|
|
|
|
2023-05-26 18:40:54 +02:00
|
|
|
$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');
|
2021-11-14 18:18:26 +01:00
|
|
|
$token = $this->createMock(TokenInterface::class);
|
2023-05-26 18:40:54 +02:00
|
|
|
$token->expects($this->any())->method('getUser')->willReturn($user);
|
2021-11-14 18:18:26 +01:00
|
|
|
|
|
|
|
$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 */
|
2022-12-31 21:19:55 +01:00
|
|
|
$stack = self::getContainer()->get('request_stack');
|
2019-02-05 21:37:33 +01:00
|
|
|
$request = new Request();
|
|
|
|
$request->setLocale('en');
|
|
|
|
$stack->push($request);
|
|
|
|
|
2021-08-06 18:38:41 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
}
|