‪TYPO3CMS  10.4
StandardPreviewRendererResolverTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of a TYPO3 extension.
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 
25 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
26 
27 class ‪StandardPreviewRendererResolverTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37 
38  $this->subject = new ‪StandardPreviewRendererResolver();
39  ‪$GLOBALS['TCA']['tt_content'] = [
40  'ctrl' => [
41  'type' => 'CType',
42  'previewRenderer' => StandardContentPreviewRenderer::class,
43  ],
44  'types' => [
45  'list' => [
46  'subtype_value_field' => 'list_type'
47  ]
48  ]
49  ];
50  }
51 
52  protected function ‪tearDown(): void
53  {
54  GeneralUtility::purgeInstances();
55  parent::tearDown();
56  }
57 
61  public function ‪resolveStandardContentPreviewRenderer(): void
62  {
63  $table = 'tt_content';
64  $row = [
65  'CType' => 'text'
66  ];
67 
68  self::assertEquals(
69  StandardContentPreviewRenderer::class,
70  get_class($this->subject->resolveRendererFor($table, $row, 0))
71  );
72  }
73 
77  public function ‪resolveCustomContentPreviewRenderer(): void
78  {
79  $customPreviewRenderer = $this->getMockBuilder(PreviewRendererInterface::class)->getMock();
80 
81  $table = 'tt_content';
82  $row = [
83  'CType' => 'list',
84  'list_type' => 'custom'
85  ];
86  ‪$GLOBALS['TCA'][$table]['types']['list']['previewRenderer']['custom'] = get_class($customPreviewRenderer);
87 
88  self::assertEquals(
89  get_class($customPreviewRenderer),
90  get_class($this->subject->resolveRendererFor($table, $row, 0))
91  );
92  }
93 
98  {
99  $customPreviewRenderer = $this->getMockBuilder(PreviewRendererInterface::class)->getMock();
100 
101  $table = 'tt_content';
102  $row = [
103  'CType' => 'list',
104  'list_type' => 'default'
105  ];
106  ‪$GLOBALS['TCA'][$table]['types']['list']['previewRenderer']['custom'] = get_class($customPreviewRenderer);
107 
108  self::assertEquals(
109  StandardContentPreviewRenderer::class,
110  get_class($this->subject->resolveRendererFor($table, $row, 0))
111  );
112  }
113 
118  {
119  $customPreviewRenderer = $this->getMockBuilder(PreviewRendererInterface::class)->getMock();
120 
121  $table = 'tt_content';
122  $row = [
123  'CType' => 'list',
124  'list_type' => 'default'
125  ];
126  ‪$GLOBALS['TCA'][$table]['types']['list']['previewRenderer'] = get_class($customPreviewRenderer);
127 
128  self::assertEquals(
129  get_class($customPreviewRenderer),
130  get_class($this->subject->resolveRendererFor($table, $row, 0))
131  );
132  }
133 
137  public function ‪getExceptionWithNoPreviewRendererDefined(): void
138  {
139  ‪$GLOBALS['TCA']['pages']['ctrl'] = [];
140 
141  $table = 'pages';
142  $row = [
144  ];
145 
146  $this->expectException(\RuntimeException::class);
147  $this->expectExceptionCode(1477520356);
148 
149  $this->subject->resolveRendererFor($table, $row, 0);
150  }
151 }
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\setUp
‪setUp()
Definition: StandardPreviewRendererResolverTest.php:33
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\resolveCustomContentPreviewRenderer
‪resolveCustomContentPreviewRenderer()
Definition: StandardPreviewRendererResolverTest.php:76
‪TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer
Definition: StandardContentPreviewRenderer.php:51
‪TYPO3\CMS\Backend\Preview\StandardPreviewRendererResolver
Definition: StandardPreviewRendererResolver.php:35
‪TYPO3\CMS\Backend\Preview\PreviewRendererInterface
Definition: PreviewRendererInterface.php:40
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_DEFAULT
‪const DOKTYPE_DEFAULT
Definition: PageRepository.php:103
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\resolveStandardContentPreviewRendererWithCustomPreviewRendererDefined
‪resolveStandardContentPreviewRendererWithCustomPreviewRendererDefined()
Definition: StandardPreviewRendererResolverTest.php:96
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\resolveStandardContentPreviewRenderer
‪resolveStandardContentPreviewRenderer()
Definition: StandardPreviewRendererResolverTest.php:60
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest
Definition: StandardPreviewRendererResolverTest.php:28
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\$subject
‪StandardPreviewRendererResolver $subject
Definition: StandardPreviewRendererResolverTest.php:31
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\getExceptionWithNoPreviewRendererDefined
‪getExceptionWithNoPreviewRendererDefined()
Definition: StandardPreviewRendererResolverTest.php:136
‪TYPO3\CMS\Backend\Tests\Unit\Preview
Definition: StandardPreviewRendererResolverTest.php:18
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\tearDown
‪tearDown()
Definition: StandardPreviewRendererResolverTest.php:51
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Backend\Tests\Unit\Preview\StandardPreviewRendererResolverTest\resolveStandardContentPreviewRendererWithGeneralPreviewRendererDefinedForAllSubTypes
‪resolveStandardContentPreviewRendererWithGeneralPreviewRendererDefinedForAllSubTypes()
Definition: StandardPreviewRendererResolverTest.php:116
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46