MediaWiki
REL1_24
|
00001 <?php 00036 class ORMTableTest extends MediaWikiTestCase { 00037 00042 protected function getTableClass() { 00043 return 'PageORMTableForTesting'; 00044 } 00045 00050 public function getTable() { 00051 $class = $this->getTableClass(); 00052 00053 return $class::singleton(); 00054 } 00055 00060 public function getRowClass() { 00061 return $this->getTable()->getRowClass(); 00062 } 00063 00067 public function testSingleton() { 00068 $class = $this->getTableClass(); 00069 00070 $this->assertInstanceOf( $class, $class::singleton() ); 00071 $this->assertTrue( $class::singleton() === $class::singleton() ); 00072 } 00073 00077 public function testIgnoreErrorsOverride() { 00078 $table = $this->getTable(); 00079 00080 $db = $table->getReadDbConnection(); 00081 $db->ignoreErrors( true ); 00082 00083 try { 00084 $table->rawSelect( "this is invalid" ); 00085 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." ); 00086 } catch ( DBQueryError $ex ) { 00087 $this->assertTrue( true, "just making phpunit happy" ); 00088 } 00089 00090 $db->ignoreErrors( false ); 00091 } 00092 } 00093 00100 class PageORMTableForTesting extends ORMTable { 00101 00107 public function getName() { 00108 return 'page'; 00109 } 00110 00116 public function getRowClass() { 00117 return 'Title'; 00118 } 00119 00125 public function newRow( array $data, $loadDefaults = false ) { 00126 return Title::makeTitle( $data['namespace'], $data['title'] ); 00127 } 00128 00134 public function getFields() { 00135 return array( 00136 'id' => 'int', 00137 'namespace' => 'int', 00138 'title' => 'str', 00139 ); 00140 } 00141 00147 protected function getFieldPrefix() { 00148 return 'page_'; 00149 } 00150 }