| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
use MediaWiki\Page\PageReference; |
| 23 |
use MediaWiki\Page\PageReferenceValue; |
| 24 |
use Wikimedia\Assert\ParameterAssertionException; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
class PageReferenceValueTest extends MediaWikiUnitTestCase { |
| 32 |
|
| 33 |
public static function goodConstructorProvider() { |
| 34 |
return [ |
| 35 |
[ NS_MAIN, 'Test', false ], |
| 36 |
[ NS_MAIN, 'Test', false ], |
| 37 |
[ NS_USER, 'Test', 'h2g2' ], |
| 38 |
[ NS_MEDIA, 'Test', false ], |
| 39 |
[ NS_SPECIAL, 'Test', false ], |
| 40 |
]; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public function testConstruction( $namespace, $dbKey, $wikiId ) { |
| 47 |
$pageReference = new PageReferenceValue( $namespace, $dbKey, $wikiId ); |
| 48 |
|
| 49 |
$this->assertSame( $wikiId, $pageReference->getWikiId() ); |
| 50 |
$this->assertSame( $namespace, $pageReference->getNamespace() ); |
| 51 |
$this->assertSame( $dbKey, $pageReference->getDBkey() ); |
| 52 |
} |
| 53 |
|
| 54 |
public static function badConstructorProvider() { |
| 55 |
return [ |
| 56 |
[ NS_MAIN, 'Test', 2.3 ], |
| 57 |
]; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function testConstructionErrors( $namespace, $dbKey, $wikiId ) { |
| 64 |
$this->expectException( ParameterAssertionException::class ); |
| 65 |
new PageReferenceValue( $namespace, $dbKey, $wikiId ); |
| 66 |
} |
| 67 |
|
| 68 |
public static function provideToString() { |
| 69 |
yield [ |
| 70 |
new PageReferenceValue( 0, 'Foo', PageReference::LOCAL ), |
| 71 |
'[0:Foo]' |
| 72 |
]; |
| 73 |
yield [ |
| 74 |
new PageReferenceValue( 1, 'Bar_Baz', PageReference::LOCAL ), |
| 75 |
'[1:Bar_Baz]' |
| 76 |
]; |
| 77 |
yield [ |
| 78 |
new PageReferenceValue( 200, 'tea', 'codewiki' ), |
| 79 |
'[200:tea]@codewiki' |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public function testToString( PageReferenceValue $value, $expected ) { |
| 87 |
$this->assertSame( |
| 88 |
$expected, |
| 89 |
$value->__toString() |
| 90 |
); |
| 91 |
} |
| 92 |
|
| 93 |
public static function provideIsSamePageAs() { |
| 94 |
yield [ |
| 95 |
new PageReferenceValue( 0, 'Foo', PageReference::LOCAL ), |
| 96 |
new PageReferenceValue( 0, 'Foo', PageReference::LOCAL ), |
| 97 |
true |
| 98 |
]; |
| 99 |
yield [ |
| 100 |
new PageReferenceValue( 1, 'Bar_Baz', PageReference::LOCAL ), |
| 101 |
new PageReferenceValue( 1, 'Bar_Baz', PageReference::LOCAL ), |
| 102 |
true |
| 103 |
]; |
| 104 |
yield [ |
| 105 |
new PageReferenceValue( 0, 'Foo', PageReference::LOCAL ), |
| 106 |
new PageReferenceValue( 0, 'Foozz', PageReference::LOCAL ), |
| 107 |
false |
| 108 |
]; |
| 109 |
yield [ |
| 110 |
new PageReferenceValue( 0, 'Foo', PageReference::LOCAL ), |
| 111 |
new PageReferenceValue( 1, 'Foo', PageReference::LOCAL ), |
| 112 |
false |
| 113 |
]; |
| 114 |
yield [ |
| 115 |
new PageReferenceValue( 0, 'Foo', '' ), |
| 116 |
new PageReferenceValue( 0, 'Foo', 'bar' ), |
| 117 |
false |
| 118 |
]; |
| 119 |
yield [ |
| 120 |
new PageReferenceValue( 0, 'Foo', '' ), |
| 121 |
new PageReferenceValue( 0, 'Foo', 'bar' ), |
| 122 |
false |
| 123 |
]; |
| 124 |
yield [ |
| 125 |
new PageReferenceValue( 0, 'Foo', 'bar' ), |
| 126 |
new PageReferenceValue( 0, 'Foo', 'bar' ), |
| 127 |
true |
| 128 |
]; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public function testIsSamePageAs( PageReferenceValue $a, PageReferenceValue $b, $expected ) { |
| 135 |
$this->assertSame( $expected, $a->isSamePageAs( $b ) ); |
| 136 |
$this->assertSame( $expected, $b->isSamePageAs( $a ) ); |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
public function testLocalIdentity() { |
| 143 |
$page = PageReferenceValue::localReference( NS_MAIN, __METHOD__ ); |
| 144 |
$this->assertSame( NS_MAIN, $page->getNamespace() ); |
| 145 |
$this->assertSame( __METHOD__, $page->getDBkey() ); |
| 146 |
$this->assertSame( PageReference::LOCAL, $page->getWikiId() ); |
| 147 |
} |
| 148 |
} |