‪TYPO3CMS  11.5
GetUniqueTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
29 class ‪GetUniqueTest extends FunctionalTestCase
30 {
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34 
35  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
36  $connection->insert('pages', ['title' => 'ExistingPage']);
37  $connection->insert('pages', ['title' => 'ManyPages']);
38  for ($i = 0; $i <= 100; $i++) {
39  $connection->insert('pages', ['title' => 'ManyPages' . $i]);
40  }
41  }
42 
47  public function ‪getUniqueDataProvider(): array
48  {
49  $randomValue = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(10);
50 
51  return [
52  'unique value' => [$randomValue, $randomValue],
53  'non-unique value' => ['ExistingPage', 'ExistingPage0'],
54  'uniqueness not enforceable' => ['ManyPages', 'ManyPages100'],
55  ];
56  }
57 
64  public function ‪getUnique(string $value, string $expected): void
65  {
66  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
67  $dataHandler->enableLogging = false;
68  self::assertSame(
69  $expected,
70  $dataHandler->getUnique('pages', 'title', $value, 0, 0)
71  );
72  }
73 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:86
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: DefaultValuesTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\getUniqueDataProvider
‪array getUniqueDataProvider()
Definition: GetUniqueTest.php:47
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\setUp
‪setUp()
Definition: GetUniqueTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest
Definition: GetUniqueTest.php:30
‪TYPO3\CMS\Core\Crypto\Random
Definition: Random.php:24
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\GetUniqueTest\getUnique
‪getUnique(string $value, string $expected)
Definition: GetUniqueTest.php:64