‪TYPO3CMS  ‪main
CaseContentObjectTest.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;
21 use Symfony\Component\DependencyInjection\Container;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
31 final class ‪CaseContentObjectTest extends UnitTestCase
32 {
33  protected bool ‪$resetSingletonInstances = true;
34 
36 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  $tsfe = $this->getMockBuilder(TypoScriptFrontendController::class)
41  ->onlyMethods([])
42  ->disableOriginalConstructor()
43  ->getMock();
44 
45  $request = new ‪ServerRequest();
46  $contentObjectRenderer = new ‪ContentObjectRenderer($tsfe);
47  $contentObjectRenderer->setRequest($request);
48  $cObjectFactoryMock = $this->getMockBuilder(ContentObjectFactory::class)->disableOriginalConstructor()->getMock();
49 
50  $caseContentObject = new ‪CaseContentObject();
51  $caseContentObject->setRequest($request);
52  $caseContentObject->setContentObjectRenderer($contentObjectRenderer);
53 
54  $textContentObject = new ‪TextContentObject();
55  $textContentObject->setRequest($request);
56  $textContentObject->setContentObjectRenderer($contentObjectRenderer);
57 
58  $cObjectFactoryMock->method('getContentObject')->willReturnMap([
59  ['CASE', $request, $contentObjectRenderer, $caseContentObject],
60  ['TEXT', $request, $contentObjectRenderer, $textContentObject],
61  ]);
62  $container = new Container();
63  $container->set(ContentObjectFactory::class, $cObjectFactoryMock);
64  GeneralUtility::setContainer($container);
65 
66  $this->subject = new ‪CaseContentObject();
67  $this->subject->setRequest($request);
68  $this->subject->setContentObjectRenderer($contentObjectRenderer);
69  }
70 
71  #[Test]
73  {
74  $conf = [
75  'key' => 'not existing',
76  ];
77  self::assertSame('', $this->subject->render($conf));
78  }
79 
80  #[Test]
82  {
83  $conf = [
84  'key' => 'not existing',
85  'default' => 'TEXT',
86  'default.' => [
87  'value' => 'expected value',
88  ],
89  ];
90  self::assertSame('expected value', $this->subject->render($conf));
91  }
92 }
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CaseContentObjectTest.php:33
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest\setUp
‪setUp()
Definition: CaseContentObjectTest.php:37
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest\$subject
‪CaseContentObject $subject
Definition: CaseContentObjectTest.php:35
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest\renderReturnsContentFromDefaultObjectIfKeyDoesNotExist
‪renderReturnsContentFromDefaultObjectIfKeyDoesNotExist()
Definition: CaseContentObjectTest.php:81
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject
Definition: CaseContentObjectTest.php:18
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Frontend\ContentObject\CaseContentObject
Definition: CaseContentObject.php:22
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest
Definition: CaseContentObjectTest.php:32
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectFactory
Definition: ContentObjectFactory.php:29
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:58
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\CaseContentObjectTest\renderReturnsEmptyStringIfNoKeyMatchesAndIfNoDefaultObjectIsSet
‪renderReturnsEmptyStringIfNoKeyMatchesAndIfNoDefaultObjectIsSet()
Definition: CaseContentObjectTest.php:72
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Frontend\ContentObject\TextContentObject
Definition: TextContentObject.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52