Merge "Ensure users are able to edit the page after changing the content model"
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / rdbms / database / DatabaseDomainTest.php
1 <?php
2
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' ],
19 ];
20 }
21
22 /**
23 * @dataProvider provideConstruct
24 */
25 public function testConstruct( $db, $schema, $prefix, $id, $exception = false ) {
26 if ( $exception ) {
27 $this->setExpectedException( InvalidArgumentException::class );
28 }
29
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() );
36 }
37
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 ],
53 ];
54 }
55
56 /**
57 * @dataProvider provideNewFromId
58 */
59 public function testNewFromId( $id, $db, $schema, $prefix, $exception = false ) {
60 if ( $exception ) {
61 $this->setExpectedException( InvalidArgumentException::class );
62 }
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() );
68 }
69 }