TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
LikeWildcardTest.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\IndexedSearch\Tests\Unit\Utility;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
20 
25 {
35  public function getLikeQueryPart($tableName, $fieldName, $likeValue, $wildcard, $expected)
36  {
37  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
38  $subject = LikeWildcard::cast($wildcard);
39  $expected = $connection->quoteIdentifier($fieldName) . ' ' . $expected;
40  $this->assertSame($expected, $subject->getLikeQueryPart($tableName, $fieldName, $likeValue));
41  }
42 
54  public function getLikeQueryPartDataProvider()
55  {
56  return [
57  'no placeholders and no wildcard mode' => [
58  'tt_content',
59  'body',
60  'searchstring',
62  "LIKE 'searchstring'"
63  ],
64  'no placeholders and left wildcard mode' => [
65  'tt_content',
66  'body',
67  'searchstring',
69  "LIKE '%searchstring'"
70  ],
71  'no placeholders and right wildcard mode' => [
72  'tt_content',
73  'body',
74  'searchstring',
76  "LIKE 'searchstring%'"
77  ],
78  'no placeholders and both wildcards mode' => [
79  'tt_content',
80  'body',
81  'searchstring',
83  "LIKE '%searchstring%'"
84  ],
85  'underscore placeholder and left wildcard mode' => [
86  'tt_content',
87  'body',
88  'search_string',
90  "LIKE '%search\\\\_string'"
91  ],
92  'percent placeholder and right wildcard mode' => [
93  'tt_content',
94  'body',
95  'search%string',
97  "LIKE 'search\\\\%string%'"
98  ],
99  'percent and underscore placeholder and both wildcards mode' => [
100  'tt_content',
101  'body',
102  '_search%string_',
104  "LIKE '\\\\_search\\\\%string\\\\_%'"
105  ],
106  ];
107  }
108 }
getLikeQueryPart($tableName, $fieldName, $likeValue, $wildcard, $expected)
static makeInstance($className,...$constructorArguments)