Add features to build an archive (#8)

* Add context to factory
* Allow configuring default arguments if missing in request
* Add plugin name to AssignTemplateVariables event
This commit is contained in:
Daniel Siepmann 2023-01-04 08:42:36 +01:00 committed by GitHub
parent 77dd56ad43
commit f1d9466045
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 684 additions and 20 deletions

View file

@ -21,11 +21,15 @@ namespace WerkraumMedia\Calendar\Controller\Frontend;
* 02110-1301, USA. * 02110-1301, USA.
*/ */
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Annotation as Extbase; use TYPO3\CMS\Extbase\Annotation as Extbase;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter; use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
use WerkraumMedia\Calendar\Domain\Model\Context;
use WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory;
use WerkraumMedia\Calendar\Domain\Model\Day; use WerkraumMedia\Calendar\Domain\Model\Day;
use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory;
use WerkraumMedia\Calendar\Domain\Model\Month; use WerkraumMedia\Calendar\Domain\Model\Month;
use WerkraumMedia\Calendar\Domain\Model\Week; use WerkraumMedia\Calendar\Domain\Model\Week;
use WerkraumMedia\Calendar\Domain\Model\Year; use WerkraumMedia\Calendar\Domain\Model\Year;
@ -33,12 +37,39 @@ use WerkraumMedia\Calendar\Events\AssignTemplateVariables;
class CalendarController extends ActionController class CalendarController extends ActionController
{ {
/**
* @var ForeignDataFactory
*/
private $foreignDataFactory;
/**
* @var TypoScriptService
*/
private $typoScriptService;
public function __construct(
ForeignDataFactory $foreignDataFactory,
TypoScriptService $typoScriptService
) {
$this->foreignDataFactory = $foreignDataFactory;
$this->typoScriptService = $typoScriptService;
}
public function initializeAction()
{
if ($this->foreignDataFactory instanceof ContextSpecificFactory) {
$this->foreignDataFactory->setContext(
Context::createFromContentObjectRenderer($this->configurationManager->getContentObject())
);
}
}
public function initializeYearAction() public function initializeYearAction()
{ {
if ($this->request->hasArgument('year') === false) { if ($this->request->hasArgument('year') === false) {
$this->request->setArguments([ $this->request->setArguments([
'year' => [ 'year' => [
'year' => date('Y'), 'year' => $this->getDefaultArgumentValue('year'),
], ],
]); ]);
} }
@ -63,8 +94,8 @@ class CalendarController extends ActionController
if ($this->request->hasArgument('month') === false) { if ($this->request->hasArgument('month') === false) {
$this->request->setArguments([ $this->request->setArguments([
'month' => [ 'month' => [
'month' => date('m'), 'month' => $this->getDefaultArgumentValue('month'),
'year' => date('Y'), 'year' => $this->getDefaultArgumentValue('year'),
], ],
]); ]);
} }
@ -89,8 +120,8 @@ class CalendarController extends ActionController
if ($this->request->hasArgument('week') === false) { if ($this->request->hasArgument('week') === false) {
$this->request->setArguments([ $this->request->setArguments([
'week' => [ 'week' => [
'week' => date('W'), 'week' => $this->getDefaultArgumentValue('week'),
'year' => date('Y'), 'year' => $this->getDefaultArgumentValue('year'),
], ],
]); ]);
} }
@ -115,7 +146,7 @@ class CalendarController extends ActionController
if ($this->request->hasArgument('day') === false) { if ($this->request->hasArgument('day') === false) {
$this->request->setArguments([ $this->request->setArguments([
'day' => [ 'day' => [
'day' => date('Y-m-d'), 'day' => $this->getDefaultArgumentValue('day'),
], ],
]); ]);
} }
@ -145,8 +176,38 @@ class CalendarController extends ActionController
private function assignVariables(array $variables): void private function assignVariables(array $variables): void
{ {
$event = GeneralUtility::makeInstance(AssignTemplateVariables::class, $variables); $event = GeneralUtility::makeInstance(
AssignTemplateVariables::class,
$variables,
$this->request->getPluginName()
);
$this->eventDispatcher->dispatch($event); $this->eventDispatcher->dispatch($event);
$this->view->assignMultiple($event->getVariables()); $this->view->assignMultiple($event->getVariables());
} }
/**
* Checks for TypoScript and transforms TypoScript into expected value.
* Allows to define defaults other than "now" for arguments.
*/
private function getDefaultArgumentValue(string $argumentName): string
{
$arguments = $this->typoScriptService->convertPlainArrayToTypoScriptArray(
$this->settings['arguments'] ?? []
);
$fallbackValues = [
'year' => date('Y'),
'month' => date('m'),
'week' => date('W'),
'day' => date('Y-m-d'),
];
$value = $this->configurationManager->getContentObject()->stdWrapValue(
$argumentName,
$arguments,
$fallbackValues[$argumentName]
);
return $value;
}
} }

View file

@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2021 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\Domain\Model;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
class Context
{
/**
* @var string
*/
protected $tableName = '';
/**
* @var array
*/
protected $databaseRow = [];
private function __construct()
{
}
public static function createFromContentObjectRenderer(
ContentObjectRenderer $contentObjectRenderer
): self {
$instance = new self();
$instance->tableName = $contentObjectRenderer->getCurrentTable();
$instance->databaseRow = $contentObjectRenderer->data;
return $instance;
}
public function getTableName(): string
{
return $this->tableName;
}
public function getDatabaseRow(): array
{
return $this->databaseRow;
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace WerkraumMedia\Calendar\Domain\Model;
/*
* 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.
*/
interface ContextSpecificFactory
{
/**
* Might be called prior ot getData().
* Allows getData() to know the current context and make decisions.
*/
public function setContext(Context $context): void;
}

View file

@ -85,5 +85,6 @@ class Day
$this->foreignData = GeneralUtility::makeInstance(ForeignDataFactory::class) $this->foreignData = GeneralUtility::makeInstance(ForeignDataFactory::class)
->getData($this); ->getData($this);
$this->initialized = true;
} }
} }

View file

@ -28,10 +28,22 @@ final class AssignTemplateVariables
*/ */
private $variables; private $variables;
/**
* @var string
*/
private $pluginName;
public function __construct( public function __construct(
array $variables array $variables,
string $pluginName
) { ) {
$this->variables = $variables; $this->variables = $variables;
$this->pluginName = $pluginName;
}
public function getPluginName(): string
{
return $this->pluginName;
} }
public function getVariables(): array public function getVariables(): array

View file

@ -0,0 +1,13 @@
.. _changelog:
=========
Changelog
=========
.. toctree::
:glob:
:reversed:
Changelog/*

View file

@ -0,0 +1,58 @@
1.1.0
=====
Breaking
--------
Nothing
Features
--------
* Add context to foreign data factory.
The factory can optionally implement the ``WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory`` interface.
That way it will receive a bit of context to react on the current situation.
* Add Extbase Settings to configure default arguments for each action:
.. code-block:: typoscript
plugin.tx_calendar_example {
settings {
arguments {
year = 1988
month = 11
week = 12
day = 1988-11-03
}
}
}
StdWrap is applied, so more complex setups are possible, e.g.:
.. code-block:: typoscript
arguments {
year {
strtotime = midnight first day of -1 year
strftime = %Y
}
}
* The current plugin name is available to the ``AssignTemplateVariables`` event.
Fixes
-----
Nothing
Tasks
-----
Nothing
Deprecation
-----------
Nothing

15
Documentation/Index.rst Normal file
View file

@ -0,0 +1,15 @@
.. _start:
============
EXT:calendar
============
Table of Contents
=================
.. toctree::
:maxdepth: 1
:titlesonly:
Changelog
Sitemap

View file

@ -0,0 +1,49 @@
[general]
# .................................................................................
# ... (required) title (displayed in left sidebar (desktop) or top panel (mobile)
# .................................................................................
project = TYPO3 EXT:calendar
# .................................................................................
# ... (recommended) version, displayed next to title (desktop) and in <meta name="book-version"
# .................................................................................
release = latest
# .................................................................................
# ... (recommended) displayed in footer
# .................................................................................
copyright = by werkraum-media
[html_theme_options]
# .................................................................................
# ... (recommended) to get the "Edit me on Github Button"
# .................................................................................
github_branch = main
github_repository = werkraum-media/calendar
# usually an email address
project_contact = coding@daniel-siepmann.de
# URL of online discussions, you can leave this blank
project_discussions =
# URL of webpage of your extension (if it has one)
project_home = https://github.com/werkraum-media/calendar
# URL to Issues
project_issues = https://github.com/werkraum-media/calendar/issues
# URL of repository
project_repository = https://github.com/werkraum-media/calendar
[intersphinx_mapping]
# .................................................................................
# for cross-referencing across manuals (intersphinx) with :ref:
# You must uncomment all manuals you use in your cross-references
#
# Example usage:
# :ref:`t3contribute:start` will link to start page of Contribution Guide
# .................................................................................

View file

@ -0,0 +1,9 @@
:template: sitemap.html
.. _sitemap:
=======
Sitemap
=======
.. template 'sitemap.html' will insert the toctree as a sitemap here below normal contents

View file

@ -9,3 +9,22 @@ Provides:
Each day can have foreign data created by a factory. Each day can have foreign data created by a factory.
That way extensions or TYPO3 instances can add further data to each day. That way extensions or TYPO3 instances can add further data to each day.
Configuration
-------------
Allows to configure default values for arguments if not provided in current request.
Each argument is configured below TypoScript settings namespace `arguments`, e.g.::
tx_calendar_example {
settings {
arguments {
year {
strtotime = midnight first day of -1 year
strftime = %Y
}
}
}
}
Supported arguments are: `year`, `month`, `week` and `day`.

View file

@ -23,15 +23,31 @@ declare(strict_types=1);
namespace WerkraumMedia\CalendarExample\Domain; namespace WerkraumMedia\CalendarExample\Domain;
use WerkraumMedia\Calendar\Domain\Model\Context;
use WerkraumMedia\Calendar\Domain\Model\ContextSpecificFactory;
use WerkraumMedia\Calendar\Domain\Model\Day; use WerkraumMedia\Calendar\Domain\Model\Day;
use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory; use WerkraumMedia\Calendar\Domain\Model\ForeignDataFactory;
class ExampleDataFactory implements ForeignDataFactory class ExampleDataFactory implements ForeignDataFactory, ContextSpecificFactory
{ {
/**
* @var Context
*/
private $context;
public function setContext(Context $context): void
{
$this->context = $context;
}
public function getData(Day $day) public function getData(Day $day)
{ {
return [ return [
'exampleKey' => 'exampleValue', 'exampleKey' => 'exampleValue',
'context' => [
'tableName' => $this->context->getTableName(),
'databaseRow' => $this->context->getDatabaseRow(),
],
]; ];
} }
} }

View file

@ -30,6 +30,7 @@ class AssignTemplateVariables
public function __invoke(AssignTemplateVariablesEvent $event): void public function __invoke(AssignTemplateVariablesEvent $event): void
{ {
$event->setVariables(array_merge($event->getVariables(), [ $event->setVariables(array_merge($event->getVariables(), [
'pluginName' => $event->getPluginName(),
'customVariable' => 'modifiedVariable', 'customVariable' => 'modifiedVariable',
])); ]));
} }

View file

@ -10,3 +10,16 @@ page = PAGE
page { page {
10 =< tt_content.calendar_example.20 10 =< tt_content.calendar_example.20
} }
[request.getQueryParams()['typoScriptDefaults'] == 1]
plugin.tx_calendar_example {
settings {
arguments {
year = 1988
month = 11
week = 12
day = 1988-11-03
}
}
}
[GLOBAL]

View file

@ -5,6 +5,9 @@
<h2>{day.dateTimeInstance -> f:format.date(format: 'd.m.Y')}</h2> <h2>{day.dateTimeInstance -> f:format.date(format: 'd.m.Y')}</h2>
{day.foreignData.exampleKey} {day.foreignData.exampleKey}
Table: {day.foreignData.context.tableName}
Title: {day.foreignData.context.databaseRow.title}
{customVariable} {customVariable}
PluginName: {pluginName}
</html> </html>

View file

@ -7,8 +7,11 @@
<f:for each="{week.days}" as="day"> <f:for each="{week.days}" as="day">
{day.dateTimeInstance -> f:format.date(format: 'd')} {day.dateTimeInstance -> f:format.date(format: 'd')}
{day.foreignData.exampleKey} {day.foreignData.exampleKey}
Table: {day.foreignData.context.tableName}
Title: {day.foreignData.context.databaseRow.title}
</f:for> </f:for>
</f:for> </f:for>
{customVariable} {customVariable}
PluginName: {pluginName}
</html> </html>

View file

@ -6,7 +6,10 @@
<f:for each="{week.days}" as="day"> <f:for each="{week.days}" as="day">
{day.dateTimeInstance -> f:format.date(format: 'd')} {day.dateTimeInstance -> f:format.date(format: 'd')}
{day.foreignData.exampleKey} {day.foreignData.exampleKey}
Table: {day.foreignData.context.tableName}
Title: {day.foreignData.context.databaseRow.title}
</f:for> </f:for>
{customVariable} {customVariable}
PluginName: {pluginName}
</html> </html>

View file

@ -8,9 +8,12 @@
<f:for each="{week.days}" as="day"> <f:for each="{week.days}" as="day">
{day.dateTimeInstance -> f:format.date(format: 'd')} {day.dateTimeInstance -> f:format.date(format: 'd')}
{day.foreignData.exampleKey} {day.foreignData.exampleKey}
Table: {day.foreignData.context.tableName}
Title: {day.foreignData.context.databaseRow.title}
</f:for> </f:for>
</f:for> </f:for>
</f:for> </f:for>
{customVariable} {customVariable}
PluginName: {pluginName}
</html> </html>

View file

@ -67,6 +67,35 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertStringContainsString('modifiedVariable', $html); self::assertStringContainsString('modifiedVariable', $html);
} }
/**
* @test
*/
public function pluginNameForCurrentDay(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('PluginName: Example', $html);
}
/**
* @test
*/
public function contextForCurrentDay(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('Table: pages', $html);
self::assertStringContainsString('Title: Page Title', $html);
}
/** /**
* @test * @test
*/ */
@ -85,7 +114,22 @@ class CalendarControllerTest extends FunctionalTestCase
/** /**
* @test * @test
*/ */
public function customDataForProvidedDay(): void public function configuredDay(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$request = $request->withQueryParameter('typoScriptDefaults', '1');
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('03.11.1988', $html);
}
/**
* @test
*/
public function providedDay(): void
{ {
$request = new InternalRequest(); $request = new InternalRequest();
$request = $request->withPageId(1); $request = $request->withPageId(1);
@ -95,7 +139,6 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertSame(200, $result->getStatusCode()); self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString(); $html = $result->getBody()->__toString();
self::assertStringContainsString('03.11.2020', $html); self::assertStringContainsString('03.11.2020', $html);
self::assertStringContainsString('exampleValue', $html);
} }
/** /**
@ -113,6 +156,37 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertStringContainsString('modifiedVariable', $html); self::assertStringContainsString('modifiedVariable', $html);
} }
/**
* @test
*/
public function pluginNameForCurrentWeek(): 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('PluginName: Example', $html);
}
/**
* @test
*/
public function contextForCurrentWeek(): 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('Table: pages', $html);
self::assertStringContainsString('Title: Page Title', $html);
}
/** /**
* @test * @test
*/ */
@ -132,7 +206,23 @@ class CalendarControllerTest extends FunctionalTestCase
/** /**
* @test * @test
*/ */
public function customDataForProvidedWeek(): void public function configuredWeek(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$request = $request->withQueryParameter('tx_calendar_example[action]', 'week');
$request = $request->withQueryParameter('typoScriptDefaults', '1');
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('12 1988', $html);
}
/**
* @test
*/
public function providedWeek(): void
{ {
$request = new InternalRequest(); $request = new InternalRequest();
$request = $request->withPageId(1); $request = $request->withPageId(1);
@ -144,7 +234,6 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertSame(200, $result->getStatusCode()); self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString(); $html = $result->getBody()->__toString();
self::assertStringContainsString('02 2020', $html); self::assertStringContainsString('02 2020', $html);
self::assertStringContainsString('exampleValue', $html);
} }
/** /**
@ -162,6 +251,37 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertStringContainsString('modifiedVariable', $html); self::assertStringContainsString('modifiedVariable', $html);
} }
/**
* @test
*/
public function pluginNameForCurrentMonth(): 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('PluginName: Example', $html);
}
/**
* @test
*/
public function contextForCurrentMonth(): 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('Table: pages', $html);
self::assertStringContainsString('Title: Page Title', $html);
}
/** /**
* @test * @test
*/ */
@ -181,7 +301,23 @@ class CalendarControllerTest extends FunctionalTestCase
/** /**
* @test * @test
*/ */
public function customDataForProvidedMonth(): void public function configuredMonth(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$request = $request->withQueryParameter('tx_calendar_example[action]', 'month');
$request = $request->withQueryParameter('typoScriptDefaults', '1');
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('November 1988', $html);
}
/**
* @test
*/
public function providedMonth(): void
{ {
$request = new InternalRequest(); $request = new InternalRequest();
$request = $request->withPageId(1); $request = $request->withPageId(1);
@ -211,6 +347,37 @@ class CalendarControllerTest extends FunctionalTestCase
self::assertStringContainsString('modifiedVariable', $html); self::assertStringContainsString('modifiedVariable', $html);
} }
/**
* @test
*/
public function pluginNameForCurrentYear(): 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('PluginName: Example', $html);
}
/**
* @test
*/
public function contextForCurrentYear(): 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('Table: pages', $html);
self::assertStringContainsString('Title: Page Title', $html);
}
/** /**
* @test * @test
*/ */
@ -230,7 +397,23 @@ class CalendarControllerTest extends FunctionalTestCase
/** /**
* @test * @test
*/ */
public function customDataForProvidedYear(): void public function configuredYear(): void
{
$request = new InternalRequest();
$request = $request->withPageId(1);
$request = $request->withQueryParameter('tx_calendar_example[action]', 'year');
$request = $request->withQueryParameter('typoScriptDefaults', '1');
$result = $this->executeFrontendRequest($request);
self::assertSame(200, $result->getStatusCode());
$html = $result->getBody()->__toString();
self::assertStringContainsString('1988', $html);
}
/**
* @test
*/
public function providedYear(): void
{ {
$request = new InternalRequest(); $request = new InternalRequest();
$request = $request->withPageId(1); $request = $request->withPageId(1);

View file

@ -0,0 +1,88 @@
<?php
declare(strict_types=1);
/*
* Copyright (C) 2021 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\Unit\Domain\Model;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use WerkraumMedia\Calendar\Domain\Model\Context;
/**
* @covers \WerkraumMedia\Calendar\Domain\Model\Context
*/
class ContextTest extends TestCase
{
use ProphecyTrait;
/**
* @test
*/
public function canNotBeCreatedViaNew(): void
{
$this->expectError();
$this->expectErrorMessage('Call to private WerkraumMedia\Calendar\Domain\Model\Context::__construct() from context \'WerkraumMedia\Calendar\Tests\Unit\Domain\Model\ContextTest\'');
$subject = new Context();
}
/**
* @test
*/
public function canBeCreatedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
self::assertInstanceOf(Context::class, $subject);
}
/**
* @test
*/
public function providesTableNameInheritedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRenderer->getCurrentTable()->willReturn('tx_calendar_example_table');
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
self::assertSame('tx_calendar_example_table', $subject->getTableName());
}
/**
* @test
*/
public function providesDatabaseRowInheritedFromContentObjectRenderer(): void
{
$contentObjectRenderer = $this->prophesize(ContentObjectRenderer::class);
$contentObjectRenderer->data = [
'uid' => 10,
'pid' => 1,
];
$subject = Context::createFromContentObjectRenderer($contentObjectRenderer->reveal());
self::assertSame([
'uid' => 10,
'pid' => 1,
], $subject->getDatabaseRow());
}
}

View file

@ -35,12 +35,28 @@ class AssignTemplateVariablesTest extends TestCase
public function canBeCreated(): void public function canBeCreated(): void
{ {
$subject = new AssignTemplateVariables( $subject = new AssignTemplateVariables(
[] [],
''
); );
self::assertInstanceOf(AssignTemplateVariables::class, $subject); self::assertInstanceOf(AssignTemplateVariables::class, $subject);
} }
/**
* @test
*/
public function returnsPluginName(): void
{
$subject = new AssignTemplateVariables(
[],
'Example'
);
$result = $subject->getPluginName();
self::assertSame('Example', $result);
}
/** /**
* @test * @test
*/ */
@ -49,7 +65,8 @@ class AssignTemplateVariablesTest extends TestCase
$subject = new AssignTemplateVariables( $subject = new AssignTemplateVariables(
[ [
'variable1' => 'value1', 'variable1' => 'value1',
] ],
''
); );
$result = $subject->getVariables(); $result = $subject->getVariables();
@ -67,7 +84,8 @@ class AssignTemplateVariablesTest extends TestCase
$subject = new AssignTemplateVariables( $subject = new AssignTemplateVariables(
[ [
'variable1' => 'value1', 'variable1' => 'value1',
] ],
''
); );
$subject->setVariables([ $subject->setVariables([

View file

@ -15,7 +15,8 @@
"require": { "require": {
"php": "^7.3.0 || ^7.4.0", "php": "^7.3.0 || ^7.4.0",
"typo3/cms-core": "^10.4", "typo3/cms-core": "^10.4",
"typo3/cms-extbase": "^10.4" "typo3/cms-extbase": "^10.4",
"typo3/cms-frontend": "^10.4"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View file

@ -10,7 +10,7 @@ $EM_CONF['calendar'] = [
'state' => 'alpha', 'state' => 'alpha',
'uploadfolder' => 0, 'uploadfolder' => 0,
'clearCacheOnLoad' => 0, 'clearCacheOnLoad' => 0,
'version' => '1.0.0', 'version' => '1.1.0',
'constraints' => [ 'constraints' => [
'depends' => [ 'depends' => [
'typo3' => '*', 'typo3' => '*',