Merge "startup.js: log current time as global 'mediaWikiLoadStart'"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / ORMTableTest.php
index 2ed3dd3..7171ee5 100644 (file)
  * @ingroup Test
  *
  * @group ORM
+ * @group Database
  *
  * @licence GNU GPL v2+
  * @author Jeroen De Dauw < jeroendedauw@gmail.com >
+ * @author Daniel Kinzler
  */
-abstract class ORMTableTest extends MediaWikiTestCase {
+
+/**
+ * @covers PageORMTableForTesting
+ */
+class ORMTableTest extends MediaWikiTestCase {
 
        /**
         * @since 1.21
         * @return string
         */
-       protected abstract function getTableClass();
+       protected function getTableClass() {
+               return 'PageORMTableForTesting';
+       }
 
        /**
         * @since 1.21
@@ -41,6 +49,7 @@ abstract class ORMTableTest extends MediaWikiTestCase {
         */
        public function getTable() {
                $class = $this->getTableClass();
+
                return $class::singleton();
        }
 
@@ -62,4 +71,80 @@ abstract class ORMTableTest extends MediaWikiTestCase {
                $this->assertTrue( $class::singleton() === $class::singleton() );
        }
 
+       /**
+        * @since 1.21
+        */
+       public function testIgnoreErrorsOverride() {
+               $table = $this->getTable();
+
+               $db = $table->getReadDbConnection();
+               $db->ignoreErrors( true );
+
+               try {
+                       $table->rawSelect( "this is invalid" );
+                       $this->fail( "An invalid query should trigger a DBQueryError even if ignoreErrors is enabled." );
+               } catch ( DBQueryError $ex ) {
+                       $this->assertTrue( true, "just making phpunit happy" );
+               }
+
+               $db->ignoreErrors( false );
+       }
+}
+
+/**
+ * Dummy ORM table for testing, reading Title objects from the page table.
+ *
+ * @since 1.21
+ */
+
+class PageORMTableForTesting extends ORMTable {
+
+       /**
+        * @see ORMTable::getName
+        *
+        * @return string
+        */
+       public function getName() {
+               return 'page';
+       }
+
+       /**
+        * @see ORMTable::getRowClass
+        *
+        * @return string
+        */
+       public function getRowClass() {
+               return 'Title';
+       }
+
+       /**
+        * @see ORMTable::newRow
+        *
+        * @return IORMRow
+        */
+       public function newRow( array $data, $loadDefaults = false ) {
+               return Title::makeTitle( $data['namespace'], $data['title'] );
+       }
+
+       /**
+        * @see ORMTable::getFields
+        *
+        * @return array
+        */
+       public function getFields() {
+               return array(
+                       'id' => 'int',
+                       'namespace' => 'int',
+                       'title' => 'str',
+               );
+       }
+
+       /**
+        * @see ORMTable::getFieldPrefix
+        *
+        * @return string
+        */
+       protected function getFieldPrefix() {
+               return 'page_';
+       }
 }