‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\Test;
23 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
26 
27 final class ‪CObjectViewHelperTest extends FunctionalTestCase
28 {
30 
31  protected const ‪LANGUAGE_PRESETS = [
32  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
33  ];
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  #[Test]
49  public function ‪viewHelperAcceptsDataParameter(): void
50  {
51  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
52  'pid' => 1,
53  'root' => 1,
54  'clear' => 1,
55  'config' => <<<EOT
56 page = PAGE
57 page.10 = FLUIDTEMPLATE
58 page.10 {
59  template = TEXT
60  template.value = <f:cObject typoscriptObjectPath="lib.test" data="foo" />
61 }
62 lib.test = TEXT
63 lib.test.current = 1
64 EOT
65  ]);
66  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
67  self::assertStringContainsString('foo', (string)$response->getBody());
68  }
69 
70  #[Test]
71  public function viewHelperAcceptsChildrenClosureAsData(): void
72  {
73  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
74  'pid' => 1,
75  'root' => 1,
76  'clear' => 1,
77  'config' => <<<EOT
78 page = PAGE
79 page.10 = FLUIDTEMPLATE
80 page.10 {
81  template = TEXT
82  template.value = <f:cObject typoscriptObjectPath="lib.test">foo</f:cObject>
83 }
84 lib.test = TEXT
85 lib.test.current = 1
86 EOT
87  ]);
88  $response = $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
89  self::assertStringContainsString('foo', (string)$response->getBody());
90  }
91 
92  #[Test]
93  public function renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist(): void
94  {
95  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
96  'pid' => 1,
97  'root' => 1,
98  'clear' => 1,
99  'config' => <<<EOT
100 page = PAGE
101 page.10 = FLUIDTEMPLATE
102 page.10 {
103  template = TEXT
104  template.value = <f:cObject typoscriptObjectPath="doesNotExist" />
105 }
106 EOT
107  ]);
108  $this->expectException(Exception::class);
109  $this->expectExceptionCode(1540246570);
110  $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
111  }
112 
113  #[Test]
114  public function renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist(): void
115  {
116  (new ‪ConnectionPool())->getConnectionForTable('sys_template')->insert('sys_template', [
117  'pid' => 1,
118  'root' => 1,
119  'clear' => 1,
120  'config' => <<<EOT
121 page = PAGE
122 page.10 = FLUIDTEMPLATE
123 page.10 {
124  template = TEXT
125  template.value = <f:cObject typoscriptObjectPath="does.not.exist" />
126 }
127 EOT
128  ]);
129  $this->expectException(Exception::class);
130  $this->expectExceptionCode(1253191023);
131  $this->executeFrontendSubRequest((new InternalRequest())->withPageId(1));
132  }
133 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsChildrenClosureAsData
‪viewHelperAcceptsChildrenClosureAsData()
Definition: CObjectViewHelperTest.php:70
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest
Definition: CObjectViewHelperTest.php:28
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: CObjectViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfNestedTypoScriptObjectPathDoesNotExist()
Definition: CObjectViewHelperTest.php:113
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\viewHelperAcceptsDataParameter
‪viewHelperAcceptsDataParameter()
Definition: CObjectViewHelperTest.php:48
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist
‪renderThrowsExceptionIfTypoScriptObjectPathDoesNotExist()
Definition: CObjectViewHelperTest.php:92
‪TYPO3\CMS\Fluid\Tests\Functional\ViewHelpers\CObjectViewHelperTest\setUp
‪setUp()
Definition: CObjectViewHelperTest.php:37