wiki.techinc.nl/tests/phpunit/includes/db/TestORMRowTest.php

184 lines
4.3 KiB
PHP
Raw Normal View History

<?php
/**
* Tests for the TestORMRow class.
* TestORMRow is a dummy class to be able to test the abstract ORMRow class.
*
* 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
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @since 1.20
*
* @ingroup Test
*
* @group ORM
*
* 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";
class TestORMRowTest extends ORMRowTest {
/**
* @since 1.20
* @return string
*/
protected function getRowClass() {
return 'TestORMRow';
}
/**
* @since 1.20
* @return IORMTable
*/
protected function getTableInstance() {
return TestORMTable::singleton();
}
Clean and repair many phpunit tests (+ fix implied configuration) This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-08 10:56:20 +00:00
protected function setUp() {
parent::setUp();
$dbw = wfGetDB( DB_MASTER );
$isSqlite = $GLOBALS['wgDBtype'] === 'sqlite';
$idField = $isSqlite ? 'INTEGER' : 'INT unsigned';
$primaryKey = $isSqlite ? 'PRIMARY KEY AUTOINCREMENT' : 'auto_increment PRIMARY KEY';
$dbw->query(
'CREATE TABLE IF NOT EXISTS ' . $dbw->tableName( 'orm_test' ) . '(
test_id ' . $idField . ' NOT NULL ' . $primaryKey . ',
test_name VARCHAR(255) NOT NULL,
test_age TINYINT unsigned NOT NULL,
test_height FLOAT NOT NULL,
test_awesome TINYINT unsigned NOT NULL,
test_stuff BLOB NOT NULL,
test_moarstuff BLOB NOT NULL,
test_time varbinary(14) NOT NULL
);',
__METHOD__
);
}
protected function tearDown() {
$dbw = wfGetDB( DB_MASTER );
$dbw->dropTable( 'orm_test', __METHOD__ );
parent::tearDown();
}
public function constructorTestProvider() {
return array(
array(
array(
'name' => 'Foobar',
'time' => '20120101020202',
'age' => 42,
'height' => 9000.1,
'awesome' => true,
'stuff' => array( 13, 11, 7, 5, 3, 2 ),
'moarstuff' => (object)array( 'foo' => 'bar', 'bar' => array( 4, 2 ), 'baz' => true )
),
true
),
);
}
}
class TestORMRow extends ORMRow {}
class TestORMTable extends ORMTable {
/**
* Returns the name of the database table objects of this type are stored in.
*
* @since 1.20
*
* @return string
*/
public function getName() {
return 'orm_test';
}
/**
* Returns the name of a IORMRow implementing class that
* represents single rows in this table.
*
* @since 1.20
*
* @return string
*/
public function getRowClass() {
return 'TestORMRow';
}
/**
* Returns an array with the fields and their types this object contains.
* This corresponds directly to the fields in the database, without prefix.
*
* field name => type
*
* Allowed types:
* * id
* * str
* * int
* * float
* * bool
* * array
* * blob
*
* @since 1.20
*
* @return array
*/
public function getFields() {
return array(
'id' => 'id',
'name' => 'str',
'age' => 'int',
'height' => 'float',
'awesome' => 'bool',
'stuff' => 'array',
'moarstuff' => 'blob',
'time' => 'str', // TS_MW
);
}
/**
* Gets the db field prefix.
*
* @since 1.20
*
* @return string
*/
protected function getFieldPrefix() {
return 'test_';
}
}