Skip to content
Snippets Groups Projects
Commit 73bedee8 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Benni Mack
Browse files

[TASK] Integrate test-case for DataHandler::getUnique

Resolves: #77351
Releases: master
Change-Id: Iab4b9ba167060dd8f8a15b69d8f9a0842ec899b6
Reviewed-on: https://review.typo3.org/49310


Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: default avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarBenni Mack <benni@typo3.org>
parent 33ced562
Branches
Tags
No related merge requests found
<?php
declare (strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Tests\FunctionalTestCase;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Tests related to DataHandler::getUnique()
*/
class GetUniqueTest extends FunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages');
$connection->insert('pages', ['title' => 'ExistingPage']);
$connection->insert('pages', ['title' => 'ManyPages']);
for ($i = 0; $i <= 100; $i++) {
$connection->insert('pages', ['title' => 'ManyPages' . $i]);
}
}
/**
* Data provider for getUnique
* @return array
*/
public function getUniqueDataProvider(): array
{
$randomValue = GeneralUtility::makeInstance(Random::class)->generateRandomHexString(10);
return [
'unique value' => [$randomValue, $randomValue],
'non-unique value' => ['ExistingPage', 'ExistingPage0'],
'uniqueness not enforceable' => ['ManyPages', 'ManyPages100'],
];
}
/**
* @param string $value
* @param string $expected
* @test
* @dataProvider getUniqueDataProvider
*/
public function getUnique(string $value, string $expected)
{
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$this->assertSame(
$expected,
$dataHandler->getUnique('pages', 'title', $value, 0, 0)
);
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment