TYPO3 CMS  TYPO3_7-6
DatabaseConnectionMssqlTest.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  */
16 
21 {
25  protected $subject;
26 
32  protected function setUp()
33  {
34  $configuration = [
35  'handlerCfg' => [
36  '_DEFAULT' => [
37  'type' => 'adodb',
38  'config' => [
39  'driver' => 'mssql',
40  ],
41  ],
42  ],
43  'mapping' => [
44  'tx_templavoila_tmplobj' => [
45  'mapFieldNames' => [
46  'datastructure' => 'ds',
47  ],
48  ],
49  'Members' => [
50  'mapFieldNames' => [
51  'pid' => '0',
52  'cruser_id' => '1',
53  'uid' => 'MemberID',
54  ],
55  ],
56  ],
57  ];
58  $this->subject = $this->prepareSubject('mssql', $configuration);
59  }
60 
65  {
66  $this->assertTrue($this->subject->runningADOdbDriver('mssql'));
67  }
68 
73  public function findInSetIsProperlyRemapped()
74  {
75  $expected = 'SELECT * FROM "fe_users" WHERE \',\'+"usergroup"+\',\' LIKE \'%,10,%\'';
76  $result = $this->subject->SELECTquery('*', 'fe_users', 'FIND_IN_SET(10, usergroup)');
77  $this->assertEquals($expected, $this->cleanSql($result));
78  }
79 
84  public function canParseSingleQuote()
85  {
86  $parseString = 'SELECT * FROM pages WHERE title=\'1\'\'\' AND deleted=0';
87  $components = $this->subject->SQLparser->_callRef('parseSELECT', $parseString);
88 
89  $this->assertTrue(is_array($components), $components);
90  $this->assertEmpty($components['parseString']);
91  }
92 
94  // Tests concerning remapping with
95  // external (non-TYPO3) databases
97 
101  public function canRemapPidToZero()
102  {
103  $selectFields = 'uid, FirstName, LastName';
104  $fromTables = 'Members';
105  $whereClause = 'pid=0 AND cruser_id=1';
106  $groupBy = '';
107  $orderBy = '';
108 
109  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
110  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
111  $expected = 'SELECT "MemberID", "FirstName", "LastName" FROM "Members" WHERE 0 = 0 AND 1 = 1';
112  $this->assertEquals($expected, $this->cleanSql($result));
113  }
114 
116  // Tests concerning advanced operators
118 
123  {
124  $result = $this->subject->SELECTquery('*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure)>0 THEN 2' . ' ELSE 1' . ' END AS scope', 'tx_templavoila_tmplobj', '1=1');
125  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure") > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
126  $this->assertEquals($expected, $this->cleanSql($result));
127  }
128 
134  {
135  $result = $this->subject->SELECTquery('*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope', 'tx_templavoila_tmplobj', '1=1');
136  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "datastructure", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
137  $this->assertEquals($expected, $this->cleanSql($result));
138  }
139 
145  {
146  $selectFields = '*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope';
147  $fromTables = 'tx_templavoila_tmplobj';
148  $whereClause = '1=1';
149  $groupBy = '';
150  $orderBy = '';
151  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
152 
153  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
154  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
155  $this->assertEquals($expected, $this->cleanSql($result));
156  }
157 
163  {
164  $selectFields = '*, CASE WHEN' . ' LOCATE(' . $this->subject->fullQuoteStr('(fce)', 'tx_templavoila_tmplobj') . ', tx_templavoila_tmplobj.datastructure, 4)>0 THEN 2' . ' ELSE 1' . ' END AS scope';
165  $fromTables = 'tx_templavoila_tmplobj';
166  $whereClause = '1=1';
167  $groupBy = '';
168  $orderBy = '';
169  $remappedParameters = $this->subject->_call('map_remapSELECTQueryParts', $selectFields, $fromTables, $whereClause, $groupBy, $orderBy);
170 
171  $result = $this->subject->_call('SELECTqueryFromArray', $remappedParameters);
172  $expected = 'SELECT *, CASE WHEN CHARINDEX(\'(fce)\', "tx_templavoila_tmplobj"."ds", 4) > 0 THEN 2 ELSE 1 END AS "scope" FROM "tx_templavoila_tmplobj" WHERE 1 = 1';
173  $this->assertEquals($expected, $this->cleanSql($result));
174  }
175 
180  public function IfNullIsProperlyRemapped()
181  {
182  $result = $this->subject->SELECTquery('*', 'tt_news_cat_mm', 'IFNULL(tt_news_cat_mm.uid_foreign,0) IN (21,22)');
183  $expected = 'SELECT * FROM "tt_news_cat_mm" WHERE ISNULL("tt_news_cat_mm"."uid_foreign", 0) IN (21,22)';
184  $this->assertEquals($expected, $this->cleanSql($result));
185  }
186 
192  {
193  $result = $this->subject->SELECTquery(
194  'ISEC.phash',
195  'index_section ISEC, index_fulltext IFT',
196  'IFT.fulltextdata LIKE \'%' . $this->subject->quoteStr("Don't worry", 'index_fulltext')
197  . '%\' AND ISEC.phash = IFT.phash',
198  'ISEC.phash'
199  );
200  $expected = 'SELECT "ISEC"."phash" FROM "index_section" "ISEC", "index_fulltext" "IFT" WHERE "IFT"."fulltextdata" LIKE \'%Don\'\'t worry%\' AND "ISEC"."phash" = "IFT"."phash" GROUP BY "ISEC"."phash"';
201  $this->assertEquals($expected, $this->cleanSql($result));
202  }
203 }