‪TYPO3CMS  9.5
DatabaseRecordLinkBuilderTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
19 use Prophecy\Argument;
28 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
29 
33 class ‪DatabaseRecordLinkBuilderTest extends UnitTestCase
34 {
35 
42  {
43  return [
44  'attributes from db overwrite config' => [
45  '27 tsTarget tsClass tsTitle',
46  't3://record?identifier=tx_news&uid=1 dbTarget dbClass dbTitle',
47  '27 dbTarget dbClass dbTitle',
48  ],
49  'no attributes from db - config is taken' => [
50  '27 tsTarget tsClass tsTitle',
51  't3://record?identifier=tx_news&uid=1',
52  '27 tsTarget tsClass tsTitle',
53  ],
54  'mixed: target from db' => [
55  '27 tsTarget tsClass tsTitle',
56  't3://record?identifier=tx_news&uid=1 dbTarget',
57  '27 dbTarget tsClass tsTitle',
58  ],
59  'mixed: class from db' => [
60  '27 tsTarget tsClass tsTitle',
61  't3://record?identifier=tx_news&uid=1 - dbClass',
62  '27 tsTarget dbClass tsTitle',
63  ],
64  'mixed: title from db' => [
65  '27 tsTarget tsClass tsTitle',
66  't3://record?identifier=tx_news&uid=1 - - dbTitle',
67  '27 tsTarget tsClass dbTitle',
68  ],
69  'mixed: target and title from db' => [
70  '27 tsTarget tsClass tsTitle',
71  't3://record?identifier=tx_news&uid=1 dbTarget - dbTitle',
72  '27 dbTarget tsClass dbTitle',
73  ],
74  'mixed: target and title from db, no class set' => [
75  '27 tsTarget - tsTitle',
76  't3://record?identifier=tx_news&uid=1 dbTarget - dbTitle',
77  '27 dbTarget - dbTitle',
78  ],
79  'mixed: title from db, no config set' => [
80  '27',
81  't3://record?identifier=tx_news&uid=1 - - dbTitle',
82  '27 - - dbTitle',
83  ],
84  'no attributes configured' => [
85  '27',
86  't3://record?identifier=tx_news&uid=1',
87  '27',
88  ],
89 
90  ];
91  }
92 
106  public function ‪attributesSetInRecordLinkOverwriteConfiguredAttributes(string $parameterFromTypoScript, string $parameterFromDb, string $expectedParameter): void
107  {
108  $confFromDb = [
109  'parameter' => $parameterFromDb,
110  ];
111  $extractedLinkDetails = [
112  'identifier' => 'tx_news',
113  'uid' => '1',
114  'type' => 'record',
115  'typoLinkParameter' => 't3://record?identifier=tx_news&uid=1',
116  ];
117  $typoScriptConfig = [
118  'config.' => [
119  'recordLinks.' => [
120  'tx_news.' =>
121  [
122  'forceLink' => '0',
123  'typolink.' =>
124  [
125  'parameter' => $parameterFromTypoScript,
126  'additionalParams' => '&tx_news_pi1[news]={field:uid}',
127  'additionalParams.' =>
128  [
129  'insertData' => '1',
130  ],
131  ],
132  ],
133  ],
134  ],
135  ];
136  $pageTsConfig = [
137  'TCEMAIN.' =>
138  [
139  'linkHandler.' =>
140  [
141 
142  'tx_news.' =>
143  [
144  'handler' => RecordLinkHandler::class,
145  'label' => 'News',
146  'configuration.' =>
147  [
148  'table' => 'tx_news_domain_model_news',
149  ],
150  'scanAfter' => 'page',
151  ],
152  ],
153  ],
154 
155  ];
156  $target = '';
157  $linkText = 'Test Link';
158 
159  $expectedConfiguration = [
160  'parameter' => $expectedParameter,
161  'additionalParams' => '&tx_news_pi1[news]={field:uid}',
162  'additionalParams.' => ['insertData' => '1'],
163  ];
164 
165  // Arrange
166  $tsfe = $this->prophesize(TypoScriptFrontendController::class);
167  $templateService = $this->prophesize(TemplateService::class);
168  $pageRepository = $this->prophesize(PageRepository::class);
169  $cObj = $this->prophesize(ContentObjectRenderer::class);
170 
171  ‪$GLOBALS['TSFE'] = $tsfe->reveal();
172  $tsfe->tmpl = $templateService->reveal();
173  $tsfe->tmpl->setup = $typoScriptConfig;
174  $tsfe->sys_page = $pageRepository->reveal();
175  GeneralUtility::addInstance(ContentObjectRenderer::class, $cObj->reveal());
176 
177  $pageRepository->checkRecord('tx_news_domain_model_news', 1)->willReturn(
178  [
179  'uid' => '1',
180  ]
181  );
182 
183  $cObj->start(Argument::cetera())->shouldBeCalled();
184  $cObj->typoLink(Argument::cetera())->shouldBeCalled();
185 
186  $tsfe->getPagesTSconfig()->willReturn($pageTsConfig);
187 
188  // Act
189  $databaseRecordLinkBuilder = new ‪DatabaseRecordLinkBuilder($cObj->reveal());
190  try {
191  $databaseRecordLinkBuilder->build($extractedLinkDetails, $linkText, $target, $confFromDb);
192  } catch (‪UnableToLinkException $exception) {
193  // Assert
194  $cObj->typoLink($linkText, $expectedConfiguration)->shouldHaveBeenCalled();
195  }
196  }
197 }
‪TYPO3\CMS\Frontend\Page\PageRepository
Definition: PageRepository.php:53
‪TYPO3\CMS\Core\TypoScript\TemplateService
Definition: TemplateService.php:50
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:97
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:91
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45