Merge "(bug 43498) (bug 43574) Two wikilink types and {{int:}}."
[lhc/web/wiklou.git] / tests / phpunit / includes / db / ORMTableTest.php
1 <?php
2 /**
3 * Abstract class to construct tests for ORMTable deriving classes.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 * @since 1.21
22 *
23 * @ingroup Test
24 *
25 * @group ORM
26 * @group Database
27 *
28 * @licence GNU GPL v2+
29 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
30 * @author Daniel Kinzler
31 */
32 class ORMTableTest extends MediaWikiTestCase {
33
34 /**
35 * @since 1.21
36 * @return string
37 */
38 protected function getTableClass() {
39 return 'PageORMTableForTesting';
40 }
41
42 /**
43 * @since 1.21
44 * @return IORMTable
45 */
46 public function getTable() {
47 $class = $this->getTableClass();
48 return $class::singleton();
49 }
50
51 /**
52 * @since 1.21
53 * @return string
54 */
55 public function getRowClass() {
56 return $this->getTable()->getRowClass();
57 }
58
59 /**
60 * @since 1.21
61 */
62 public function testSingleton() {
63 $class = $this->getTableClass();
64
65 $this->assertInstanceOf( $class, $class::singleton() );
66 $this->assertTrue( $class::singleton() === $class::singleton() );
67 }
68
69 /**
70 * @since 1.21
71 */
72 public function testIgnoreErrorsOverride() {
73 $table = $this->getTable();
74
75 $db = $table->getReadDbConnection();
76 $db->ignoreErrors( true );
77
78 try {
79 $table->rawSelect( "this is invalid" );
80 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." );
81 } catch ( DBQueryError $ex ) {
82 $this->assertTrue( true, "just making phpunit happy" );
83 }
84
85 $db->ignoreErrors( false );
86 }
87
88 }
89
90 /**
91 * Dummy ORM table for testing, reading Title objects from the page table.
92 *
93 * @since 1.21
94 */
95
96 class PageORMTableForTesting extends ORMTable {
97
98 /**
99 * @see ORMTable::getName
100 *
101 * @return string
102 */
103 public function getName() {
104 return 'page';
105 }
106
107 /**
108 * @see ORMTable::getRowClass
109 *
110 * @return string
111 */
112 public function getRowClass() {
113 return 'Title';
114 }
115
116 /**
117 * @see ORMTable::newRow
118 *
119 * @return IORMRow
120 */
121 public function newRow( array $data, $loadDefaults = false ) {
122 return Title::makeTitle( $data['namespace'], $data['title'] );
123 }
124
125 /**
126 * @see ORMTable::getFields
127 *
128 * @return array
129 */
130 public function getFields() {
131 return array(
132 'id' => 'int',
133 'namespace' => 'int',
134 'title' => 'str',
135 );
136 }
137
138 /**
139 * @see ORMTable::getFieldPrefix
140 *
141 * @return string
142 */
143 protected function getFieldPrefix() {
144 return 'page_';
145 }
146 }