MediaWiki  1.23.2
ORMRowTest.php
Go to the documentation of this file.
1 <?php
2 
40 abstract class ORMRowTest extends \MediaWikiTestCase {
41 
46  abstract protected function getRowClass();
47 
52  abstract protected function getTableInstance();
53 
58  abstract public function constructorTestProvider();
59 
65  protected function verifyFields( IORMRow $row, array $data ) {
66  foreach ( array_keys( $data ) as $fieldName ) {
67  $this->assertEquals( $data[$fieldName], $row->getField( $fieldName ) );
68  }
69  }
70 
77  protected function getRowInstance( array $data, $loadDefaults ) {
78  $class = $this->getRowClass();
79 
80  return new $class( $this->getTableInstance(), $data, $loadDefaults );
81  }
82 
87  protected function getMockValues() {
88  return array(
89  'id' => 1,
90  'str' => 'foobar4645645',
91  'int' => 42,
92  'float' => 4.2,
93  'bool' => true,
94  'array' => array( 42, 'foobar' ),
95  'blob' => new stdClass()
96  );
97  }
98 
103  protected function getMockFields() {
104  $mockValues = $this->getMockValues();
105  $mockFields = array();
106 
107  foreach ( $this->getTableInstance()->getFields() as $name => $type ) {
108  if ( $name !== 'id' ) {
109  $mockFields[$name] = $mockValues[$type];
110  }
111  }
112 
113  return $mockFields;
114  }
115 
120  public function instanceProvider() {
121  $instances = array();
122 
123  foreach ( $this->constructorTestProvider() as $arguments ) {
124  $instances[] = array( call_user_func_array( array( $this, 'getRowInstance' ), $arguments ) );
125  }
126 
127  return $instances;
128  }
129 
133  public function testConstructor( array $data, $loadDefaults ) {
134  $this->verifyFields( $this->getRowInstance( $data, $loadDefaults ), $data );
135  }
136 
140  public function testSaveAndRemove( array $data, $loadDefaults ) {
141  $item = $this->getRowInstance( $data, $loadDefaults );
142 
143  $this->assertTrue( $item->save() );
144 
145  $this->assertTrue( $item->hasIdField() );
146  $this->assertTrue( is_integer( $item->getId() ) );
147 
148  $id = $item->getId();
149 
150  $this->assertTrue( $item->save() );
151 
152  $this->assertEquals( $id, $item->getId() );
153 
154  $this->verifyFields( $item, $data );
155 
156  $this->assertTrue( $item->remove() );
157 
158  $this->assertFalse( $item->hasIdField() );
159 
160  $this->assertTrue( $item->save() );
161 
162  $this->verifyFields( $item, $data );
163 
164  $this->assertTrue( $item->remove() );
165 
166  $this->assertFalse( $item->hasIdField() );
167 
168  $this->verifyFields( $item, $data );
169  }
170 
174  public function testSetField( IORMRow $item ) {
175  foreach ( $this->getMockFields() as $name => $value ) {
176  $item->setField( $name, $value );
177  $this->assertEquals( $value, $item->getField( $name ) );
178  }
179  }
180 
186  protected function assertFieldValues( array $expected, IORMRow $item ) {
187  foreach ( $expected as $name => $type ) {
188  if ( $name !== 'id' ) {
189  $this->assertEquals( $expected[$name], $item->getField( $name ) );
190  }
191  }
192  }
193 
197  public function testSetFields( IORMRow $item ) {
198  $originalValues = $item->getFields();
199 
200  $item->setFields( array(), false );
201 
202  foreach ( $item->getTable()->getFields() as $name => $type ) {
203  $originalHas = array_key_exists( $name, $originalValues );
204  $newHas = $item->hasField( $name );
205 
206  $this->assertEquals( $originalHas, $newHas );
207 
208  if ( $originalHas && $newHas ) {
209  $this->assertEquals( $originalValues[$name], $item->getField( $name ) );
210  }
211  }
212 
213  $mockFields = $this->getMockFields();
214 
215  $item->setFields( $mockFields, false );
216 
217  $this->assertFieldValues( $originalValues, $item );
218 
219  $item->setFields( $mockFields, true );
220 
221  $this->assertFieldValues( $mockFields, $item );
222  }
223 
224  // TODO: test all of the methods!
225 
226 }
IORMRow\hasField
hasField( $name)
Gets if a certain field is set.
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
IORMRow
Definition: IORMRow.php:34
IORMRow\getFields
getFields()
Return the names and values of the fields.
IORMRow\getField
getField( $name, $default=null)
Gets the value of a field.
ORMRowTest\testSetFields
testSetFields(IORMRow $item)
@dataProvider instanceProvider
Definition: ORMRowTest.php:197
ORMRowTest\getMockFields
getMockFields()
Definition: ORMRowTest.php:103
IORMRow\setField
setField( $name, $value)
Sets the value of a field.
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
IORMRow\getTable
getTable()
Returns the table this IORMRow is a row in.
ORMRowTest\getRowInstance
getRowInstance(array $data, $loadDefaults)
Definition: ORMRowTest.php:77
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ORMRowTest\assertFieldValues
assertFieldValues(array $expected, IORMRow $item)
Definition: ORMRowTest.php:186
ORMRowTest\getMockValues
getMockValues()
Definition: ORMRowTest.php:87
ORMRowTest\testSetField
testSetField(IORMRow $item)
@dataProvider instanceProvider
Definition: ORMRowTest.php:174
ORMRowTest\verifyFields
verifyFields(IORMRow $row, array $data)
Definition: ORMRowTest.php:65
ORMRowTest\getRowClass
getRowClass()
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
$value
$value
Definition: styleTest.css.php:45
ORMRowTest\getTableInstance
getTableInstance()
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ORMRowTest\testConstructor
testConstructor(array $data, $loadDefaults)
@dataProvider constructorTestProvider
Definition: ORMRowTest.php:133
ORMRowTest\instanceProvider
instanceProvider()
Definition: ORMRowTest.php:120
ORMRowTest\testSaveAndRemove
testSaveAndRemove(array $data, $loadDefaults)
@dataProvider constructorTestProvider
Definition: ORMRowTest.php:140
ORMRowTest\constructorTestProvider
constructorTestProvider()
IORMRow\setFields
setFields(array $fields, $override=true)
Sets multiple fields.
ORMRowTest
Definition: ORMRowTest.php:40
$type
$type
Definition: testCompression.php:46