10 use MediaWikiCoversValidator;
11 use PHPUnit4And6Compat;
16 [
'foo',
'bar',
'baz',
'foo-bar-baz' ],
18 [
null,
null,
'',
'' ],
19 'Invalid $database' =>
20 [ 0,
'bar',
'',
'',
true ],
22 [
'foo', 0,
'',
'',
true ],
24 [
'foo',
'bar', 0,
'',
true ],
26 [
'foo-bar',
'baz',
'baa',
'foo?hbar-baz-baa' ],
28 [
'foo?bar',
'baz',
'baa',
'foo??bar-baz-baa' ],
35 public function testConstruct( $db, $schema, $prefix, $id, $exception =
false ) {
37 $this->setExpectedException( InvalidArgumentException::class );
43 $this->assertInstanceOf( DatabaseDomain::class, $domain );
44 $this->assertEquals( $db, $domain->getDatabase() );
45 $this->assertEquals( $schema, $domain->getSchema() );
46 $this->assertEquals( $prefix, $domain->getTablePrefix() );
47 $this->assertEquals( $id, $domain->getId() );
48 $this->assertEquals( $id, strval( $domain ),
'toString' );
54 [
'foo',
'foo',
null,
'' ],
56 [
'foo-bar',
'foo',
null,
'bar' ],
58 [
'foo-bar-baz',
'foo',
'bar',
'baz' ],
60 [
'foo?hbar-baz-baa',
'foo-bar',
'baz',
'baa' ],
62 [
'foo??bar-baz-baa',
'foo?bar',
'baz',
'baa' ],
64 [
'foo?bar-baz-baa',
'foo?bar',
'baz',
'baa' ],
66 [
'foo-bar-baz-baa',
'',
'',
'',
true ],
68 [ DatabaseDomain::newUnspecified(),
null,
null,
'' ],
75 public function testNewFromId( $id, $db, $schema, $prefix, $exception =
false ) {
77 $this->setExpectedException( InvalidArgumentException::class );
78 DatabaseDomain::newFromId( $id );
81 $domain = DatabaseDomain::newFromId( $id );
82 $this->assertInstanceOf( DatabaseDomain::class, $domain );
83 $this->assertEquals( $db, $domain->getDatabase() );
84 $this->assertEquals( $schema, $domain->getSchema() );
85 $this->assertEquals( $prefix, $domain->getTablePrefix() );
91 [
'foo',
'foo',
null,
'' ],
93 [
'foo-bar',
'foo',
null,
'bar' ],
95 [
'foo-bar-baz',
'foo',
'bar',
'baz' ],
97 [
'foo?hbar-baz-baa',
'foo-bar',
'baz',
'baa' ],
99 [
'foo??bar-baz-baa',
'foo?bar',
'baz',
'baa' ],
101 [
'',
null,
null,
'' ],
110 $fromId = DatabaseDomain::newFromId( $id );
111 $this->assertInstanceOf( DatabaseDomain::class, $fromId );
115 $this->assertTrue( $constructed->equals( $id ),
'constructed equals string' );
116 $this->assertTrue( $fromId->equals( $id ),
'fromId equals string' );
118 $this->assertTrue( $constructed->equals( $fromId ),
'compare constructed to newId' );
119 $this->assertTrue( $fromId->equals( $constructed ),
'compare newId to constructed' );
126 $domain = DatabaseDomain::newUnspecified();
127 $this->assertInstanceOf( DatabaseDomain::class, $domain );
128 $this->assertTrue( $domain->equals(
'' ) );
129 $this->assertSame(
null, $domain->getDatabase() );
130 $this->assertSame(
null, $domain->getSchema() );
131 $this->assertSame(
'', $domain->getTablePrefix() );
137 [
'foo',
'foo',
null,
'',
true ],
139 [
'foo-bar',
'foo',
null,
'bar',
true ],
140 'db+schema+prefix' =>
141 [
'foo-bar-baz',
'foo',
'bar',
'baz',
true ],
142 'db+dontcare_schema+prefix' =>
143 [
'foo-bar-baz',
'foo',
null,
'baz',
false ],
145 [
'foo?hbar-baz-baa',
'foo-bar',
'baz',
'baa',
true ],
147 [
'foo??bar-baz-baa',
'foo?bar',
'baz',
'baa',
true ],
149 [
'',
null,
null,
'',
true ],
150 'dontcaredb+dontcaredbschema+prefix' =>
151 [
'mywiki-mediawiki-prefix',
null,
null,
'prefix',
false ],
152 'dontcaredb+schema+prefix' =>
153 [
'mywiki-schema-prefix',
null,
'schema',
'prefix',
false ],
154 'db+dontcareschema+prefix' =>
155 [
'mywiki-schema-prefix',
'mywiki',
null,
'prefix',
false ],
156 'postgres-db-jobqueue' =>
157 [
'postgres-mediawiki-',
'postgres',
null,
'',
false ]
166 $compareIdObj = DatabaseDomain::newFromId( $id );
167 $this->assertInstanceOf( DatabaseDomain::class, $compareIdObj );
171 $this->assertTrue( $fromId->isCompatible( $id ),
'constructed equals string' );
172 $this->assertTrue( $fromId->isCompatible( $compareIdObj ),
'fromId equals string' );
174 $this->assertEquals( $transitive, $compareIdObj->isCompatible( $fromId ),
175 'test transitivity of nulls components' );
180 'db+schema+prefix' =>
181 [
'mywiki-schema-prefix',
'thatwiki',
'schema',
'prefix' ],
182 'dontcaredb+dontcaredbschema+prefix' =>
183 [
'thatwiki-mediawiki-otherprefix',
null,
null,
'prefix' ],
184 'dontcaredb+schema+prefix' =>
185 [
'mywiki-otherschema-prefix',
null,
'schema',
'prefix' ],
186 'db+dontcareschema+prefix' =>
187 [
'notmywiki-schema-prefix',
'mywiki',
null,
'prefix' ],
196 $compareIdObj = DatabaseDomain::newFromId( $id );
197 $this->assertInstanceOf( DatabaseDomain::class, $compareIdObj );
201 $this->assertFalse( $fromId->isCompatible( $id ),
'constructed equals string' );
202 $this->assertFalse( $fromId->isCompatible( $compareIdObj ),
'fromId equals string' );
210 $this->assertTrue( $domain->isUnspecified() );
212 $this->assertFalse( $domain->isUnspecified() );
214 $this->assertFalse( $domain->isUnspecified() );
Wikimedia\Rdbms\DatabaseDomain.
testNewUnspecified()
Wikimedia\Rdbms\DatabaseDomain::newUnspecified.
static provideNewFromId()
testIsUnspecified()
Wikimedia\Rdbms\DatabaseDomain::isUnspecified.
testEquals( $id, $db, $schema, $prefix)
provideEquals Wikimedia\Rdbms\DatabaseDomain::equals
static provideIsCompatible()
static provideIsCompatible2()
static provideConstruct()
testNewFromId( $id, $db, $schema, $prefix, $exception=false)
provideNewFromId
testConstruct( $db, $schema, $prefix, $id, $exception=false)
provideConstruct
testIsCompatible2( $id, $db, $schema, $prefix)
provideIsCompatible2 Wikimedia\Rdbms\DatabaseDomain::isCompatible
testIsCompatible( $id, $db, $schema, $prefix, $transitive)
provideIsCompatible Wikimedia\Rdbms\DatabaseDomain::isCompatible
Class to handle database/prefix specification for IDatabase domains.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
processing should stop and the error should be shown to the user * false