[TASK] Integrate test-case for DataHandler::getUnique 10/49310/4
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Tue, 2 Aug 2016 12:54:44 +0000 (14:54 +0200)
committerBenni Mack <benni@typo3.org>
Tue, 2 Aug 2016 14:01:18 +0000 (16:01 +0200)
Resolves: #77351
Releases: master
Change-Id: Iab4b9ba167060dd8f8a15b69d8f9a0842ec899b6
Reviewed-on: https://review.typo3.org/49310
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/GetUniqueTest.php [new file with mode: 0644]

diff --git a/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/GetUniqueTest.php b/typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/GetUniqueTest.php
new file mode 100644 (file)
index 0000000..8545c7e
--- /dev/null
@@ -0,0 +1,70 @@
+<?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