TYPO3 CMS  TYPO3_7-6
LikeWildcardTest.php
Go to the documentation of this file.
1 <?php
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  */
17 
22 {
26  protected function setUp()
27  {
29  $databaseConnectionMock = $this->getMock(\TYPO3\CMS\Core\Database\DatabaseConnection::class, ['quoteStr']);
30  $databaseConnectionMock->method('quoteStr')
31  ->will($this->returnArgument(0));
32  $GLOBALS['TYPO3_DB'] = $databaseConnectionMock;
33  }
34 
44  public function getLikeQueryPart($tableName, $fieldName, $likeValue, $wildcard, $expected)
45  {
47  $this->assertSame($expected, $subject->getLikeQueryPart($tableName, $fieldName, $likeValue));
48  }
49 
61  public function getLikeQueryPartDataProvider()
62  {
63  return [
64  'no placeholders and no wildcard mode' => [
65  'tt_content',
66  'body',
67  'searchstring',
69  'body LIKE \'searchstring\''
70  ],
71  'no placeholders and left wildcard mode' => [
72  'tt_content',
73  'body',
74  'searchstring',
76  'body LIKE \'%searchstring\''
77  ],
78  'no placeholders and right wildcard mode' => [
79  'tt_content',
80  'body',
81  'searchstring',
83  'body LIKE \'searchstring%\''
84  ],
85  'no placeholders and both wildcards mode' => [
86  'tt_content',
87  'body',
88  'searchstring',
90  'body LIKE \'%searchstring%\''
91  ],
92  'underscore placeholder and left wildcard mode' => [
93  'tt_content',
94  'body',
95  'search_string',
97  'body LIKE \'%search\\_string\''
98  ],
99  'percent placeholder and right wildcard mode' => [
100  'tt_content',
101  'body',
102  'search%string',
104  'body LIKE \'search\\%string%\''
105  ],
106  'percent and underscore placeholder and both wildcards mode' => [
107  'tt_content',
108  'body',
109  '_search%string_',
111  'body LIKE \'\\_search\\%string\\_%\''
112  ],
113  ];
114  }
115 }
getLikeQueryPart($tableName, $fieldName, $likeValue, $wildcard, $expected)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']