Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / libs / rdbms / database / DatabaseDomainTest.php
blobd13fbf93416e1b966de50f3c6c02e1ff7ef19cb1
1 <?php
3 /**
4 * @covers DatabaseDomain
5 */
6 class DatabaseDomainTest extends PHPUnit_Framework_TestCase {
7 public static function provideConstruct() {
8 return [
9 // All strings
10 [ 'foo', 'bar', 'baz', 'foo-bar-baz' ],
11 // Nothing
12 [ null, null, '', '' ],
13 // Invalid $database
14 [ 0, 'bar', '', '', true ],
15 // - in one of the fields
16 [ 'foo-bar', 'baz', 'baa', 'foo?hbar-baz-baa' ],
17 // ? in one of the fields
18 [ 'foo?bar', 'baz', 'baa', 'foo??bar-baz-baa' ],
22 /**
23 * @dataProvider provideConstruct
25 public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
26 if ( $exception ) {
27 $this->setExpectedException( InvalidArgumentException::class );
30 $domain = new DatabaseDomain( $db, $schema, $prefix );
31 $this->assertInstanceOf( DatabaseDomain::class, $domain );
32 $this->assertEquals( $db, $domain->getDatabase() );
33 $this->assertEquals( $schema, $domain->getSchema() );
34 $this->assertEquals( $prefix, $domain->getTablePrefix() );
35 $this->assertEquals( $id, $domain->getId() );
38 public static function provideNewFromId() {
39 return [
40 // basic
41 [ 'foo', 'foo', null, '' ],
42 // <database>-<prefix>
43 [ 'foo-bar', 'foo', null, 'bar' ],
44 [ 'foo-bar-baz', 'foo', 'bar', 'baz' ],
45 // ?h -> -
46 [ 'foo?hbar-baz-baa', 'foo-bar', 'baz', 'baa' ],
47 // ?? -> ?
48 [ 'foo??bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
49 // ? is left alone
50 [ 'foo?bar-baz-baa', 'foo?bar', 'baz', 'baa' ],
51 // too many parts
52 [ 'foo-bar-baz-baa', '', '', '', true ],
56 /**
57 * @dataProvider provideNewFromId
59 public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
60 if ( $exception ) {
61 $this->setExpectedException( InvalidArgumentException::class );
63 $domain = DatabaseDomain::newFromId( $id );
64 $this->assertInstanceOf( DatabaseDomain::class, $domain );
65 $this->assertEquals( $db, $domain->getDatabase() );
66 $this->assertEquals( $schema, $domain->getSchema() );
67 $this->assertEquals( $prefix, $domain->getTablePrefix() );