‪TYPO3CMS  9.5
GetUniqueTest.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 
22 
26 class ‪GetUniqueTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
27 {
28  protected function ‪setUp()
29  {
30  parent::setUp();
31 
32  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
33  $connection->insert('pages', ['title' => 'ExistingPage']);
34  $connection->insert('pages', ['title' => 'ManyPages']);
35  for ($i = 0; $i <= 100; $i++) {
36  $connection->insert('pages', ['title' => 'ManyPages' . $i]);
37  }
38  }
39 
44  public function ‪getUniqueDataProvider(): array
45  {
46  $randomValue = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(10);
47 
48  return [
49  'unique value' => [$randomValue, $randomValue],
50  'non-unique value' => ['ExistingPage', 'ExistingPage0'],
51  'uniqueness not enforceable' => ['ManyPages', 'ManyPages100'],
52  ];
53  }
54 
61  public function ‪getUnique(string $value, string $expected)
62  {
63  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
64  $this->assertSame(
65  $expected,
66  $dataHandler->getUnique('pages', 'title', $value, 0, 0)
67  );
68  }
69 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: DefaultValuesTest.php:17
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\getUniqueDataProvider
‪array getUniqueDataProvider()
Definition: GetUniqueTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\setUp
‪setUp()
Definition: GetUniqueTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest
Definition: GetUniqueTest.php:27
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:22
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\getUnique
‪getUnique(string $value, string $expected)
Definition: GetUniqueTest.php:61