MediaWiki
REL1_22
|
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 00049 return $class::singleton(); 00050 } 00051 00056 public function getRowClass() { 00057 return $this->getTable()->getRowClass(); 00058 } 00059 00063 public function testSingleton() { 00064 $class = $this->getTableClass(); 00065 00066 $this->assertInstanceOf( $class, $class::singleton() ); 00067 $this->assertTrue( $class::singleton() === $class::singleton() ); 00068 } 00069 00073 public function testIgnoreErrorsOverride() { 00074 $table = $this->getTable(); 00075 00076 $db = $table->getReadDbConnection(); 00077 $db->ignoreErrors( true ); 00078 00079 try { 00080 $table->rawSelect( "this is invalid" ); 00081 $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." ); 00082 } catch ( DBQueryError $ex ) { 00083 $this->assertTrue( true, "just making phpunit happy" ); 00084 } 00085 00086 $db->ignoreErrors( false ); 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 }