‪TYPO3CMS  10.4
DatabaseRecordLinkBuilderTest.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;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪DatabaseRecordLinkBuilderTest extends UnitTestCase
35 {
36 
43  {
44  return [
45  'attributes from db overwrite config' => [
46  '27 tsTarget tsClass tsTitle',
47  't3://record?identifier=tx_news&uid=1 dbTarget dbClass dbTitle',
48  '27 dbTarget dbClass dbTitle',
49  ],
50  'no attributes from db - config is taken' => [
51  '27 tsTarget tsClass tsTitle',
52  't3://record?identifier=tx_news&uid=1',
53  '27 tsTarget tsClass tsTitle',
54  ],
55  'mixed: target from db' => [
56  '27 tsTarget tsClass tsTitle',
57  't3://record?identifier=tx_news&uid=1 dbTarget',
58  '27 dbTarget tsClass tsTitle',
59  ],
60  'mixed: class from db' => [
61  '27 tsTarget tsClass tsTitle',
62  't3://record?identifier=tx_news&uid=1 - dbClass',
63  '27 tsTarget dbClass tsTitle',
64  ],
65  'mixed: title from db' => [
66  '27 tsTarget tsClass tsTitle',
67  't3://record?identifier=tx_news&uid=1 - - dbTitle',
68  '27 tsTarget tsClass dbTitle',
69  ],
70  'mixed: target and title from db' => [
71  '27 tsTarget tsClass tsTitle',
72  't3://record?identifier=tx_news&uid=1 dbTarget - dbTitle',
73  '27 dbTarget tsClass dbTitle',
74  ],
75  'mixed: target and title from db, no class set' => [
76  '27 tsTarget - tsTitle',
77  't3://record?identifier=tx_news&uid=1 dbTarget - dbTitle',
78  '27 dbTarget - dbTitle',
79  ],
80  'mixed: title from db, no config set' => [
81  '27',
82  't3://record?identifier=tx_news&uid=1 - - dbTitle',
83  '27 - - dbTitle',
84  ],
85  'no attributes configured' => [
86  '27',
87  't3://record?identifier=tx_news&uid=1',
88  '27',
89  ],
90 
91  ];
92  }
93 
107  public function ‪attributesSetInRecordLinkOverwriteConfiguredAttributes(string $parameterFromTypoScript, string $parameterFromDb, string $expectedParameter): void
108  {
109  $confFromDb = [
110  'parameter' => $parameterFromDb,
111  ];
112  $extractedLinkDetails = [
113  'identifier' => 'tx_news',
114  'uid' => '1',
115  'type' => 'record',
116  'typoLinkParameter' => 't3://record?identifier=tx_news&uid=1',
117  ];
118  $typoScriptConfig = [
119  'config.' => [
120  'recordLinks.' => [
121  'tx_news.' =>
122  [
123  'forceLink' => '0',
124  'typolink.' =>
125  [
126  'parameter' => $parameterFromTypoScript,
127  'additionalParams' => '&tx_news_pi1[news]={field:uid}',
128  'additionalParams.' =>
129  [
130  'insertData' => '1',
131  ],
132  ],
133  ],
134  ],
135  ],
136  ];
137  $pageTsConfig = [
138  'TCEMAIN.' =>
139  [
140  'linkHandler.' =>
141  [
142 
143  'tx_news.' =>
144  [
145  'handler' => RecordLinkHandler::class,
146  'label' => 'News',
147  'configuration.' =>
148  [
149  'table' => 'tx_news_domain_model_news',
150  ],
151  'scanAfter' => 'page',
152  ],
153  ],
154  ],
155 
156  ];
157  $target = '';
158  $linkText = 'Test Link';
159 
160  $expectedConfiguration = [
161  'parameter' => $expectedParameter,
162  'additionalParams' => '&tx_news_pi1[news]={field:uid}',
163  'additionalParams.' => ['insertData' => '1'],
164  ];
165 
166  // Arrange
167  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
168  $templateService = $this->prophesize(TemplateService::class);
169  $pageRepository = $this->prophesize(PageRepository::class);
170  $cObj = $this->prophesize(ContentObjectRenderer::class);
171 
172  ‪$GLOBALS['TSFE'] = $tsfe->reveal();
173  $tsfe->tmpl = $templateService->reveal();
174  $tsfe->tmpl->setup = $typoScriptConfig;
175  $tsfe->sys_page = $pageRepository->reveal();
176  GeneralUtility::addInstance(ContentObjectRenderer::class, $cObj->reveal());
177 
178  $pageRepository->checkRecord('tx_news_domain_model_news', 1)->willReturn(
179  [
180  'uid' => '1',
181  ]
182  );
183 
184  $cObj->start(Argument::cetera())->shouldBeCalled();
185  $cObj->typoLink(Argument::cetera())->shouldBeCalled();
186 
187  $tsfe->getPagesTSconfig()->willReturn($pageTsConfig);
188 
189  // Act
190  $databaseRecordLinkBuilder = new ‪DatabaseRecordLinkBuilder($cObj->reveal());
191  try {
192  $databaseRecordLinkBuilder->build($extractedLinkDetails, $linkText, $target, $confFromDb);
193  } catch (‪UnableToLinkException $exception) {
194  // Assert
195  $cObj->typoLink($linkText, $expectedConfiguration)->shouldHaveBeenCalled();
196  }
197  }
198 }
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:46
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:97
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:52
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46