‪TYPO3CMS  9.5
ValuePickerItemDataProviderTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Doctrine\DBAL\Driver\Statement;
19 use Prophecy\Prophecy\ObjectProphecy;
26 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
27 
28 class ‪ValuePickerItemDataProviderTest extends UnitTestCase
29 {
31  'tableName' => 'sys_redirect',
32  'processedTca' => [
33  'columns' => [
34  'source_host' => [
35  'config' => [
36  'valuePicker' => [
37  'items' => []
38  ]
39  ]
40  ]
41  ]
42  ]
43  ];
44 
49  {
50  $result = [
51  'tableName' => 'tt_content',
52  ];
53 
54  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
55  $siteFinderProphecy->getAllSites()->willReturn([]);
56  $valuePickerItemDataProvider = new ‪ValuePickerItemDataProvider($siteFinderProphecy->reveal());
57  $actualResult = $valuePickerItemDataProvider->addData($result);
58  self::assertSame($result, $actualResult);
59  }
60 
65  {
66  $statementProphecy = $this->‪setUpDatabase();
67  $statementProphecy->fetchAll()->willReturn(
68  [
69  ['domainName' => 'bar.test'],
70  ['domainName' => 'foo.test'],
71  ]
72  );
73  // no results for now
74  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
75  $siteFinderProphecy->getAllSites()->willReturn([]);
76  $valuePickerItemDataProvider = new ‪ValuePickerItemDataProvider($siteFinderProphecy->reveal());
77  $actualResult = $valuePickerItemDataProvider->addData($this->sysRedirectResultSet);
79  $expected['processedTca']['columns']['source_host']['config']['valuePicker']['items'] = [
80  ['bar.test', 'bar.test'],
81  ['foo.test', 'foo.test'],
82  ];
83  self::assertSame($expected, $actualResult);
84  }
85 
90  {
91  $statementProphecy = $this->‪setUpDatabase();
92  $statementProphecy->fetchAll()->willReturn([]);
93  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
94  $siteFinderProphecy->getAllSites()->willReturn([]);
95  $valuePickerItemDataProvider = new ‪ValuePickerItemDataProvider($siteFinderProphecy->reveal());
96  $actualResult = $valuePickerItemDataProvider->addData($this->sysRedirectResultSet);
97 
98  self::assertSame($this->sysRedirectResultSet, $actualResult);
99  }
100 
104  private function ‪setUpDatabase(): ObjectProphecy
105  {
106  $queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
107  $connectionPoolProphecy = $this->prophesize(ConnectionPool::class);
108  $connectionPoolProphecy->getQueryBuilderForTable('sys_domain')->willReturn($queryBuilderProphecy->reveal());
109  $queryRestrictionContainerProphecy = $this->prophesize(QueryRestrictionContainerInterface::class);
110  $queryBuilderProphecy->getRestrictions()->willReturn($queryRestrictionContainerProphecy->reveal());
111  $queryBuilderProphecy->select('domainName')->willReturn($queryBuilderProphecy->reveal());
112  $queryBuilderProphecy->from('sys_domain')->willReturn($queryBuilderProphecy->reveal());
113  $statementProphecy = $this->prophesize(Statement::class);
114  $queryBuilderProphecy->execute()->willReturn($statementProphecy->reveal());
115  GeneralUtility::addInstance(ConnectionPool::class, $connectionPoolProphecy->reveal());
116  return $statementProphecy;
117  }
118 }
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider
Definition: ValuePickerItemDataProviderTest.php:3
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
Definition: QueryRestrictionContainerInterface.php:23
‪TYPO3\CMS\Core\Database\Query\QueryBuilder
Definition: QueryBuilder.php:47
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest\$sysRedirectResultSet
‪$sysRedirectResultSet
Definition: ValuePickerItemDataProviderTest.php:30
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest\addDataAddsDomainNameAsKeyAndValueToRedirectValuePicker
‪addDataAddsDomainNameAsKeyAndValueToRedirectValuePicker()
Definition: ValuePickerItemDataProviderTest.php:64
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest\addDataDoesNothingIfNoRedirectDataGiven
‪addDataDoesNothingIfNoRedirectDataGiven()
Definition: ValuePickerItemDataProviderTest.php:48
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest\setUpDatabase
‪Doctrine DBAL Driver Statement Prophecy Prophecy ObjectProphecy setUpDatabase()
Definition: ValuePickerItemDataProviderTest.php:104
‪TYPO3\CMS\Redirects\FormDataProvider\ValuePickerItemDataProvider
Definition: ValuePickerItemDataProvider.php:28
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest
Definition: ValuePickerItemDataProviderTest.php:29
‪TYPO3\CMS\Redirects\Tests\Unit\FormDataProvider\ValuePickerItemDataProviderTest\addDataDoesNotChangeResultSetIfNoSysDomainsAreFound
‪addDataDoesNotChangeResultSetIfNoSysDomainsAreFound()
Definition: ValuePickerItemDataProviderTest.php:89