‪TYPO3CMS  11.5
FluidTemplateContentObjectTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Prophecy\PhpUnit\ProphecyTrait;
21 use Psr\Http\Message\ServerRequestInterface;
23 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 class ‪FluidTemplateContentObjectTest extends FunctionalTestCase
30 {
31  use ProphecyTrait;
32 
36  protected ‪$initializeDatabase = false;
37 
38  protected ‪$testExtensionsToLoad = [
39  'typo3/sysext/fluid/Tests/Functional/Fixtures/Extensions/fluid_test',
40  ];
41 
45  public function ‪renderWorksWithNestedFluidtemplate(): void
46  {
47  $tsfe = $this->createMock(TypoScriptFrontendController::class);
48  ‪$GLOBALS['TSFE'] = $tsfe;
49 
50  $configuration = [
51  '10' => 'FLUIDTEMPLATE',
52  '10.' => [
53  'template' => 'TEXT',
54  'template.' => [
55  'value' => 'A{anotherFluidTemplate}C',
56  ],
57  'variables.' => [
58  'anotherFluidTemplate' => 'FLUIDTEMPLATE',
59  'anotherFluidTemplate.' => [
60  'template' => 'TEXT',
61  'template.' => [
62  'value' => 'B',
63  ],
64  ],
65  ],
66  ],
67  ];
68  $expectedResult = 'ABC';
69 
70  $contentObjectRenderer = new ContentObjectRenderer();
71  $contentObjectRenderer->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
72  $contentObjectRenderer->setContentObjectClassMap([
73  'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
74  'TEXT' => TextContentObject::class,
75  ]);
76  $fluidTemplateContentObject = new ‪ContentObjectArrayContentObject(
77  $contentObjectRenderer
78  );
79  $result = $fluidTemplateContentObject->render($configuration);
80 
81  self::assertEquals($expectedResult, $result);
82  }
83 
88  {
89  $tsfe = $this->createMock(TypoScriptFrontendController::class);
90  ‪$GLOBALS['TSFE'] = $tsfe;
91 
92  $configuration = [
93  '10' => 'FLUIDTEMPLATE',
94  '10.' => [
95  'template' => 'TEXT',
96  'template.' => [
97  'value' => '<f:layout name="BaseLayout"/><f:section name="main"><f:format.raw>{anotherFluidTemplate}</f:format.raw></f:section>',
98  ],
99  'layoutRootPaths.' => [
100  '0' => 'EXT:fluid_test/Resources/Private/Layouts',
101  ],
102  'variables.' => [
103  'anotherFluidTemplate' => 'FLUIDTEMPLATE',
104  'anotherFluidTemplate.' => [
105  'template' => 'TEXT',
106  'template.' => [
107  'value' => '<f:layout name="BaseLayout"/><f:section name="main"></f:section>',
108  ],
109  'layoutRootPaths.' => [
110  '0' => 'EXT:fluid_test/Resources/Private/LayoutOverride/Layouts',
111  ],
112  ],
113  ],
114  ],
115  ];
116  $expectedResult = 'DefaultLayoutLayoutOverride';
117 
118  $contentObjectRenderer = new ContentObjectRenderer();
119  $contentObjectRenderer->setRequest($this->prophesize(ServerRequestInterface::class)->reveal());
120  $contentObjectRenderer->setContentObjectClassMap([
121  'FLUIDTEMPLATE' => FluidTemplateContentObject::class,
122  'TEXT' => TextContentObject::class,
123  ]);
124  $fluidTemplateContentObject = new ‪ContentObjectArrayContentObject(
125  $contentObjectRenderer
126  );
127  $result = preg_replace('/\s+/', '', strip_tags($fluidTemplateContentObject->render($configuration)));
128 
129  self::assertEquals($expectedResult, $result);
130  }
131 }
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\FluidTemplateContentObjectTest\renderWorksWithNestedFluidtemplate
‪renderWorksWithNestedFluidtemplate()
Definition: FluidTemplateContentObjectTest.php:43
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\FluidTemplateContentObjectTest\$testExtensionsToLoad
‪$testExtensionsToLoad
Definition: FluidTemplateContentObjectTest.php:36
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\FluidTemplateContentObjectTest\renderWorksWithNestedFluidtemplateWithLayouts
‪renderWorksWithNestedFluidtemplateWithLayouts()
Definition: FluidTemplateContentObjectTest.php:85
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\FluidTemplateContentObjectTest\$initializeDatabase
‪bool $initializeDatabase
Definition: FluidTemplateContentObjectTest.php:34
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject\FluidTemplateContentObjectTest
Definition: FluidTemplateContentObjectTest.php:30
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectArrayContentObject
Definition: ContentObjectArrayContentObject.php:26
‪TYPO3\CMS\Frontend\ContentObject\FluidTemplateContentObject
Definition: FluidTemplateContentObject.php:29
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:104
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\ContentObject\TextContentObject
Definition: TextContentObject.php:22
‪TYPO3\CMS\Frontend\Tests\Functional\ContentObject
Definition: ContentObjectRendererTest.php:18