test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / db / ORMTableTest.php
blobe583d1bcac16f0634fc2fa96599a28eba7113b88
1 <?php
2 /**
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
20 * @file
21 * @since 1.21
23 * @ingroup Test
25 * @group ORM
26 * @group Database
28 * @licence GNU GPL v2+
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
30 * @author Daniel Kinzler
32 class ORMTableTest extends MediaWikiTestCase {
34 /**
35 * @since 1.21
36 * @return string
38 protected function getTableClass() {
39 return 'PageORMTableForTesting';
42 /**
43 * @since 1.21
44 * @return IORMTable
46 public function getTable() {
47 $class = $this->getTableClass();
49 return $class::singleton();
52 /**
53 * @since 1.21
54 * @return string
56 public function getRowClass() {
57 return $this->getTable()->getRowClass();
60 /**
61 * @since 1.21
63 public function testSingleton() {
64 $class = $this->getTableClass();
66 $this->assertInstanceOf( $class, $class::singleton() );
67 $this->assertTrue( $class::singleton() === $class::singleton() );
70 /**
71 * @since 1.21
73 public function testIgnoreErrorsOverride() {
74 $table = $this->getTable();
76 $db = $table->getReadDbConnection();
77 $db->ignoreErrors( true );
79 try {
80 $table->rawSelect( "this is invalid" );
81 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." );
82 } catch ( DBQueryError $ex ) {
83 $this->assertTrue( true, "just making phpunit happy" );
86 $db->ignoreErrors( false );
90 /**
91 * Dummy ORM table for testing, reading Title objects from the page table.
93 * @since 1.21
96 class PageORMTableForTesting extends ORMTable {
98 /**
99 * @see ORMTable::getName
101 * @return string
103 public function getName() {
104 return 'page';
108 * @see ORMTable::getRowClass
110 * @return string
112 public function getRowClass() {
113 return 'Title';
117 * @see ORMTable::newRow
119 * @return IORMRow
121 public function newRow( array $data, $loadDefaults = false ) {
122 return Title::makeTitle( $data['namespace'], $data['title'] );
126 * @see ORMTable::getFields
128 * @return array
130 public function getFields() {
131 return array(
132 'id' => 'int',
133 'namespace' => 'int',
134 'title' => 'str',
139 * @see ORMTable::getFieldPrefix
141 * @return string
143 protected function getFieldPrefix() {
144 return 'page_';