Go to the documentation of this file.
14 protected function setUp() {
34 isset( $sql[
'conds'] ) ? $sql[
'conds'] :
array(),
36 isset( $sql[
'options'] ) ? $sql[
'options'] :
array(),
37 isset( $sql[
'join_conds'] ) ? $sql[
'join_conds'] :
array()
47 'fields' =>
array(
'field',
'alias' =>
'field2' ),
48 'conds' =>
array(
'alias' =>
'text' ),
50 "SELECT field,field2 AS alias " .
52 "WHERE alias = 'text'"
57 'fields' =>
array(
'field',
'alias' =>
'field2' ),
58 'conds' =>
array(
'alias' =>
'text' ),
59 'options' =>
array(
'LIMIT' => 1,
'ORDER BY' =>
'field' ),
61 "SELECT field,field2 AS alias " .
63 "WHERE alias = 'text' " .
69 'tables' =>
array(
'table',
't2' =>
'table2' ),
70 'fields' =>
array(
'tid',
'field',
'alias' =>
'field2',
't2.id' ),
71 'conds' =>
array(
'alias' =>
'text' ),
72 'options' =>
array(
'LIMIT' => 1,
'ORDER BY' =>
'field' ),
74 'LEFT JOIN',
'tid = t2.id'
77 "SELECT tid,field,field2 AS alias,t2.id " .
78 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
79 "WHERE alias = 'text' " .
85 'tables' =>
array(
'table',
't2' =>
'table2' ),
86 'fields' =>
array(
'tid',
'field',
'alias' =>
'field2',
't2.id' ),
87 'conds' =>
array(
'alias' =>
'text' ),
88 'options' =>
array(
'LIMIT' => 1,
'GROUP BY' =>
'field',
'HAVING' =>
'COUNT(*) > 1' ),
90 'LEFT JOIN',
'tid = t2.id'
93 "SELECT tid,field,field2 AS alias,t2.id " .
94 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
95 "WHERE alias = 'text' " .
96 "GROUP BY field HAVING COUNT(*) > 1 " .
101 'tables' =>
array(
'table',
't2' =>
'table2' ),
102 'fields' =>
array(
'tid',
'field',
'alias' =>
'field2',
't2.id' ),
103 'conds' =>
array(
'alias' =>
'text' ),
104 'options' =>
array(
'LIMIT' => 1,
'GROUP BY' =>
array(
'field',
'field2' ),
'HAVING' =>
array(
'COUNT(*) > 1',
'field' => 1 ) ),
106 'LEFT JOIN',
'tid = t2.id'
109 "SELECT tid,field,field2 AS alias,t2.id " .
110 "FROM table LEFT JOIN table2 t2 ON ((tid = t2.id)) " .
111 "WHERE alias = 'text' " .
112 "GROUP BY field,field2 HAVING (COUNT(*) > 1) AND field = '1' " .
117 'tables' =>
array(
'table' ),
118 'fields' =>
array(
'alias' =>
'field' ),
119 'conds' =>
array(
'alias' =>
array( 1, 2, 3, 4 ) ),
121 "SELECT field AS alias " .
123 "WHERE alias IN ('1','2','3','4')"
132 public function testUpdate( $sql, $sqlText ) {
138 isset( $sql[
'options'] ) ? $sql[
'options'] :
array()
148 'values' =>
array(
'field' =>
'text',
'field2' =>
'text2' ),
149 'conds' =>
array(
'alias' =>
'text' ),
152 "SET field = 'text'" .
153 ",field2 = 'text2' " .
154 "WHERE alias = 'text'"
159 'values' =>
array(
'field = other',
'field2' =>
'text2' ),
160 'conds' =>
array(
'id' =>
'1' ),
163 "SET field = other" .
164 ",field2 = 'text2' " .
170 'values' =>
array(
'field = other',
'field2' =>
'text2' ),
174 "SET field = other" .
184 public function testDelete( $sql, $sqlText ) {
198 'conds' =>
array(
'alias' =>
'text' ),
200 "DELETE FROM table " .
201 "WHERE alias = 'text'"
217 public function testUpsert( $sql, $sqlText ) {
221 $sql[
'uniqueIndexes'],
232 'table' =>
'upsert_table',
233 'rows' =>
array(
'field' =>
'text',
'field2' =>
'text2' ),
234 'uniqueIndexes' =>
array(
'field' ),
235 'set' =>
array(
'field' =>
'set' ),
238 "UPDATE upsert_table " .
239 "SET field = 'set' " .
240 "WHERE ((field = 'text')); " .
241 "INSERT IGNORE INTO upsert_table " .
243 "VALUES ('text','text2'); " .
269 'delTable' =>
'table',
270 'joinTable' =>
'table_join',
272 'joinVar' =>
'field_join',
273 'conds' =>
array(
'alias' =>
'text' ),
275 "DELETE FROM table " .
277 "SELECT field_join FROM table_join WHERE alias = 'text'" .
282 'delTable' =>
'table',
283 'joinTable' =>
'table_join',
285 'joinVar' =>
'field_join',
288 "DELETE FROM table " .
290 "SELECT field_join FROM table_join " .
300 public function testInsert( $sql, $sqlText ) {
305 isset( $sql[
'options'] ) ? $sql[
'options'] :
array()
315 'rows' =>
array(
'field' =>
'text',
'field2' => 2 ),
317 "INSERT INTO table " .
319 "VALUES ('text','2')"
324 'rows' =>
array(
'field' =>
'text',
'field2' => 2 ),
325 'options' =>
'IGNORE',
327 "INSERT IGNORE INTO table " .
329 "VALUES ('text','2')"
335 array(
'field' =>
'text',
'field2' => 2 ),
336 array(
'field' =>
'multi',
'field2' => 3 ),
338 'options' =>
'IGNORE',
340 "INSERT IGNORE INTO table " .
360 isset( $sql[
'insertOptions'] ) ? $sql[
'insertOptions'] :
array(),
361 isset( $sql[
'selectOptions'] ) ? $sql[
'selectOptions'] :
array()
370 'destTable' =>
'insert_table',
371 'srcTable' =>
'select_table',
372 'varMap' =>
array(
'field_insert' =>
'field_select',
'field' =>
'field2' ),
375 "INSERT INTO insert_table " .
376 "(field_insert,field) " .
377 "SELECT field_select,field2 " .
382 'destTable' =>
'insert_table',
383 'srcTable' =>
'select_table',
384 'varMap' =>
array(
'field_insert' =>
'field_select',
'field' =>
'field2' ),
385 'conds' =>
array(
'field' => 2 ),
387 "INSERT INTO insert_table " .
388 "(field_insert,field) " .
389 "SELECT field_select,field2 " .
390 "FROM select_table " .
395 'destTable' =>
'insert_table',
396 'srcTable' =>
'select_table',
397 'varMap' =>
array(
'field_insert' =>
'field_select',
'field' =>
'field2' ),
398 'conds' =>
array(
'field' => 2 ),
399 'insertOptions' =>
'IGNORE',
400 'selectOptions' =>
array(
'ORDER BY' =>
'field' ),
402 "INSERT IGNORE INTO insert_table " .
403 "(field_insert,field) " .
404 "SELECT field_select,field2 " .
405 "FROM select_table " .
406 "WHERE field = '2' " .
419 $sql[
'uniqueIndexes'],
430 'table' =>
'replace_table',
431 'uniqueIndexes' =>
array(
'field' ),
432 'rows' =>
array(
'field' =>
'text',
'field2' =>
'text2' ),
434 "DELETE FROM replace_table " .
435 "WHERE ( field='text' ); " .
436 "INSERT INTO replace_table " .
438 "VALUES ('text','text2')"
442 'table' =>
'module_deps',
443 'uniqueIndexes' =>
array(
array(
'md_module',
'md_skin' ) ),
445 'md_module' =>
'module',
450 "DELETE FROM module_deps " .
451 "WHERE ( md_module='module' AND md_skin='skin' ); " .
452 "INSERT INTO module_deps " .
453 "(md_module,md_skin,md_deps) " .
454 "VALUES ('module','skin','deps')"
458 'table' =>
'module_deps',
459 'uniqueIndexes' =>
array(
array(
'md_module',
'md_skin' ) ),
462 'md_module' =>
'module',
466 'md_module' =>
'module2',
467 'md_skin' =>
'skin2',
468 'md_deps' =>
'deps2',
472 "DELETE FROM module_deps " .
473 "WHERE ( md_module='module' AND md_skin='skin' ); " .
474 "INSERT INTO module_deps " .
475 "(md_module,md_skin,md_deps) " .
476 "VALUES ('module','skin','deps'); " .
477 "DELETE FROM module_deps " .
478 "WHERE ( md_module='module2' AND md_skin='skin2' ); " .
479 "INSERT INTO module_deps " .
480 "(md_module,md_skin,md_deps) " .
481 "VALUES ('module2','skin2','deps2')"
485 'table' =>
'module_deps',
486 'uniqueIndexes' =>
array(
'md_module',
'md_skin' ),
489 'md_module' =>
'module',
493 'md_module' =>
'module2',
494 'md_skin' =>
'skin2',
495 'md_deps' =>
'deps2',
499 "DELETE FROM module_deps " .
500 "WHERE ( md_module='module' ) OR ( md_skin='skin' ); " .
501 "INSERT INTO module_deps " .
502 "(md_module,md_skin,md_deps) " .
503 "VALUES ('module','skin','deps'); " .
504 "DELETE FROM module_deps " .
505 "WHERE ( md_module='module2' ) OR ( md_skin='skin2' ); " .
506 "INSERT INTO module_deps " .
507 "(md_module,md_skin,md_deps) " .
508 "VALUES ('module2','skin2','deps2')"
512 'table' =>
'module_deps',
513 'uniqueIndexes' =>
array(),
515 'md_module' =>
'module',
520 "INSERT INTO module_deps " .
521 "(md_module,md_skin,md_deps) " .
522 "VALUES ('module','skin','deps')"
544 'table' =>
'replace_table',
545 'rows' =>
array(
'field' =>
'text',
'field2' =>
'text2' ),
547 "REPLACE INTO replace_table " .
549 "VALUES ('text','text2')"
559 $this->assertEquals( trim( $this->
database->conditional(
570 'conds' =>
array(
'field' =>
'text' ),
574 "(CASE WHEN field = 'text' THEN 1 ELSE NULL END)"
578 'conds' =>
array(
'field' =>
'text',
'field2' =>
'anothertext' ),
582 "(CASE WHEN field = 'text' AND field2 = 'anothertext' THEN 1 ELSE NULL END)"
586 'conds' =>
'field=1',
590 "(CASE WHEN field=1 THEN 1 ELSE NULL END)"
600 $this->assertEquals( trim( $this->
database->buildConcat(
608 array(
'field',
'field2' ),
609 "CONCAT(field,field2)"
612 array(
"'test'",
'field2' ),
613 "CONCAT('test',field2)"
623 $this->assertEquals( trim( $this->
database->buildLike(
654 $this->assertEquals( trim( $this->
database->unionQueries(
664 'sqls' =>
array(
'RAW SQL',
'RAW2SQL' ),
667 "(RAW SQL) UNION ALL (RAW2SQL)"
671 'sqls' =>
array(
'RAW SQL',
'RAW2SQL' ),
674 "(RAW SQL) UNION (RAW2SQL)"
678 'sqls' =>
array(
'RAW SQL',
'RAW2SQL',
'RAW3SQL' ),
681 "(RAW SQL) UNION (RAW2SQL) UNION (RAW3SQL)"
690 $this->
database->begin( __METHOD__ );
691 $this->
database->commit( __METHOD__ );
699 $this->
database->begin( __METHOD__ );
700 $this->
database->rollback( __METHOD__ );
709 $this->
database->dropTable(
'table', __METHOD__ );
718 $this->
database->dropTable(
'non_existing', __METHOD__ )
static provideUnionQueries()
static provideNativeReplace()
testBuildConcat( $stringList, $sqlText)
@dataProvider provideBuildConcat @covers DatabaseBase::buildConcat
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
DatabaseTestHelper $database
static provideDeleteJoin()
testDropTable()
@covers DatabaseBase::dropTable
testInsertSelect( $sql, $sqlText)
@dataProvider provideInsertSelect @covers DatabaseBase::insertSelect
Used by DatabaseBase::buildLike() to represent characters that have special meaning in SQL LIKE claus...
static provideBuildConcat()
testUnionQueries( $sql, $sqlText)
@dataProvider provideUnionQueries @covers DatabaseBase::unionQueries
testTransactionCommit()
@covers DatabaseBase::commit
testDeleteJoin( $sql, $sqlText)
@dataProvider provideDeleteJoin @covers DatabaseBase::deleteJoin
testUpsert( $sql, $sqlText)
@dataProvider provideUpsert @covers DatabaseBase::upsert
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
testConditional( $sql, $sqlText)
@dataProvider provideConditional @covers DatabaseBase::conditional
testDropNonExistingTable()
@covers DatabaseBase::dropTable
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the database
testInsert( $sql, $sqlText)
@dataProvider provideInsert @covers DatabaseBase::insert
testUpdate( $sql, $sqlText)
@dataProvider provideUpdate @covers DatabaseBase::update
testDelete( $sql, $sqlText)
@dataProvider provideDelete @covers DatabaseBase::delete
testTransactionRollback()
@covers DatabaseBase::rollback
Helper for testing the methods from the DatabaseBase class.
testReplace( $sql, $sqlText)
@dataProvider provideReplace @covers DatabaseBase::replace
testNativeReplace( $sql, $sqlText)
@dataProvider provideNativeReplace @covers DatabaseBase::nativeReplace
Test the abstract database layer This is a non DBMS depending test.
static provideConditional()
testBuildLike( $array, $sqlText)
@dataProvider provideBuildLike @covers DatabaseBase::buildLike
testSelect( $sql, $sqlText)
@dataProvider provideSelect @covers DatabaseBase::select
static provideInsertSelect()
static provideBuildLike()