4 * Abstract class to construct tests for ORMRow deriving classes.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
28 * The database group has as a side effect that temporal database tables are created. This makes
29 * it possible to test without poisoning a production database.
32 * Some of the tests takes more time, and needs therefor longer time before they can be aborted
33 * as non-functional. The reason why tests are aborted is assumed to be set up of temporal databases
34 * that hold the first tests in a pending state awaiting access to the database.
37 * @licence GNU GPL v2+
38 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
40 abstract class ORMRowTest
extends \MediaWikiTestCase
{
46 protected abstract function getRowClass();
52 protected abstract function getTableInstance();
58 public abstract function constructorTestProvider();
65 protected function verifyFields( IORMRow
$row, array $data ) {
66 foreach ( array_keys( $data ) as $fieldName ) {
67 $this->assertEquals( $data[$fieldName], $row->getField( $fieldName ) );
74 * @param boolean $loadDefaults
77 protected function getRowInstance( array $data, $loadDefaults ) {
78 $class = $this->getRowClass();
79 return new $class( $this->getTableInstance(), $data, $loadDefaults );
83 * @dataProvider constructorTestProvider
85 public function testConstructor( array $data, $loadDefaults ) {
86 $this->verifyFields( $this->getRowInstance( $data, $loadDefaults ), $data );
90 * @dataProvider constructorTestProvider
92 public function testSave( array $data, $loadDefaults ) {
93 $item = $this->getRowInstance( $data, $loadDefaults );
95 $this->assertTrue( $item->save() );
97 $this->assertTrue( $item->hasIdField() );
98 $this->assertTrue( is_integer( $item->getId() ) );
100 $id = $item->getId();
102 $this->assertTrue( $item->save() );
104 $this->assertEquals( $id, $item->getId() );
106 $this->verifyFields( $item, $data );
110 * @dataProvider constructorTestProvider
112 public function testRemove( array $data, $loadDefaults ) {
113 $item = $this->getRowInstance( $data, $loadDefaults );
115 $this->assertTrue( $item->save() );
117 $this->assertTrue( $item->remove() );
119 $this->assertFalse( $item->hasIdField() );
121 $this->assertTrue( $item->save() );
123 $this->verifyFields( $item, $data );
125 $this->assertTrue( $item->remove() );
127 $this->assertFalse( $item->hasIdField() );
129 $this->verifyFields( $item, $data );
132 // TODO: test all of the methods!