[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Functional / DataHandling / DataHandler / GetUniqueTest.php
1 <?php
2 declare (strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler;
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\Crypto\Random;
19 use TYPO3\CMS\Core\Database\ConnectionPool;
20 use TYPO3\CMS\Core\DataHandling\DataHandler;
21 use TYPO3\CMS\Core\Tests\FunctionalTestCase;
22 use TYPO3\CMS\Core\Utility\GeneralUtility;
23
24 /**
25 * Tests related to DataHandler::getUnique()
26 */
27 class GetUniqueTest extends FunctionalTestCase
28 {
29 protected function setUp()
30 {
31 parent::setUp();
32
33 $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
34 $connection->insert('pages', ['title' => 'ExistingPage']);
35 $connection->insert('pages', ['title' => 'ManyPages']);
36 for ($i = 0; $i <= 100; $i++) {
37 $connection->insert('pages', ['title' => 'ManyPages' . $i]);
38 }
39 }
40
41 /**
42 * Data provider for getUnique
43 * @return array
44 */
45 public function getUniqueDataProvider(): array
46 {
47 $randomValue = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(10);
48
49 return [
50 'unique value' => [$randomValue, $randomValue],
51 'non-unique value' => ['ExistingPage', 'ExistingPage0'],
52 'uniqueness not enforceable' => ['ManyPages', 'ManyPages100'],
53 ];
54 }
55
56 /**
57 * @param string $value
58 * @param string $expected
59 * @test
60 * @dataProvider getUniqueDataProvider
61 */
62 public function getUnique(string $value, string $expected)
63 {
64 $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
65 $this->assertSame(
66 $expected,
67 $dataHandler->getUnique('pages', 'title', $value, 0, 0)
68 );
69 }
70 }