Skip to content
Snippets Groups Projects
Commit fff914b5 authored by Simon Praetorius's avatar Simon Praetorius
Browse files

[TASK] Add test coverage for EmailFinisher TemplatePaths

In preparation for a refactoring, test coverage is added to
the existing path merging code.

Resolves: #104862
Releases: main
Change-Id: I9f92108d565b01e3177341ef7cd0b3f25529bf91
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/85928


Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarSimon Praetorius <simon@praetorius.me>
Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Tested-by: default avatarSimon Praetorius <simon@praetorius.me>
parent b6973235
Branches
Tags
No related merge requests found
......@@ -160,38 +160,42 @@ class EmailFinisher extends AbstractFinisher
GeneralUtility::makeInstance(MailerInterface::class)->send($mail);
}
protected function initializeFluidEmail(FormRuntime $formRuntime): FluidEmail
protected function initializeTemplatePaths(array $globalConfig, array $localConfig): TemplatePaths
{
$templateConfiguration = $GLOBALS['TYPO3_CONF_VARS']['MAIL'];
if (is_array($this->options['templateRootPaths'] ?? null)) {
$templateConfiguration['templateRootPaths'] = array_replace_recursive(
$templateConfiguration['templateRootPaths'],
$this->options['templateRootPaths']
if (is_array($localConfig['templateRootPaths'] ?? null)) {
$globalConfig['templateRootPaths'] = array_replace_recursive(
$globalConfig['templateRootPaths'],
$localConfig['templateRootPaths']
);
ksort($templateConfiguration['templateRootPaths']);
ksort($globalConfig['templateRootPaths']);
}
if (is_array($this->options['partialRootPaths'] ?? null)) {
$templateConfiguration['partialRootPaths'] = array_replace_recursive(
$templateConfiguration['partialRootPaths'],
$this->options['partialRootPaths']
if (is_array($localConfig['partialRootPaths'] ?? null)) {
$globalConfig['partialRootPaths'] = array_replace_recursive(
$globalConfig['partialRootPaths'],
$localConfig['partialRootPaths']
);
ksort($templateConfiguration['partialRootPaths']);
ksort($globalConfig['partialRootPaths']);
}
if (is_array($this->options['layoutRootPaths'] ?? null)) {
$templateConfiguration['layoutRootPaths'] = array_replace_recursive(
$templateConfiguration['layoutRootPaths'],
$this->options['layoutRootPaths']
if (is_array($localConfig['layoutRootPaths'] ?? null)) {
$globalConfig['layoutRootPaths'] = array_replace_recursive(
$globalConfig['layoutRootPaths'],
$localConfig['layoutRootPaths']
);
ksort($templateConfiguration['layoutRootPaths']);
ksort($globalConfig['layoutRootPaths']);
}
$fluidEmail = GeneralUtility::makeInstance(
FluidEmail::class,
GeneralUtility::makeInstance(TemplatePaths::class, $templateConfiguration)
return GeneralUtility::makeInstance(TemplatePaths::class, $globalConfig);
}
protected function initializeFluidEmail(FormRuntime $formRuntime): FluidEmail
{
$templatePaths = $this->initializeTemplatePaths(
$GLOBALS['TYPO3_CONF_VARS']['MAIL'],
$this->options,
);
$fluidEmail = GeneralUtility::makeInstance(FluidEmail::class, $templatePaths);
if (!isset($this->options['templateName']) || $this->options['templateName'] === '') {
throw new FinisherException('The option "templateName" must be set to use FluidEmail.', 1599834020);
......
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Form\Tests\Unit\Domain\Finishers;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Form\Domain\Finishers\EmailFinisher;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
final class EmailFinisherTest extends UnitTestCase
{
public static function templatePathsAreMergedCorrectlyDataProvider(): array
{
return [
'default configuration' => [
'globalConfig' => [
'templateRootPaths' => [
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:backend/Resources/Private/Templates/Email/',
],
'layoutRootPaths' => [
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
],
],
'localConfig' => [
'templateRootPaths' => [
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
],
'layoutRootPaths' => [],
'partialRootPaths' => [],
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
],
],
],
'user-defined form templates' => [
'globalConfig' => [
'templateRootPaths' => [
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:backend/Resources/Private/Templates/Email/',
],
'layoutRootPaths' => [
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
],
],
'localConfig' => [
'templateRootPaths' => [
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
20 => 'EXT:myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [],
'partialRootPaths' => [],
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
'EXT:myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
],
],
],
'user-defined global and local templates' => [
'globalConfig' => [
'templateRootPaths' => [
0 => 'EXT:core/Resources/Private/Templates/Email/',
10 => 'EXT:backend/Resources/Private/Templates/Email/',
20 => 'path/to/myextension/Resources/Private/Templates/Email/',
],
'layoutRootPaths' => [
0 => 'EXT:core/Resources/Private/Layouts/',
10 => 'EXT:backend/Resources/Private/Layouts/',
20 => 'path/to/myextension/Resources/Private/Layouts/Email/',
],
'partialRootPaths' => [
0 => 'EXT:core/Resources/Private/Partials/',
10 => 'EXT:backend/Resources/Private/Partials/',
20 => 'path/to/myextension/Resources/Private/Partials/Email/',
],
],
'localConfig' => [
'templateRootPaths' => [
10 => 'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
100 => 'path/to/myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [
100 => 'path/to/myextension/Resources/Private/Layouts/Form/Email/',
],
'partialRootPaths' => [
100 => 'path/to/myextension/Resources/Private/Partials/Form/Email/',
],
],
'expected' => [
'templateRootPaths' => [
'EXT:core/Resources/Private/Templates/Email/',
'EXT:form/Resources/Private/Frontend/Templates/Finishers/Email/',
'path/to/myextension/Resources/Private/Templates/Email/',
'path/to/myextension/Resources/Private/Templates/Form/Email/',
],
'layoutRootPaths' => [
'EXT:core/Resources/Private/Layouts/',
'EXT:backend/Resources/Private/Layouts/',
'path/to/myextension/Resources/Private/Layouts/Email/',
'path/to/myextension/Resources/Private/Layouts/Form/Email/',
],
'partialRootPaths' => [
'EXT:core/Resources/Private/Partials/',
'EXT:backend/Resources/Private/Partials/',
'path/to/myextension/Resources/Private/Partials/Email/',
'path/to/myextension/Resources/Private/Partials/Form/Email/',
],
],
],
];
}
#[Test]
#[DataProvider('templatePathsAreMergedCorrectlyDataProvider')]
public function templatePathsAreMergedCorrectly(array $globalConfig, array $localConfig, array $expected): void
{
$subject = $this->getAccessibleMock(EmailFinisher::class, null, [], '', false);
$templatePaths = $subject->_call('initializeTemplatePaths', $globalConfig, $localConfig);
self::assertSame(array_map(fn($path) => GeneralUtility::getFileAbsFileName($path), $expected['templateRootPaths']), $templatePaths->getTemplateRootPaths());
self::assertSame(array_map(fn($path) => GeneralUtility::getFileAbsFileName($path), $expected['layoutRootPaths']), $templatePaths->getLayoutRootPaths());
self::assertSame(array_map(fn($path) => GeneralUtility::getFileAbsFileName($path), $expected['partialRootPaths']), $templatePaths->getPartialRootPaths());
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment