/
FluidTemplateContentObjectTest.php
130 lines (118 loc) · 4.68 KB
/
FluidTemplateContentObjectTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
* 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\Frontend\Tests\Functional\ContentObject;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject;
use TYPO3\CMS\Frontend\ContentObject\TextContentObject;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* Test case
*/
class FluidTemplateContentObjectTest extends FunctionalTestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
/**
* @var array
*/
protected $testExtensionsToLoad = [
'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
];
/**
* @test
*/
public function renderWorksWithNestedFluidtemplate()
{
/** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
$tsfe = $this->createMock(TypoScriptFrontendController::class);
$GLOBALS['TSFE'] = $tsfe;
$configuration = [
'10' => 'FLUIDTEMPLATE',
'10.' => [
'template' => 'TEXT',
'template.' => [
'value' => 'A{anotherFluidTemplate}C'
],
'variables.' => [
'anotherFluidTemplate' => 'FLUIDTEMPLATE',
'anotherFluidTemplate.' => [
'template' => 'TEXT',
'template.' => [
'value' => 'B',
],
],
],
],
];
$expectedResult = 'ABC';
$contentObjectRenderer = new ContentObjectRenderer();
$contentObjectRenderer->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
$contentObjectRenderer->setContentObjectClassMap([
'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
'TEXT' => TextContentObject::class,
]);
$fluidTemplateContentObject = new ContentObjectArrayContentObject(
$contentObjectRenderer
);
$result = $fluidTemplateContentObject->render($configuration);
self::assertEquals($expectedResult, $result);
}
/**
* @test
*/
public function renderWorksWithNestedFluidtemplateWithLayouts()
{
/** @var $tsfe \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController */
$tsfe = $this->createMock(TypoScriptFrontendController::class);
$GLOBALS['TSFE'] = $tsfe;
$configuration = [
'10' => 'FLUIDTEMPLATE',
'10.' => [
'template' => 'TEXT',
'template.' => [
'value' => '<f:layout name="BaseLayout"/><f:section name="main"><f:format.raw>{anotherFluidTemplate}</f:format.raw></f:section>'
],
'layoutRootPaths.' => [
'0' => 'EXT:fluid_test/Resources/Private/Layouts'
],
'variables.' => [
'anotherFluidTemplate' => 'FLUIDTEMPLATE',
'anotherFluidTemplate.' => [
'template' => 'TEXT',
'template.' => [
'value' => '<f:layout name="BaseLayout"/><f:section name="main"></f:section>'
],
'layoutRootPaths.' => [
'0' => 'EXT:fluid_test/Resources/Private/LayoutOverride/Layouts'
],
],
],
],
];
$expectedResult = 'DefaultLayoutLayoutOverride';
$contentObjectRenderer = new ContentObjectRenderer();
$contentObjectRenderer->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
$contentObjectRenderer->setContentObjectClassMap([
'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
'TEXT' => TextContentObject::class,
]);
$fluidTemplateContentObject = new ContentObjectArrayContentObject(
$contentObjectRenderer
);
$result = preg_replace('/\s+/', '', strip_tags($fluidTemplateContentObject->render($configuration)));
self::assertEquals($expectedResult, $result);
}
}