mirror of
https://github.com/werkraum-media/calendar.git
synced 2024-11-21 17:46:08 +01:00
Add functional tests (#7)
This replaces the existing unit tests for the controller. Functional tests are way better suited for testing the controller.
This commit is contained in:
parent
c944a3c78f
commit
77dd56ad43
18 changed files with 536 additions and 359 deletions
|
@ -114,7 +114,9 @@ class CalendarController extends ActionController
|
||||||
{
|
{
|
||||||
if ($this->request->hasArgument('day') === false) {
|
if ($this->request->hasArgument('day') === false) {
|
||||||
$this->request->setArguments([
|
$this->request->setArguments([
|
||||||
'day' => new \DateTimeImmutable(),
|
'day' => [
|
||||||
|
'day' => date('Y-m-d'),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
22
Tests/Fixtures/BasicDatabase.xml
Normal file
22
Tests/Fixtures/BasicDatabase.xml
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<dataset>
|
||||||
|
<pages>
|
||||||
|
<uid>1</uid>
|
||||||
|
<pid>0</pid>
|
||||||
|
<doktype>1</doktype>
|
||||||
|
<is_siteroot>1</is_siteroot>
|
||||||
|
<slug>/</slug>
|
||||||
|
<title>Page Title</title>
|
||||||
|
</pages>
|
||||||
|
<sys_template>
|
||||||
|
<uid>1</uid>
|
||||||
|
<pid>1</pid>
|
||||||
|
<root>1</root>
|
||||||
|
<clear>3</clear>
|
||||||
|
<constants>databasePlatform = mysql</constants>
|
||||||
|
<config><![CDATA[
|
||||||
|
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:calendar_example/Configuration/TypoScript/Setup.typoscript">
|
||||||
|
<INCLUDE_TYPOSCRIPT: source="FILE:EXT:fluid_styled_content/Configuration/TypoScript/setup.typoscript">
|
||||||
|
]]></config>
|
||||||
|
</sys_template>
|
||||||
|
</dataset>
|
32
Tests/Fixtures/Sites/default/config.yaml
Normal file
32
Tests/Fixtures/Sites/default/config.yaml
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
base: /
|
||||||
|
languages:
|
||||||
|
-
|
||||||
|
title: English
|
||||||
|
enabled: true
|
||||||
|
base: /
|
||||||
|
typo3Language: default
|
||||||
|
locale: en_GB.UTF-8
|
||||||
|
iso-639-1: en
|
||||||
|
websiteTitle: ''
|
||||||
|
navigationTitle: English
|
||||||
|
hreflang: en-GB
|
||||||
|
direction: ''
|
||||||
|
flag: gb
|
||||||
|
languageId: 0
|
||||||
|
fallbackType: strict
|
||||||
|
fallbacks: '0'
|
||||||
|
-
|
||||||
|
title: Deutsch
|
||||||
|
enabled: true
|
||||||
|
base: /de
|
||||||
|
typo3Language: de
|
||||||
|
locale: de_DE.UTF-8
|
||||||
|
iso-639-1: de
|
||||||
|
navigationTitle: Deutsch
|
||||||
|
hreflang: de-DE
|
||||||
|
direction: ''
|
||||||
|
flag: de
|
||||||
|
websiteTitle: ''
|
||||||
|
languageId: 1
|
||||||
|
rootPageId: 1
|
||||||
|
websiteTitle: 'Example Website'
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WerkraumMedia\CalendarExample\Domain;
|
||||||
|
|
||||||
|
use WerkraumMedia\Calendar\Domain\Model\Day;
|
||||||
|
use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory;
|
||||||
|
|
||||||
|
class ExampleDataFactory implements ForeignDataFactory
|
||||||
|
{
|
||||||
|
public function getData(Day $day)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'exampleKey' => 'exampleValue',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WerkraumMedia\CalendarExample\EventListener;
|
||||||
|
|
||||||
|
use WerkraumMedia\Calendar\Events\AssignTemplateVariables as AssignTemplateVariablesEvent;
|
||||||
|
|
||||||
|
class AssignTemplateVariables
|
||||||
|
{
|
||||||
|
public function __invoke(AssignTemplateVariablesEvent $event): void
|
||||||
|
{
|
||||||
|
$event->setVariables(array_merge($event->getVariables(), [
|
||||||
|
'customVariable' => 'modifiedVariable',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
17
Tests/Fixtures/calendar_example/Configuration/Services.yaml
Normal file
17
Tests/Fixtures/calendar_example/Configuration/Services.yaml
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
services:
|
||||||
|
_defaults:
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
public: false
|
||||||
|
|
||||||
|
WerkraumMedia\CalendarExample\:
|
||||||
|
resource: '../Classes/*'
|
||||||
|
|
||||||
|
WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory:
|
||||||
|
class: 'WerkraumMedia\CalendarExample\Domain\ExampleDataFactory'
|
||||||
|
public: true
|
||||||
|
|
||||||
|
WerkraumMedia\CalendarExample\EventListener\AssignTemplateVariables:
|
||||||
|
tags:
|
||||||
|
- name: 'event.listener'
|
||||||
|
event: 'WerkraumMedia\Calendar\Events\AssignTemplateVariables'
|
|
@ -0,0 +1,12 @@
|
||||||
|
plugin.tx_calendar_example {
|
||||||
|
view {
|
||||||
|
templateRootPaths {
|
||||||
|
10 = EXT:calendar_example/Resources/Private/Templates/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
page = PAGE
|
||||||
|
page {
|
||||||
|
10 =< tt_content.calendar_example.20
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
|
||||||
|
data-namespace-typo3-fluid="true"
|
||||||
|
>
|
||||||
|
|
||||||
|
<h2>{day.dateTimeInstance -> f:format.date(format: 'd.m.Y')}</h2>
|
||||||
|
|
||||||
|
{day.foreignData.exampleKey}
|
||||||
|
|
||||||
|
{customVariable}
|
||||||
|
</html>
|
|
@ -0,0 +1,14 @@
|
||||||
|
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
|
||||||
|
data-namespace-typo3-fluid="true">
|
||||||
|
|
||||||
|
<h2>{month.dateTimeInstance -> f:format.date(format: '%B %Y')}</h2>
|
||||||
|
|
||||||
|
<f:for each="{month.weeks}" as="week">
|
||||||
|
<f:for each="{week.days}" as="day">
|
||||||
|
{day.dateTimeInstance -> f:format.date(format: 'd')}
|
||||||
|
{day.foreignData.exampleKey}
|
||||||
|
</f:for>
|
||||||
|
</f:for>
|
||||||
|
|
||||||
|
{customVariable}
|
||||||
|
</html>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
|
||||||
|
data-namespace-typo3-fluid="true">
|
||||||
|
|
||||||
|
<h2>{week.dateTimeInstance -> f:format.date(format: '%V %Y')}</h2>
|
||||||
|
|
||||||
|
<f:for each="{week.days}" as="day">
|
||||||
|
{day.dateTimeInstance -> f:format.date(format: 'd')}
|
||||||
|
{day.foreignData.exampleKey}
|
||||||
|
</f:for>
|
||||||
|
|
||||||
|
{customVariable}
|
||||||
|
</html>
|
|
@ -0,0 +1,16 @@
|
||||||
|
<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
|
||||||
|
data-namespace-typo3-fluid="true">
|
||||||
|
|
||||||
|
<h2>{year.dateTimeInstance -> f:format.date(format: 'Y')}</h2>
|
||||||
|
|
||||||
|
<f:for each="{year.months}" as="month">
|
||||||
|
<f:for each="{month.weeks}" as="week">
|
||||||
|
<f:for each="{week.days}" as="day">
|
||||||
|
{day.dateTimeInstance -> f:format.date(format: 'd')}
|
||||||
|
{day.foreignData.exampleKey}
|
||||||
|
</f:for>
|
||||||
|
</f:for>
|
||||||
|
</f:for>
|
||||||
|
|
||||||
|
{customVariable}
|
||||||
|
</html>
|
21
Tests/Fixtures/calendar_example/composer.json
Normal file
21
Tests/Fixtures/calendar_example/composer.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"name": "werkraummedia/calendar_example",
|
||||||
|
"description": "Add calendar data",
|
||||||
|
"type": "typo3-cms-extension",
|
||||||
|
"license": "GPL-2.0-or-later",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"WerkraumMedia\\CalendarExample\\": "Classes/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"typo3/cms-core": "*",
|
||||||
|
"typo3/cms-fluid-styled-content": "*",
|
||||||
|
"werkraummedia/calendar": "*"
|
||||||
|
},
|
||||||
|
"extra": {
|
||||||
|
"typo3/cms": {
|
||||||
|
"extension-key": "calendar_example"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
21
Tests/Fixtures/calendar_example/ext_emconf.php
Normal file
21
Tests/Fixtures/calendar_example/ext_emconf.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$EM_CONF['calendar_example'] = [
|
||||||
|
'title' => 'Calendar Example',
|
||||||
|
'description' => 'Example extension to demonstrate integration',
|
||||||
|
'category' => 'misc',
|
||||||
|
'author' => 'Daniel Siepmann',
|
||||||
|
'author_email' => 'coding@daniel-siepmann.de',
|
||||||
|
'author_company' => 'Codappix GmbH',
|
||||||
|
'state' => 'alpha',
|
||||||
|
'uploadfolder' => 0,
|
||||||
|
'clearCacheOnLoad' => 0,
|
||||||
|
'version' => '1.0.0',
|
||||||
|
'constraints' => [
|
||||||
|
'depends' => [
|
||||||
|
'typo3' => '*',
|
||||||
|
],
|
||||||
|
'conflicts' => [],
|
||||||
|
'suggests' => [],
|
||||||
|
],
|
||||||
|
];
|
18
Tests/Fixtures/calendar_example/ext_localconf.php
Normal file
18
Tests/Fixtures/calendar_example/ext_localconf.php
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
(function () {
|
||||||
|
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
|
||||||
|
'Calendar',
|
||||||
|
'Example',
|
||||||
|
[
|
||||||
|
\WerkraumMedia\Calendar\Controller\Frontend\CalendarController::class => implode(',', [
|
||||||
|
'day',
|
||||||
|
'week',
|
||||||
|
'month',
|
||||||
|
'year',
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
[],
|
||||||
|
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::PLUGIN_TYPE_CONTENT_ELEMENT
|
||||||
|
);
|
||||||
|
})();
|
246
Tests/Functional/CalendarControllerTest.php
Normal file
246
Tests/Functional/CalendarControllerTest.php
Normal file
|
@ -0,0 +1,246 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2
|
||||||
|
* of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||||
|
* 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace WerkraumMedia\Calendar\Tests\Functional;
|
||||||
|
|
||||||
|
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
|
||||||
|
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
|
||||||
|
use WerkraumMedia\Calendar\Controller\Frontend\CalendarController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversNothing
|
||||||
|
* @testdox Calendar controller renders with
|
||||||
|
*/
|
||||||
|
class CalendarControllerTest extends FunctionalTestCase
|
||||||
|
{
|
||||||
|
protected $coreExtensionsToLoad = [
|
||||||
|
'fluid_styled_content',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $testExtensionsToLoad = [
|
||||||
|
'typo3conf/ext/calendar',
|
||||||
|
'typo3conf/ext/calendar/Tests/Fixtures/calendar_example',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $pathsToLinkInTestInstance = [
|
||||||
|
'typo3conf/ext/calendar/Tests/Fixtures/Sites' => 'typo3conf/sites',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->importDataSet(__DIR__ . '/../Fixtures/BasicDatabase.xml');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function modifiedVariablesForCurrentDay(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('modifiedVariable', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForCurrentDay(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString(date('d.m.Y'), $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForProvidedDay(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[day][day]', '2020-11-03');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('03.11.2020', $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function modifiedVariablesForCurrentWeek(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'week');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('modifiedVariable', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForCurrentWeek(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'week');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString(date('W Y'), $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForProvidedWeek(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'week');
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[week][week]', '02');
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[week][year]', '2020');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('02 2020', $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function modifiedVariablesForCurrentMonth(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'month');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('modifiedVariable', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForCurrentMonth(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'month');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString(strftime('%B %Y'), $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForProvidedMonth(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'month');
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[month][month]', '11');
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[month][year]', '2020');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('November 2020', $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function modifiedVariablesForCurrentYear(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'year');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('modifiedVariable', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForCurrentYear(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'year');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString(date('Y'), $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
public function customDataForProvidedYear(): void
|
||||||
|
{
|
||||||
|
$request = new InternalRequest();
|
||||||
|
$request = $request->withPageId(1);
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[action]', 'year');
|
||||||
|
$request = $request->withQueryParameter('tx_calendar_example[year][year]', '2020');
|
||||||
|
$result = $this->executeFrontendRequest($request);
|
||||||
|
|
||||||
|
self::assertSame(200, $result->getStatusCode());
|
||||||
|
$html = $result->getBody()->__toString();
|
||||||
|
self::assertStringContainsString('2020', $html);
|
||||||
|
self::assertStringContainsString('exampleValue', $html);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,356 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace WerkraumMedia\Calendar\Tests\Unit\Controller\Frontend;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright (C) 2020 Daniel Siepmann <coding@daniel-siepmann.de>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* as published by the Free Software Foundation; either version 2
|
|
||||||
* of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
||||||
* 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
use Prophecy\Argument as ProphetArgument;
|
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
|
||||||
use Prophecy\Prophecy\ObjectProphecy;
|
|
||||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\Argument;
|
|
||||||
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
|
|
||||||
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
|
|
||||||
use TYPO3\CMS\Extbase\Mvc\Web\Request;
|
|
||||||
use TYPO3\CMS\Extbase\Property\PropertyMappingConfiguration;
|
|
||||||
use WerkraumMedia\Calendar\Controller\Frontend\CalendarController;
|
|
||||||
use WerkraumMedia\Calendar\Domain\Model\Day;
|
|
||||||
use WerkraumMedia\Calendar\Domain\Model\Month;
|
|
||||||
use WerkraumMedia\Calendar\Domain\Model\Week;
|
|
||||||
use WerkraumMedia\Calendar\Domain\Model\Year;
|
|
||||||
use WerkraumMedia\Calendar\Events\AssignTemplateVariables;
|
|
||||||
use WerkraumMedia\Calendar\Tests\ForcePropertyTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers WerkraumMedia\Calendar\Controller\Frontend\CalendarController
|
|
||||||
* @testdox The calendar controller
|
|
||||||
*/
|
|
||||||
class CalendarControllerTest extends TestCase
|
|
||||||
{
|
|
||||||
use ProphecyTrait;
|
|
||||||
use ForcePropertyTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function setsCurrentYearAsDefaultArgument(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('year')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('year')->willReturn(false);
|
|
||||||
$request->setArguments([
|
|
||||||
'year' => [
|
|
||||||
'year' => date('Y'),
|
|
||||||
],
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeYearAction();
|
|
||||||
$request->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function allowsYearToBeMapped(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('year')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('year')->willReturn(true);
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeYearAction();
|
|
||||||
$arguments->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function addsYearToView(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
|
||||||
$eventDispatcher->dispatch(ProphetArgument::type(AssignTemplateVariables::class))->shouldBeCalled();
|
|
||||||
$subject->injectEventDispatcher($eventDispatcher->reveal());
|
|
||||||
|
|
||||||
$year = $this->prophesize(Year::class);
|
|
||||||
$view = $this->prophesize(ViewInterface::class);
|
|
||||||
$view->assignMultiple([
|
|
||||||
'year' => $year->reveal(),
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'view', $view->reveal());
|
|
||||||
|
|
||||||
$subject->yearAction($year->reveal());
|
|
||||||
$view->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function setsCurrentMonthAsDefaultArgument(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('month')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('month')->willReturn(false);
|
|
||||||
$request->setArguments([
|
|
||||||
'month' => [
|
|
||||||
'month' => date('m'),
|
|
||||||
'year' => date('Y'),
|
|
||||||
],
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeMonthAction();
|
|
||||||
$request->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function allowsMonthToBeMapped(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('month')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('month')->willReturn(true);
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeMonthAction();
|
|
||||||
$arguments->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function addsMonthToView(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
|
||||||
$eventDispatcher->dispatch(ProphetArgument::type(AssignTemplateVariables::class))->shouldBeCalled();
|
|
||||||
$subject->injectEventDispatcher($eventDispatcher->reveal());
|
|
||||||
|
|
||||||
$month = $this->prophesize(Month::class);
|
|
||||||
$view = $this->prophesize(ViewInterface::class);
|
|
||||||
$view->assignMultiple([
|
|
||||||
'month' => $month->reveal(),
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'view', $view->reveal());
|
|
||||||
|
|
||||||
$subject->monthAction($month->reveal());
|
|
||||||
$view->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function setsCurrentWeekAsDefaultArgument(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('week')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('week')->willReturn(false);
|
|
||||||
$request->setArguments([
|
|
||||||
'week' => [
|
|
||||||
'week' => date('W'),
|
|
||||||
'year' => date('Y'),
|
|
||||||
],
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeWeekAction();
|
|
||||||
$request->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function allowsWeekToBeMapped(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$arguments = $this->allowsMappingOfAllPropertiesForArgument('week')['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('week')->willReturn(true);
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeWeekAction();
|
|
||||||
$arguments->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function addsWeekToView(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
|
||||||
$eventDispatcher->dispatch(ProphetArgument::type(AssignTemplateVariables::class))->shouldBeCalled();
|
|
||||||
$subject->injectEventDispatcher($eventDispatcher->reveal());
|
|
||||||
|
|
||||||
$week = $this->prophesize(Week::class);
|
|
||||||
$view = $this->prophesize(ViewInterface::class);
|
|
||||||
$view->assignMultiple([
|
|
||||||
'week' => $week->reveal(),
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'view', $view->reveal());
|
|
||||||
|
|
||||||
$subject->weekAction($week->reveal());
|
|
||||||
$view->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function setsCurrentDayAsDefaultArgument(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$prophecies = $this->allowsMappingOfAllPropertiesForArgument('day');
|
|
||||||
$propertyConfiguration = $prophecies['propertyMappingConfiguration'];
|
|
||||||
$arguments = $prophecies['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('day')->willReturn(false);
|
|
||||||
$request->setArguments(ProphetArgument::that(function (array $arguments) {
|
|
||||||
return count($arguments) === 1
|
|
||||||
&& isset($arguments['day'])
|
|
||||||
&& $arguments['day'] instanceof \DateTimeImmutable
|
|
||||||
&& $arguments['day']->format('Y-m-d') === date('Y-m-d')
|
|
||||||
;
|
|
||||||
}))->shouldBeCalled();
|
|
||||||
|
|
||||||
$configuration = $this->prophesize(PropertyMappingConfiguration::class);
|
|
||||||
$configuration->setTypeConverterOption(
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'Y-m-d'
|
|
||||||
);
|
|
||||||
$propertyConfiguration->forProperty('day')->willReturn($configuration);
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeDayAction();
|
|
||||||
$request->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function configuredMappingForDay(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$prophecies = $this->allowsMappingOfAllPropertiesForArgument('day');
|
|
||||||
$propertyConfiguration = $prophecies['propertyMappingConfiguration'];
|
|
||||||
$arguments = $prophecies['arguments'];
|
|
||||||
|
|
||||||
$request = $this->prophesize(Request::class);
|
|
||||||
$request->hasArgument('day')->willReturn(true);
|
|
||||||
|
|
||||||
$configuration = $this->prophesize(PropertyMappingConfiguration::class);
|
|
||||||
$configuration->setTypeConverterOption(
|
|
||||||
'',
|
|
||||||
'',
|
|
||||||
'Y-m-d'
|
|
||||||
);
|
|
||||||
$propertyConfiguration->forProperty('day')->willReturn($configuration);
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'request', $request->reveal());
|
|
||||||
$this->forceProperty($subject, 'arguments', $arguments->reveal());
|
|
||||||
|
|
||||||
$subject->initializeDayAction();
|
|
||||||
$arguments->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
*/
|
|
||||||
public function addsDayToView(): void
|
|
||||||
{
|
|
||||||
$subject = new CalendarController();
|
|
||||||
|
|
||||||
$eventDispatcher = $this->prophesize(EventDispatcherInterface::class);
|
|
||||||
$eventDispatcher->dispatch(ProphetArgument::type(AssignTemplateVariables::class))->shouldBeCalled();
|
|
||||||
$subject->injectEventDispatcher($eventDispatcher->reveal());
|
|
||||||
|
|
||||||
$day = $this->prophesize(Day::class);
|
|
||||||
$view = $this->prophesize(ViewInterface::class);
|
|
||||||
$view->assignMultiple([
|
|
||||||
'day' => $day->reveal(),
|
|
||||||
])->shouldBeCalled();
|
|
||||||
|
|
||||||
$this->forceProperty($subject, 'view', $view->reveal());
|
|
||||||
|
|
||||||
$subject->dayAction($day->reveal());
|
|
||||||
$view->checkProphecyMethodsPredictions();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function allowsMappingOfAllPropertiesForArgument(string $argumentName): array
|
|
||||||
{
|
|
||||||
$propertyMappingConfiguration = $this->prophesize(PropertyMappingConfiguration::class);
|
|
||||||
$propertyMappingConfiguration->allowAllProperties()->shouldBeCalled();
|
|
||||||
|
|
||||||
$argument = $this->prophesize(Argument::class);
|
|
||||||
$argument->getPropertyMappingConfiguration()->willReturn($propertyMappingConfiguration);
|
|
||||||
|
|
||||||
$arguments = $this->prophesize(Arguments::class);
|
|
||||||
$arguments->getArgument($argumentName)->willReturn($argument->reveal());
|
|
||||||
|
|
||||||
return [
|
|
||||||
'propertyMappingConfiguration' => $propertyMappingConfiguration,
|
|
||||||
'argument' => $argument,
|
|
||||||
'arguments' => $arguments,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -24,7 +24,8 @@
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"WerkraumMedia\\Calendar\\Tests\\": "Tests/"
|
"WerkraumMedia\\Calendar\\Tests\\": "Tests/",
|
||||||
|
"WerkraumMedia\\CalendarExample\\": "Tests/Fixtures/calendar_example/Classes/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
@ -32,7 +33,9 @@
|
||||||
"maglnet/composer-require-checker": "^2.1",
|
"maglnet/composer-require-checker": "^2.1",
|
||||||
"phpspec/prophecy-phpunit": "^2.0",
|
"phpspec/prophecy-phpunit": "^2.0",
|
||||||
"phpunit/phpunit": "^9.5",
|
"phpunit/phpunit": "^9.5",
|
||||||
"symplify/easy-coding-standard": "^9.2"
|
"symplify/easy-coding-standard": "^9.2",
|
||||||
|
"typo3/cms-fluid-styled-content": "^10.4",
|
||||||
|
"typo3/testing-framework": "^6.6"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"typo3/cms": {
|
"typo3/cms": {
|
||||||
|
@ -40,5 +43,11 @@
|
||||||
"extension-key": "calendar",
|
"extension-key": "calendar",
|
||||||
"web-dir": ".Build/web"
|
"web-dir": ".Build/web"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"post-autoload-dump": [
|
||||||
|
"@php -r 'is_dir($extFolder = __DIR__ . \"/.Build/web/typo3conf/ext/\") || mkdir($extFolder, 0777, true);'",
|
||||||
|
"@php -r 'file_exists($extFolder = __DIR__ . \"/.Build/web/typo3conf/ext/calendar\") || symlink(__DIR__, $extFolder);'"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
|
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
backupStaticAttributes="false"
|
||||||
|
bootstrap="vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php"
|
||||||
colors="true"
|
colors="true"
|
||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
|
@ -20,6 +21,9 @@
|
||||||
<testsuite name="unit">
|
<testsuite name="unit">
|
||||||
<directory>Tests/Unit/</directory>
|
<directory>Tests/Unit/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
|
<testsuite name="functional">
|
||||||
|
<directory>Tests/Functional/</directory>
|
||||||
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
<coverage>
|
<coverage>
|
||||||
|
@ -27,4 +31,8 @@
|
||||||
<directory suffix=".php">Classes</directory>
|
<directory suffix=".php">Classes</directory>
|
||||||
</include>
|
</include>
|
||||||
</coverage>
|
</coverage>
|
||||||
|
|
||||||
|
<php>
|
||||||
|
<env name="typo3DatabaseDriver" value="pdo_sqlite"/>
|
||||||
|
</php>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|
Loading…
Reference in a new issue