summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/db
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/db')
-rw-r--r--tests/phpunit/includes/db/DatabaseMysqlBaseTest.php1
-rw-r--r--tests/phpunit/includes/db/DatabaseSQLTest.php80
-rw-r--r--tests/phpunit/includes/db/DatabaseSqliteTest.php45
-rw-r--r--tests/phpunit/includes/db/LBFactoryTest.php1
-rw-r--r--tests/phpunit/includes/db/ORMRowTest.php1
-rw-r--r--tests/phpunit/includes/db/ORMTableTest.php19
-rw-r--r--tests/phpunit/includes/db/TestORMRowTest.php37
7 files changed, 128 insertions, 56 deletions
diff --git a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
index 55e48d13..b4292a60 100644
--- a/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
+++ b/tests/phpunit/includes/db/DatabaseMysqlBaseTest.php
@@ -2,7 +2,6 @@
/**
* Holds tests for DatabaseMysqlBase MediaWiki class.
*
- * @section LICENSE
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
diff --git a/tests/phpunit/includes/db/DatabaseSQLTest.php b/tests/phpunit/includes/db/DatabaseSQLTest.php
index 5c2d4b70..b13751f3 100644
--- a/tests/phpunit/includes/db/DatabaseSQLTest.php
+++ b/tests/phpunit/includes/db/DatabaseSQLTest.php
@@ -722,4 +722,84 @@ class DatabaseSQLTest extends MediaWikiTestCase {
$this->database->dropTable( 'non_existing', __METHOD__ )
);
}
+
+ /**
+ * @dataProvider provideMakeList
+ * @covers DatabaseBase::makeList
+ */
+ public function testMakeList( $list, $mode, $sqlText ) {
+ $this->assertEquals( trim( $this->database->makeList(
+ $list, $mode
+ ) ), $sqlText );
+ }
+
+ public static function provideMakeList() {
+ return array(
+ array(
+ array( 'value', 'value2' ),
+ LIST_COMMA,
+ "'value','value2'"
+ ),
+ array(
+ array( 'field', 'field2' ),
+ LIST_NAMES,
+ "field,field2"
+ ),
+ array(
+ array( 'field' => 'value', 'field2' => 'value2' ),
+ LIST_AND,
+ "field = 'value' AND field2 = 'value2'"
+ ),
+ array(
+ array( 'field' => null, "field2 != 'value2'" ),
+ LIST_AND,
+ "field IS NULL AND (field2 != 'value2')"
+ ),
+ array(
+ array( 'field' => array( 'value', null, 'value2' ), 'field2' => 'value2' ),
+ LIST_AND,
+ "(field IN ('value','value2') OR field IS NULL) AND field2 = 'value2'"
+ ),
+ array(
+ array( 'field' => array( null ), 'field2' => null ),
+ LIST_AND,
+ "field IS NULL AND field2 IS NULL"
+ ),
+ array(
+ array( 'field' => 'value', 'field2' => 'value2' ),
+ LIST_OR,
+ "field = 'value' OR field2 = 'value2'"
+ ),
+ array(
+ array( 'field' => 'value', 'field2' => null ),
+ LIST_OR,
+ "field = 'value' OR field2 IS NULL"
+ ),
+ array(
+ array( 'field' => array( 'value', 'value2' ), 'field2' => array( 'value' ) ),
+ LIST_OR,
+ "field IN ('value','value2') OR field2 = 'value'"
+ ),
+ array(
+ array( 'field' => array( null, 'value', null, 'value2' ), "field2 != 'value2'" ),
+ LIST_OR,
+ "(field IN ('value','value2') OR field IS NULL) OR (field2 != 'value2')"
+ ),
+ array(
+ array( 'field' => 'value', 'field2' => 'value2' ),
+ LIST_SET,
+ "field = 'value',field2 = 'value2'"
+ ),
+ array(
+ array( 'field' => 'value', 'field2' => null ),
+ LIST_SET,
+ "field = 'value',field2 = NULL"
+ ),
+ array(
+ array( 'field' => 'value', "field2 != 'value2'" ),
+ LIST_SET,
+ "field = 'value',field2 != 'value2'"
+ ),
+ );
+ }
}
diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php
index 98b4ca04..645baf1f 100644
--- a/tests/phpunit/includes/db/DatabaseSqliteTest.php
+++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php
@@ -1,10 +1,12 @@
<?php
-class MockDatabaseSqlite extends DatabaseSqliteStandalone {
+class MockDatabaseSqlite extends DatabaseSqlite {
private $lastQuery;
- function __construct() {
- parent::__construct( ':memory:' );
+ public static function newInstance( array $p = array() ) {
+ $p['dbFilePath'] = ':memory:';
+
+ return new self( $p );
}
function query( $sql, $fname = '', $tempIgnore = false ) {
@@ -36,7 +38,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
if ( !Sqlite::isPresent() ) {
$this->markTestSkipped( 'No SQLite support detected' );
}
- $this->db = new MockDatabaseSqlite();
+ $this->db = MockDatabaseSqlite::newInstance();
if ( version_compare( $this->db->getServerVersion(), '3.6.0', '<' ) ) {
$this->markTestSkipped( "SQLite at least 3.6 required, {$this->db->getServerVersion()} found" );
}
@@ -89,7 +91,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
*/
public function testAddQuotes( $value, $expected ) {
// check quoting
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$this->assertEquals( $expected, $db->addQuotes( $value ), 'string not quoted as expected' );
// ok, quoting works as expected, now try a round trip.
@@ -172,7 +174,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
*/
public function testTableName() {
// @todo Moar!
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$this->assertEquals( 'foo', $db->tableName( 'foo' ) );
$this->assertEquals( 'sqlite_master', $db->tableName( 'sqlite_master' ) );
$db->tablePrefix( 'foo' );
@@ -184,7 +186,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @covers DatabaseSqlite::duplicateTableStructure
*/
public function testDuplicateTableStructure() {
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$db->query( 'CREATE TABLE foo(foo, barfoo)' );
$db->duplicateTableStructure( 'foo', 'bar' );
@@ -208,7 +210,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @covers DatabaseSqlite::duplicateTableStructure
*/
public function testDuplicateTableStructureVirtual() {
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
if ( $db->getFulltextSearchModule() != 'FTS3' ) {
$this->markTestSkipped( 'FTS3 not supported, cannot create virtual tables' );
}
@@ -231,7 +233,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @covers DatabaseSqlite::deleteJoin
*/
public function testDeleteJoin() {
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$db->query( 'CREATE TABLE a (a_1)', __METHOD__ );
$db->query( 'CREATE TABLE b (b_1, b_2)', __METHOD__ );
$db->insert( 'a', array(
@@ -272,7 +274,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @todo Currently only checks list of tables
*/
public function testUpgrades() {
- global $IP, $wgVersion, $wgProfileToDatabase;
+ global $IP, $wgVersion, $wgProfiler;
// Versions tested
$versions = array(
@@ -289,9 +291,20 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
'user_newtalk.user_last_timestamp', // r84185
);
- $currentDB = new DatabaseSqliteStandalone( ':memory:' );
+ $currentDB = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$currentDB->sourceFile( "$IP/maintenance/tables.sql" );
- if ( $wgProfileToDatabase ) {
+
+ $profileToDb = false;
+ if ( isset( $wgProfiler['output'] ) ) {
+ $out = $wgProfiler['output'];
+ if ( $out === 'db' ) {
+ $profileToDb = true;
+ } elseif ( is_array( $out ) && in_array( 'db', $out ) ) {
+ $profileToDb = true;
+ }
+ }
+
+ if ( $profileToDb ) {
$currentDB->sourceFile( "$IP/maintenance/sqlite/archives/patch-profiling.sql" );
}
$currentTables = $this->getTables( $currentDB );
@@ -346,7 +359,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @covers DatabaseSqlite::insertId
*/
public function testInsertIdType() {
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ );
$this->assertInstanceOf( 'ResultWrapper', $databaseCreation, "Database creation" );
@@ -366,7 +379,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
}
global $IP;
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$db->sourceFile( "$IP/tests/phpunit/data/db/sqlite/tables-$version.sql" );
$updater = DatabaseUpdater::newForDB( $db, false, $maint );
$updater->doUpdates( array( 'core' ) );
@@ -429,7 +442,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
public function testCaseInsensitiveLike() {
// TODO: Test this for all databases
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$res = $db->query( 'SELECT "a" LIKE "A" AS a' );
$row = $res->fetchRow();
$this->assertFalse( (bool)$row['a'] );
@@ -439,7 +452,7 @@ class DatabaseSqliteTest extends MediaWikiTestCase {
* @covers DatabaseSqlite::numFields
*/
public function testNumFields() {
- $db = new DatabaseSqliteStandalone( ':memory:' );
+ $db = DatabaseSqlite::newStandaloneInstance( ':memory:' );
$databaseCreation = $db->query( 'CREATE TABLE a ( a_1 )', __METHOD__ );
$this->assertInstanceOf( 'ResultWrapper', $databaseCreation, "Failed to create table a" );
diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php
index 4c59f474..81d6840b 100644
--- a/tests/phpunit/includes/db/LBFactoryTest.php
+++ b/tests/phpunit/includes/db/LBFactoryTest.php
@@ -2,7 +2,6 @@
/**
* Holds tests for LBFactory abstract MediaWiki class.
*
- * @section LICENSE
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
diff --git a/tests/phpunit/includes/db/ORMRowTest.php b/tests/phpunit/includes/db/ORMRowTest.php
index 447bf219..807bd14e 100644
--- a/tests/phpunit/includes/db/ORMRowTest.php
+++ b/tests/phpunit/includes/db/ORMRowTest.php
@@ -34,7 +34,6 @@
* that hold the first tests in a pending state awaiting access to the database.
* @group medium
*
- * @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
abstract class ORMRowTest extends \MediaWikiTestCase {
diff --git a/tests/phpunit/includes/db/ORMTableTest.php b/tests/phpunit/includes/db/ORMTableTest.php
index 7171ee59..338d931f 100644
--- a/tests/phpunit/includes/db/ORMTableTest.php
+++ b/tests/phpunit/includes/db/ORMTableTest.php
@@ -25,14 +25,12 @@
* @group ORM
* @group Database
*
- * @licence GNU GPL v2+
+ * @covers PageORMTableForTesting
+ *
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
* @author Daniel Kinzler
*/
-/**
- * @covers PageORMTableForTesting
- */
class ORMTableTest extends MediaWikiTestCase {
/**
@@ -99,6 +97,10 @@ class ORMTableTest extends MediaWikiTestCase {
class PageORMTableForTesting extends ORMTable {
+ public function __construct() {
+ $this->fieldPrefix = 'page_';
+ }
+
/**
* @see ORMTable::getName
*
@@ -138,13 +140,4 @@ class PageORMTableForTesting extends ORMTable {
'title' => 'str',
);
}
-
- /**
- * @see ORMTable::getFieldPrefix
- *
- * @return string
- */
- protected function getFieldPrefix() {
- return 'page_';
- }
}
diff --git a/tests/phpunit/includes/db/TestORMRowTest.php b/tests/phpunit/includes/db/TestORMRowTest.php
index c9459c90..04bb9f38 100644
--- a/tests/phpunit/includes/db/TestORMRowTest.php
+++ b/tests/phpunit/includes/db/TestORMRowTest.php
@@ -20,27 +20,23 @@
* http://www.gnu.org/copyleft/gpl.html
*
* @file
- * @since 1.20
- *
* @ingroup Test
- *
- * @group ORM
- *
+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ */
+
+/**
* The database group has as a side effect that temporal database tables are created. This makes
* it possible to test without poisoning a production database.
- * @group Database
*
* Some of the tests takes more time, and needs therefor longer time before they can be aborted
* as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
* that hold the first tests in a pending state awaiting access to the database.
- * @group medium
*
- * @licence GNU GPL v2+
- * @author Jeroen De Dauw < jeroendedauw@gmail.com >
- */
-require_once __DIR__ . "/ORMRowTest.php";
-
-/**
+ * @since 1.20
+ *
+ * @group ORM
+ * @group Database
+ * @group medium
* @covers TestORMRow
*/
class TestORMRowTest extends ORMRowTest {
@@ -150,6 +146,10 @@ class TestORMRow extends ORMRow {
class TestORMTable extends ORMTable {
+ public function __construct() {
+ $this->fieldPrefix = 'test_';
+ }
+
/**
* Returns the name of the database table objects of this type are stored in.
*
@@ -204,15 +204,4 @@ class TestORMTable extends ORMTable {
'time' => 'str', // TS_MW
);
}
-
- /**
- * Gets the db field prefix.
- *
- * @since 1.20
- *
- * @return string
- */
- protected function getFieldPrefix() {
- return 'test_';
- }
}