‪TYPO3CMS  11.5
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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Prophecy\Prophecy\ObjectProphecy;
23 use Psr\Container\ContainerInterface;
25 use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
32 class ‪ContentDataProcessorTest extends UnitTestCase
33 {
34  use ProphecyTrait;
35 
37 
39  protected ObjectProphecy ‪$containerProphecy;
40 
44  protected function ‪setUp(): void
45  {
46  parent::setUp();
47  $this->containerProphecy = $this->prophesize(ContainerInterface::class);
48  $this->containerProphecy->has(Argument::any())->willReturn(false);
49  $this->contentDataProcessor = new ‪ContentDataProcessor(
50  $this->containerProphecy->reveal()
51  );
52  }
53 
57  public function ‪throwsExceptionIfProcessorDoesNotExist(): void
58  {
59  $this->expectException(\UnexpectedValueException::class);
60  $this->expectExceptionCode(1427455378);
61  $contentObjectRendererStub = new ContentObjectRenderer();
62  $config = [
63  'dataProcessing.' => [
64  '10' => 'fooClass',
65  ],
66  ];
67  $variables = [];
68  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
69  }
70 
75  {
76  $this->expectException(\UnexpectedValueException::class);
77  $this->expectExceptionCode(1427455377);
78  $contentObjectRendererStub = new ContentObjectRenderer();
79  $config = [
80  'dataProcessing.' => [
81  '10' => static::class,
82  ],
83  ];
84  $variables = [];
85  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
86  }
87 
91  public function ‪processorClassIsCalled(): void
92  {
93  $contentObjectRendererStub = new ContentObjectRenderer();
94  $config = [
95  'dataProcessing.' => [
96  '10' => DataProcessorFixture::class,
97  '10.' => ['foo' => 'bar'],
98  ],
99  ];
100  $variables = [];
101  self::assertSame(
102  ['foo' => 'bar'],
103  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables)
104  );
105  }
106 
111  {
112  $this->expectException(\UnexpectedValueException::class);
113  $this->expectExceptionCode(1635927108);
114  $contentObjectRendererStub = new ContentObjectRenderer();
115  $this->containerProphecy->has(static::class)->willReturn(true);
116  $this->containerProphecy->get(static::class)->willReturn($this);
117  $config = [
118  'dataProcessing.' => [
119  '10' => static::class,
120  ],
121  ];
122  $variables = [];
123  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables);
124  }
125 
129  public function ‪processorServiceIsCalled(): void
130  {
131  $contentObjectRendererStub = new ContentObjectRenderer();
132  $this->containerProphecy->has('dataProcessorFixture')->willReturn(true);
133  $this->containerProphecy->get('dataProcessorFixture')->willReturn(new DataProcessorFixture());
134  $config = [
135  'dataProcessing.' => [
136  '10' => 'dataProcessorFixture',
137  '10.' => ['foo' => 'bar'],
138  ],
139  ];
140  $variables = [];
141  self::assertSame(
142  ['foo' => 'bar'],
143  $this->contentDataProcessor->process($contentObjectRendererStub, $config, $variables)
144  );
145  }
146 }
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Fixtures\DataProcessorFixture
Definition: DataProcessorFixture.php:27
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:26
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorDoesNotExist
‪throwsExceptionIfProcessorDoesNotExist()
Definition: ContentDataProcessorTest.php:56
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorClassDoesNotImplementInterface
‪throwsExceptionIfProcessorClassDoesNotImplementInterface()
Definition: ContentDataProcessorTest.php:73
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\$contentDataProcessor
‪ContentDataProcessor $contentDataProcessor
Definition: ContentDataProcessorTest.php:35
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\setUp
‪setUp()
Definition: ContentDataProcessorTest.php:43
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\processorServiceIsCalled
‪processorServiceIsCalled()
Definition: ContentDataProcessorTest.php:128
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\throwsExceptionIfProcessorServiceDoesNotImplementInterface
‪throwsExceptionIfProcessorServiceDoesNotImplementInterface()
Definition: ContentDataProcessorTest.php:109
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject
Definition: CaseContentObjectTest.php:18
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\processorClassIsCalled
‪processorClassIsCalled()
Definition: ContentDataProcessorTest.php:90
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest
Definition: ContentDataProcessorTest.php:33
‪TYPO3\CMS\Frontend\Tests\Unit\ContentObject\ContentDataProcessorTest\$containerProphecy
‪ObjectProphecy $containerProphecy
Definition: ContentDataProcessorTest.php:38