X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2Fdb%2FORMTableTest.php;h=7171ee591309dc00074a160a0a8ef0681fbe8edb;hb=32234445e06df7ba8f7508b16feff0a58d346348;hp=2ed3dd3a13882f1cb845c609a1669deede44d5ee;hpb=91442d70fd3578b31b54681d1b42e5057d52615c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/db/ORMTableTest.php b/tests/phpunit/includes/db/ORMTableTest.php index 2ed3dd3a13..7171ee5913 100644 --- a/tests/phpunit/includes/db/ORMTableTest.php +++ b/tests/phpunit/includes/db/ORMTableTest.php @@ -23,17 +23,25 @@ * @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_'; + } }