‪TYPO3CMS  11.5
CObjectViewHelperTest.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 
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
23 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
24 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
25 
29 class ‪CObjectViewHelperTest extends FunctionalTestCase
30 {
32 
33  protected const ‪LANGUAGE_PRESETS = [];
34 
38  protected function ‪setUp(): void
39  {
40  parent::setUp();
41  $this->importCSVDataSet(__DIR__ . '/../Fixtures/pages.csv');
43  'test',
44  $this->‪buildSiteConfiguration(1, '/'),
45  );
46  }
47 
48  protected function ‪tearDown(): void
49  {
50  // @todo: When a FE sub request throws an exception, as some of the below test do, TSFE does NOT release locks properly!
51  ‪$GLOBALS['TSFE']->releaseLocks();
52  parent::tearDown();
53  }
54 
58  public function ‪viewHelperAcceptsDataParameter(): void
59  {
60  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
61  'pid' => 1,
62  'root' => 1,
63  'clear' => 1,
64  'config' => <<<EOT
65 page = PAGE
66 page.10 = FLUIDTEMPLATE
67 page.10 {
68  template = TEXT
69  template.value = <f:cObject typoscriptObjectPath="lib.test" data="foo" />
70 }
71 lib.test = TEXT
72 lib.test.current = 1
73 EOT
74  ]);
75  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
76  self::assertStringContainsString('foo', (string)$response->getBody());
77  }
78 
82  public function viewHelperAcceptsChildrenClosureAsData(): void
83  {
84  (new ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
85  'pid' => 1,
86  'root' => 1,
87  'clear' => 1,
88  'config' => <<<EOT
89 page = PAGE
90 page.10 = FLUIDTEMPLATE
91 page.10 {
92  template = TEXT
93  template.value = <f:cObject typoscriptObjectPath="lib.test">foo</f:cObject>
94 }
95 lib.test = TEXT
96 lib.test.current = 1
97 EOT
98  ]);
99  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
100  self::assertStringContainsString('foo', (string)$response->getBody());
101  }
102 
106  public function renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(): void
107  {
108  (new ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
109  'pid' => 1,
110  'root' => 1,
111  'clear' => 1,
112  'config' => <<<EOT
113 page = PAGE
114 page.10 = FLUIDTEMPLATE
115 page.10 {
116  template = TEXT
117  template.value = <f:cObject typoscriptObjectPath="doesNotExist" />
118 }
119 EOT
120  ]);
121  $this->expectException(Exception::class);
122  $this->expectExceptionCode(1540246570);
123  $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
124  }
125 
129  public function renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist(): void
130  {
131  (new ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
132  'pid' => 1,
133  'root' => 1,
134  'clear' => 1,
135  'config' => <<<EOT
136 page = PAGE
137 page.10 = FLUIDTEMPLATE
138 page.10 {
139  template = TEXT
140  template.value = <f:cObject typoscriptObjectPath="does.not.exist" />
141 }
142 EOT
143  ]);
144  $this->expectException(Exception::class);
145  $this->expectExceptionCode(1253191023);
146  $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
147  }
148 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:36
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsChildrenClosureAsData
‪viewHelperAcceptsChildrenClosureAsData()
Definition: CObjectViewHelperTest.php:81
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:58
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest
Definition: CObjectViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: CObjectViewHelperTest.php:32
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist()
Definition: CObjectViewHelperTest.php:128
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪array buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:111
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\tearDown
‪tearDown()
Definition: CObjectViewHelperTest.php:47
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsDataParameter
‪viewHelperAcceptsDataParameter()
Definition: CObjectViewHelperTest.php:57
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist()
Definition: CObjectViewHelperTest.php:105
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\setUp
‪setUp()
Definition: CObjectViewHelperTest.php:37