‪TYPO3CMS  ‪main
ContentDataProcessorTest.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 PHPUnit\Framework\MockObject\MockObject;
22 use Symfony\Component\DependencyInjection\Container;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪ContentDataProcessorTest extends UnitTestCase
30 {
32  protected Container ‪$container;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->container = new Container();
39  $this->dataProcessorRegistryMock = $this->getMockBuilder(DataProcessorRegistry::class)->disableOriginalConstructor()->getMock();
40  $this->dataProcessorRegistryMock->method('getDataProcessor')->willReturn(null);
41  $this->contentDataProcessor = new ‪ContentDataProcessor(
42  $this->container,
43  $this->dataProcessorRegistryMock
44  );
45  }
46 
47  #[Test]
49  {
50  $this->expectException(\UnexpectedValueException::class);
51  $this->expectExceptionCode(1427455378);
52  $contentObjectRendererStub = new ‪ContentObjectRenderer();
53  $config = [
54  'dataProcessing.' => [
55  '10' => 'fooClass',
56  ],
57  ];
58  $variables = [];
59  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
60  }
61 
62  #[Test]
64  {
65  $this->expectException(\UnexpectedValueException::class);
66  $this->expectExceptionCode(1427455377);
67  $contentObjectRendererStub = new ‪ContentObjectRenderer();
68  $config = [
69  'dataProcessing.' => [
70  '10' => static::class,
71  ],
72  ];
73  $variables = [];
74  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
75  }
76 
77  #[Test]
78  public function ‪processorClassIsCalled(): void
79  {
80  $contentObjectRendererStub = new ‪ContentObjectRenderer();
81  $config = [
82  'dataProcessing.' => [
83  '10' => DataProcessorFixture::class,
84  '10.' => ['foo' => 'bar'],
85  ],
86  ];
87  $variables = [];
88  self::assertSame(
89  ['foo' => 'bar'],
90  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables)
91  );
92  }
93 
94  #[Test]
96  {
97  $this->expectException(\UnexpectedValueException::class);
98  $this->expectExceptionCode(1635927108);
99  $contentObjectRendererStub = new ‪ContentObjectRenderer();
100  $this->container->set(static::class, $this);
101  $config = [
102  'dataProcessing.' => [
103  '10' => static::class,
104  ],
105  ];
106  $variables = [];
107  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
108  }
109 
110  #[Test]
111  public function ‪processorServiceIsCalled(): void
112  {
113  $contentObjectRendererStub = new ‪ContentObjectRenderer();
114  $this->container->set('dataProcessorFixture', new ‪DataProcessorFixture());
115  $config = [
116  'dataProcessing.' => [
117  '10' => 'dataProcessorFixture',
118  '10.' => ['foo' => 'bar'],
119  ],
120  ];
121  $variables = [];
122  self::assertSame(
123  ['foo' => 'bar'],
124  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables)
125  );
126  }
127 }
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\DataProcessorFixture
Definition: DataProcessorFixture.php:24
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:27
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorDoesNotExist
‪throwsExceptionIfProcessorDoesNotExist()
Definition: ContentDataProcessorTest.php:48
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorClassDoesNotImplementInterface
‪throwsExceptionIfProcessorClassDoesNotImplementInterface()
Definition: ContentDataProcessorTest.php:63
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\$contentDataProcessor
‪ContentDataProcessor $contentDataProcessor
Definition: ContentDataProcessorTest.php:31
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\setUp
‪setUp()
Definition: ContentDataProcessorTest.php:35
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\processorServiceIsCalled
‪processorServiceIsCalled()
Definition: ContentDataProcessorTest.php:111
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\$container
‪Container $container
Definition: ContentDataProcessorTest.php:32
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorServiceDoesNotImplementInterface
‪throwsExceptionIfProcessorServiceDoesNotImplementInterface()
Definition: ContentDataProcessorTest.php:95
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject
Definition: CaseContentObjectTest.php:18
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\$dataProcessorRegistryMock
‪MockObject &DataProcessorRegistry $dataProcessorRegistryMock
Definition: ContentDataProcessorTest.php:33
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\processorClassIsCalled
‪processorClassIsCalled()
Definition: ContentDataProcessorTest.php:78
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest
Definition: ContentDataProcessorTest.php:30
‪TYPO3\CMS\Frontend\DataProcessing\DataProcessorRegistry
Definition: DataProcessorRegistry.php:28