MediaWiki
REL1_21
|
00001 <?php 00032 class ORMTableTest extends MediaWikiTestCase { 00033 00038 protected function getTableClass() { 00039 return 'PageORMTableForTesting'; 00040 } 00041 00046 public function getTable() { 00047 $class = $this->getTableClass(); 00048 return $class::singleton(); 00049 } 00050 00055 public function getRowClass() { 00056 return $this->getTable()->getRowClass(); 00057 } 00058 00062 public function testSingleton() { 00063 $class = $this->getTableClass(); 00064 00065 $this->assertInstanceOf( $class, $class::singleton() ); 00066 $this->assertTrue( $class::singleton() === $class::singleton() ); 00067 } 00068 00072 public function testIgnoreErrorsOverride() { 00073 $table = $this->getTable(); 00074 00075 $db = $table->getReadDbConnection(); 00076 $db->ignoreErrors( true ); 00077 00078 try { 00079 $table->rawSelect( "this is invalid" ); 00080 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." ); 00081 } catch ( DBQueryError $ex ) { 00082 $this->assertTrue( true, "just making phpunit happy" ); 00083 } 00084 00085 $db->ignoreErrors( false ); 00086 } 00087 00088 } 00089 00096 class PageORMTableForTesting extends ORMTable { 00097 00103 public function getName() { 00104 return 'page'; 00105 } 00106 00112 public function getRowClass() { 00113 return 'Title'; 00114 } 00115 00121 public function newRow( array $data, $loadDefaults = false ) { 00122 return Title::makeTitle( $data['namespace'], $data['title'] ); 00123 } 00124 00130 public function getFields() { 00131 return array( 00132 'id' => 'int', 00133 'namespace' => 'int', 00134 'title' => 'str', 00135 ); 00136 } 00137 00143 protected function getFieldPrefix() { 00144 return 'page_'; 00145 } 00146 }