3 * Abstract class to construct tests for ORMTable deriving classes.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
28 * @covers PageORMTableForTesting
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
31 * @author Daniel Kinzler
34 class ORMTableTest
extends MediaWikiTestCase
{
40 protected function getTableClass() {
41 return 'PageORMTableForTesting';
48 public function getTable() {
49 $class = $this->getTableClass();
51 return $class::singleton();
58 public function getRowClass() {
59 return $this->getTable()->getRowClass();
65 public function testSingleton() {
66 $class = $this->getTableClass();
68 $this->assertInstanceOf( $class, $class::singleton() );
69 $this->assertTrue( $class::singleton() === $class::singleton() );
75 public function testIgnoreErrorsOverride() {
76 $table = $this->getTable();
78 $db = $table->getReadDbConnection();
79 $db->ignoreErrors( true );
82 $table->rawSelect( "this is invalid" );
83 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." );
84 } catch ( DBQueryError
$ex ) {
85 $this->assertTrue( true, "just making phpunit happy" );
88 $db->ignoreErrors( false );
93 * Dummy ORM table for testing, reading Title objects from the page table.
98 class PageORMTableForTesting
extends ORMTable
{
100 public function __construct() {
101 $this->fieldPrefix
= 'page_';
105 * @see ORMTable::getName
109 public function getName() {
114 * @see ORMTable::getRowClass
118 public function getRowClass() {
123 * @see ORMTable::newRow
127 public function newRow( array $data, $loadDefaults = false ) {
128 return Title
::makeTitle( $data['namespace'], $data['title'] );
132 * @see ORMTable::getFields
136 public function getFields() {
139 'namespace' => 'int',