[BUGFIX] Fix functional tests for EXT:indexed_search on PostgreSQL 65/51765/2
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Mon, 20 Feb 2017 05:21:30 +0000 (21:21 -0800)
committerChristian Kuhn <lolli@schwarzbu.ch>
Mon, 20 Feb 2017 14:46:51 +0000 (15:46 +0100)
MySQL has support for backslash escape sequences. Change the tests
to have the expected results without the additional escaping and
add the additional slashes to the expected result if the database
platform running the tests is MySQL.

Change-Id: Ib2e30e95db507501aaea095eb3764a0d37135ec9
Resolves: #79799
Releases: master
Reviewed-on: https://review.typo3.org/51765
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
typo3/sysext/indexed_search/Tests/Functional/Utility/LikeWildcardTest.php

index ef9d5a0..f6204e7 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\IndexedSearch\Tests\Unit\Utility;
  *
  * The TYPO3 project - inspiring people to share!
  */
+use Doctrine\DBAL\Platforms\MySqlPlatform;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\IndexedSearch\Utility\LikeWildcard;
@@ -35,6 +36,11 @@ class LikeWildcardTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
     {
         $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
         $subject = LikeWildcard::cast($wildcard);
+        // MySQL has support for backslash escape sequences, the expected results needs to take
+        // the additional quoting into account.
+        if ($connection->getDatabasePlatform() instanceof MySqlPlatform) {
+            $expected = addcslashes($expected, '\\');
+        }
         $expected = $connection->quoteIdentifier($fieldName) . ' ' . $expected;
         $this->assertSame($expected, $subject->getLikeQueryPart($tableName, $fieldName, $likeValue));
     }
@@ -86,21 +92,21 @@ class LikeWildcardTest extends \TYPO3\TestingFramework\Core\Functional\Functiona
                 'body',
                 'search_string',
                 LikeWildcard::LEFT,
-                "LIKE '%search\\\\_string'"
+                "LIKE '%search\\_string'"
             ],
             'percent placeholder and right wildcard mode' => [
                 'tt_content',
                 'body',
                 'search%string',
                 LikeWildcard::RIGHT,
-                "LIKE 'search\\\\%string%'"
+                "LIKE 'search\\%string%'"
             ],
             'percent and underscore placeholder and both wildcards mode' => [
                 'tt_content',
                 'body',
                 '_search%string_',
                 LikeWildcard::RIGHT,
-                "LIKE '\\\\_search\\\\%string\\\\_%'"
+                "LIKE '\\_search\\%string\\_%'"
             ],
         ];
     }