Skip to content

Commit

Permalink
Add functional tests
Browse files Browse the repository at this point in the history
This replaces the existing unit tests for the controller.
Functional tests are way better suited for testing the controller.
  • Loading branch information
DanielSiepmann committed Jan 4, 2023
1 parent c944a3c commit 100135e
Show file tree
Hide file tree
Showing 18 changed files with 537 additions and 359 deletions.
4 changes: 3 additions & 1 deletion Classes/Controller/Frontend/CalendarController.php
Expand Up @@ -114,7 +114,9 @@ public function initializeDayAction()
{
if ($this->request->hasArgument('day') === false) {
$this->request->setArguments([
'day' => new \DateTimeImmutable(),
'day' => [
'day' => date('Y-m-d'),
],
]);
}

Expand Down
22 changes: 22 additions & 0 deletions Tests/Fixtures/BasicDatabase.xml
@@ -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 changes: 32 additions & 0 deletions Tests/Fixtures/Sites/default/config.yaml
@@ -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 changes: 17 additions & 0 deletions Tests/Fixtures/calendar_example/Configuration/Services.yaml
@@ -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,13 @@
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 changes: 21 additions & 0 deletions Tests/Fixtures/calendar_example/composer.json
@@ -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 changes: 21 additions & 0 deletions Tests/Fixtures/calendar_example/ext_emconf.php
@@ -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 changes: 18 additions & 0 deletions Tests/Fixtures/calendar_example/ext_localconf.php
@@ -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
);
})();

0 comments on commit 100135e

Please sign in to comment.