summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/db/DatabaseTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/phpunit/includes/db/DatabaseTest.php')
-rw-r--r--tests/phpunit/includes/db/DatabaseTest.php62
1 files changed, 42 insertions, 20 deletions
diff --git a/tests/phpunit/includes/db/DatabaseTest.php b/tests/phpunit/includes/db/DatabaseTest.php
index 65c80d1d..301fc990 100644
--- a/tests/phpunit/includes/db/DatabaseTest.php
+++ b/tests/phpunit/includes/db/DatabaseTest.php
@@ -5,7 +5,11 @@
* @group DatabaseBase
*/
class DatabaseTest extends MediaWikiTestCase {
- var $db, $functionTest = false;
+ /**
+ * @var DatabaseBase
+ */
+ var $db;
+ var $functionTest = false;
protected function setUp() {
parent::setUp();
@@ -19,8 +23,10 @@ class DatabaseTest extends MediaWikiTestCase {
$this->functionTest = false;
}
}
-
- function testAddQuotesNull() {
+ /**
+ * @covers DatabaseBase::dropTable
+ */
+ public function testAddQuotesNull() {
$check = "NULL";
if ( $this->db->getType() === 'sqlite' || $this->db->getType() === 'oracle' ) {
$check = "''";
@@ -28,7 +34,7 @@ class DatabaseTest extends MediaWikiTestCase {
$this->assertEquals( $check, $this->db->addQuotes( null ) );
}
- function testAddQuotesInt() {
+ public function testAddQuotesInt() {
# returning just "1234" should be ok too, though...
# maybe
$this->assertEquals(
@@ -36,20 +42,20 @@ class DatabaseTest extends MediaWikiTestCase {
$this->db->addQuotes( 1234 ) );
}
- function testAddQuotesFloat() {
+ public function testAddQuotesFloat() {
# returning just "1234.5678" would be ok too, though
$this->assertEquals(
"'1234.5678'",
$this->db->addQuotes( 1234.5678 ) );
}
- function testAddQuotesString() {
+ public function testAddQuotesString() {
$this->assertEquals(
"'string'",
$this->db->addQuotes( 'string' ) );
}
- function testAddQuotesStringQuote() {
+ public function testAddQuotesStringQuote() {
$check = "'string''s cause trouble'";
if ( $this->db->getType() === 'mysql' ) {
$check = "'string\'s cause trouble'";
@@ -84,36 +90,46 @@ class DatabaseTest extends MediaWikiTestCase {
$quote = '';
} elseif ( $this->db->getType() === 'mysql' ) {
$quote = '`';
+ } elseif ( $this->db->getType() === 'oracle' ) {
+ $quote = '/*Q*/';
} else {
$quote = '"';
}
if ( $database !== null ) {
- $database = $quote . $database . $quote . '.';
+ if ( $this->db->getType() === 'oracle' ) {
+ $database = $quote . $database . '.';
+ } else {
+ $database = $quote . $database . $quote . '.';
+ }
}
if ( $prefix === null ) {
$prefix = $this->dbPrefix();
}
- return $database . $quote . $prefix . $table . $quote;
+ if ( $this->db->getType() === 'oracle' ) {
+ return strtoupper($database . $quote . $prefix . $table);
+ } else {
+ return $database . $quote . $prefix . $table . $quote;
+ }
}
- function testTableNameLocal() {
+ public function testTableNameLocal() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename' ),
$this->db->tableName( 'tablename' )
);
}
- function testTableNameRawLocal() {
+ public function testTableNameRawLocal() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename', null, null, 'raw' ),
$this->db->tableName( 'tablename', 'raw' )
);
}
- function testTableNameShared() {
+ public function testTableNameShared() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename', 'sharedatabase', 'sh_' ),
$this->getSharedTableName( 'tablename', 'sharedatabase', 'sh_' )
@@ -125,7 +141,7 @@ class DatabaseTest extends MediaWikiTestCase {
);
}
- function testTableNameRawShared() {
+ public function testTableNameRawShared() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename', 'sharedatabase', 'sh_', 'raw' ),
$this->getSharedTableName( 'tablename', 'sharedatabase', 'sh_', 'raw' )
@@ -137,21 +153,21 @@ class DatabaseTest extends MediaWikiTestCase {
);
}
- function testTableNameForeign() {
+ public function testTableNameForeign() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename', 'databasename', '' ),
$this->db->tableName( 'databasename.tablename' )
);
}
- function testTableNameRawForeign() {
+ public function testTableNameRawForeign() {
$this->assertEquals(
$this->prefixAndQuote( 'tablename', 'databasename', '', 'raw' ),
$this->db->tableName( 'databasename.tablename', 'raw' )
);
}
- function testFillPreparedEmpty() {
+ public function testFillPreparedEmpty() {
$sql = $this->db->fillPrepared(
'SELECT * FROM interwiki', array() );
$this->assertEquals(
@@ -159,7 +175,7 @@ class DatabaseTest extends MediaWikiTestCase {
$sql );
}
- function testFillPreparedQuestion() {
+ public function testFillPreparedQuestion() {
$sql = $this->db->fillPrepared(
'SELECT * FROM cur WHERE cur_namespace=? AND cur_title=?',
array( 4, "Snicker's_paradox" ) );
@@ -171,7 +187,7 @@ class DatabaseTest extends MediaWikiTestCase {
$this->assertEquals( $check, $sql );
}
- function testFillPreparedBang() {
+ public function testFillPreparedBang() {
$sql = $this->db->fillPrepared(
'SELECT user_id FROM ! WHERE user_name=?',
array( '"user"', "Slash's Dot" ) );
@@ -183,7 +199,7 @@ class DatabaseTest extends MediaWikiTestCase {
$this->assertEquals( $check, $sql );
}
- function testFillPreparedRaw() {
+ public function testFillPreparedRaw() {
$sql = $this->db->fillPrepared(
"SELECT * FROM cur WHERE cur_title='This_\\&_that,_WTF\\?\\!'",
array( '"user"', "Slash's Dot" ) );
@@ -192,7 +208,7 @@ class DatabaseTest extends MediaWikiTestCase {
$sql );
}
- function testStoredFunctions() {
+ public function testStoredFunctions() {
if ( !in_array( wfGetDB( DB_MASTER )->getType(), array( 'mysql', 'postgres' ) ) ) {
$this->markTestSkipped( 'MySQL or Postgres required' );
}
@@ -209,4 +225,10 @@ class DatabaseTest extends MediaWikiTestCase {
. ( $this->db->getType() == 'postgres' ? '()' : '' )
);
}
+
+ public function testUnknownTableCorruptsResults() {
+ $res = $this->db->select( 'page', '*', array( 'page_id' => 1 ) );
+ $this->assertFalse( $this->db->tableExists( 'foobarbaz' ) );
+ $this->assertInternalType( 'int', $res->numRows() );
+ }
}