Merge "Selenium: replace UserLoginPage with BlankPage where possible"
[lhc/web/wiklou.git] / tests / phpunit / structure / DatabaseIntegrationTest.php
1 <?php
2
3 use Wikimedia\Rdbms\IDatabase;
4 use Wikimedia\Rdbms\Database;
5
6 /**
7 * @group Database
8 */
9 class DatabaseIntegrationTest extends MediaWikiTestCase {
10 /**
11 * @var Database
12 */
13 protected $db;
14
15 private $functionTest = false;
16
17 protected function setUp() {
18 parent::setUp();
19 $this->db = wfGetDB( DB_MASTER );
20 }
21
22 protected function tearDown() {
23 parent::tearDown();
24 if ( $this->functionTest ) {
25 $this->dropFunctions();
26 $this->functionTest = false;
27 }
28 $this->db->restoreFlags( IDatabase::RESTORE_INITIAL );
29 }
30
31 public function testStoredFunctions() {
32 if ( !in_array( wfGetDB( DB_MASTER )->getType(), [ 'mysql', 'postgres' ] ) ) {
33 $this->markTestSkipped( 'MySQL or Postgres required' );
34 }
35 global $IP;
36 $this->dropFunctions();
37 $this->functionTest = true;
38 $this->assertTrue(
39 $this->db->sourceFile( "$IP/tests/phpunit/data/db/{$this->db->getType()}/functions.sql" )
40 );
41 $res = $this->db->query( 'SELECT mw_test_function() AS test', __METHOD__ );
42 $this->assertEquals( 42, $res->fetchObject()->test );
43 }
44
45 private function dropFunctions() {
46 $this->db->query( 'DROP FUNCTION IF EXISTS mw_test_function'
47 . ( $this->db->getType() == 'postgres' ? '()' : '' )
48 );
49 }
50
51 public function testUnknownTableCorruptsResults() {
52 $res = $this->db->select( 'page', '*', [ 'page_id' => 1 ] );
53 $this->assertFalse( $this->db->tableExists( 'foobarbaz' ) );
54 $this->assertInternalType( 'int', $res->numRows() );
55 }
56 }