[!!!][TASK] Remove sys_domain and LegacyDomains
[Packages/TYPO3.CMS.git] / typo3 / sysext / redirects / Tests / Unit / FormDataProvider / ValuePickerItemDataProviderTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider;
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
18 use TYPO3\CMS\Core\Site\Entity\Site;
19 use TYPO3\CMS\Core\Site\SiteFinder;
20 use TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider;
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22
23 class ValuePickerItemDataProviderTest extends UnitTestCase
24 {
25 protected $sysRedirectResultSet = [
26 'tableName' => 'sys_redirect',
27 'processedTca' => [
28 'columns' => [
29 'source_host' => [
30 'config' => [
31 'valuePicker' => [
32 'items' => []
33 ]
34 ]
35 ]
36 ]
37 ]
38 ];
39
40 /**
41 * @test
42 */
43 public function addDataDoesNothingIfNoRedirectDataGiven()
44 {
45 $result = [
46 'tableName' => 'tt_content',
47 ];
48
49 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
50 $siteFinderProphecy->getAllSites()->willReturn([]);
51 $valuePickerItemDataProvider = new ValuePickerItemDataProvider($siteFinderProphecy->reveal());
52 $actualResult = $valuePickerItemDataProvider->addData($result);
53 self::assertSame($result, $actualResult);
54 }
55
56 /**
57 * @test
58 */
59 public function addDataAddsHostsAsKeyAndValueToRedirectValuePicker()
60 {
61 // no results for now
62 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
63 $siteFinderProphecy->getAllSites()->willReturn([
64 new Site('bar', 13, ['base' => 'bar.test']),
65 new Site('foo', 14, ['base' => 'foo.test'])
66 ]);
67 $valuePickerItemDataProvider = new ValuePickerItemDataProvider($siteFinderProphecy->reveal());
68 $actualResult = $valuePickerItemDataProvider->addData($this->sysRedirectResultSet);
69 $expected = $this->sysRedirectResultSet;
70 $expected['processedTca']['columns']['source_host']['config']['valuePicker']['items'] = [
71 ['bar.test', 'bar.test'],
72 ['foo.test', 'foo.test'],
73 ];
74 self::assertSame($expected, $actualResult);
75 }
76
77 /**
78 * @test
79 */
80 public function addDataDoesNotChangeResultSetIfNoSitessAreFound()
81 {
82 $siteFinderProphecy = $this->prophesize(SiteFinder::class);
83 $siteFinderProphecy->getAllSites()->willReturn([]);
84 $valuePickerItemDataProvider = new ValuePickerItemDataProvider($siteFinderProphecy->reveal());
85 $actualResult = $valuePickerItemDataProvider->addData($this->sysRedirectResultSet);
86
87 self::assertSame($this->sysRedirectResultSet, $actualResult);
88 }
89 }