MediaWiki  1.23.15
SiteTest.php
Go to the documentation of this file.
1 <?php
2 
32 class SiteTest extends MediaWikiTestCase {
33 
34  public function instanceProvider() {
35  return $this->arrayWrap( TestSites::getSites() );
36  }
37 
43  public function testGetInterwikiIds( Site $site ) {
44  $this->assertInternalType( 'array', $site->getInterwikiIds() );
45  }
46 
52  public function testGetNavigationIds( Site $site ) {
53  $this->assertInternalType( 'array', $site->getNavigationIds() );
54  }
55 
61  public function testAddNavigationId( Site $site ) {
62  $site->addNavigationId( 'foobar' );
63  $this->assertTrue( in_array( 'foobar', $site->getNavigationIds(), true ) );
64  }
65 
71  public function testAddInterwikiId( Site $site ) {
72  $site->addInterwikiId( 'foobar' );
73  $this->assertTrue( in_array( 'foobar', $site->getInterwikiIds(), true ) );
74  }
75 
81  public function testGetLanguageCode( Site $site ) {
82  $this->assertTypeOrValue( 'string', $site->getLanguageCode(), null );
83  }
84 
90  public function testSetLanguageCode( Site $site ) {
91  $site->setLanguageCode( 'en' );
92  $this->assertEquals( 'en', $site->getLanguageCode() );
93  }
94 
100  public function testNormalizePageName( Site $site ) {
101  $this->assertInternalType( 'string', $site->normalizePageName( 'Foobar' ) );
102  }
103 
109  public function testGetGlobalId( Site $site ) {
110  $this->assertTypeOrValue( 'string', $site->getGlobalId(), null );
111  }
112 
118  public function testSetGlobalId( Site $site ) {
119  $site->setGlobalId( 'foobar' );
120  $this->assertEquals( 'foobar', $site->getGlobalId() );
121  }
122 
128  public function testGetType( Site $site ) {
129  $this->assertInternalType( 'string', $site->getType() );
130  }
131 
137  public function testGetPath( Site $site ) {
138  $this->assertTypeOrValue( 'string', $site->getPath( 'page_path' ), null );
139  $this->assertTypeOrValue( 'string', $site->getPath( 'file_path' ), null );
140  $this->assertTypeOrValue( 'string', $site->getPath( 'foobar' ), null );
141  }
142 
148  public function testGetAllPaths( Site $site ) {
149  $this->assertInternalType( 'array', $site->getAllPaths() );
150  }
151 
158  public function testSetAndRemovePath( Site $site ) {
159  $count = count( $site->getAllPaths() );
160 
161  $site->setPath( 'spam', 'http://www.wikidata.org/$1' );
162  $site->setPath( 'spam', 'http://www.wikidata.org/foo/$1' );
163  $site->setPath( 'foobar', 'http://www.wikidata.org/bar/$1' );
164 
165  $this->assertEquals( $count + 2, count( $site->getAllPaths() ) );
166 
167  $this->assertInternalType( 'string', $site->getPath( 'foobar' ) );
168  $this->assertEquals( 'http://www.wikidata.org/foo/$1', $site->getPath( 'spam' ) );
169 
170  $site->removePath( 'spam' );
171  $site->removePath( 'foobar' );
172 
173  $this->assertEquals( $count, count( $site->getAllPaths() ) );
174 
175  $this->assertNull( $site->getPath( 'foobar' ) );
176  $this->assertNull( $site->getPath( 'spam' ) );
177  }
178 
182  public function testSetLinkPath() {
183  $site = new Site();
184  $path = "TestPath/$1";
185 
186  $site->setLinkPath( $path );
187  $this->assertEquals( $path, $site->getLinkPath() );
188  }
189 
193  public function testGetLinkPathType() {
194  $site = new Site();
195 
196  $path = 'TestPath/$1';
197  $site->setLinkPath( $path );
198  $this->assertEquals( $path, $site->getPath( $site->getLinkPathType() ) );
199 
200  $path = 'AnotherPath/$1';
201  $site->setPath( $site->getLinkPathType(), $path );
202  $this->assertEquals( $path, $site->getLinkPath() );
203  }
204 
208  public function testSetPath() {
209  $site = new Site();
210 
211  $path = 'TestPath/$1';
212  $site->setPath( 'foo', $path );
213 
214  $this->assertEquals( $path, $site->getPath( 'foo' ) );
215  }
216 
221  public function testProtocolRelativePath() {
222  $site = new Site();
223 
224  $type = $site->getLinkPathType();
225  $path = '//acme.com/'; // protocol-relative URL
226  $site->setPath( $type, $path );
227 
228  $this->assertEquals( '', $site->getProtocol() );
229  }
230 
231  public static function provideGetPageUrl() {
232  //NOTE: the assumption that the URL is built by replacing $1
233  // with the urlencoded version of $page
234  // is true for Site but not guaranteed for subclasses.
235  // Subclasses need to override this provider appropriately.
236 
237  return array(
238  array( #0
239  'http://acme.test/TestPath/$1',
240  'Foo',
241  '/TestPath/Foo',
242  ),
243  array( #1
244  'http://acme.test/TestScript?x=$1&y=bla',
245  'Foo',
246  'TestScript?x=Foo&y=bla',
247  ),
248  array( #2
249  'http://acme.test/TestPath/$1',
250  'foo & bar/xyzzy (quux-shmoox?)',
251  '/TestPath/foo%20%26%20bar%2Fxyzzy%20%28quux-shmoox%3F%29',
252  ),
253  );
254  }
255 
260  public function testGetPageUrl( $path, $page, $expected ) {
261  $site = new Site();
262 
263  //NOTE: the assumption that getPageUrl is based on getLinkPath
264  // is true for Site but not guaranteed for subclasses.
265  // Subclasses need to override this test case appropriately.
266  $site->setLinkPath( $path );
267  $this->assertContains( $path, $site->getPageUrl() );
268 
269  $this->assertContains( $expected, $site->getPageUrl( $page ) );
270  }
271 
272  protected function assertTypeOrFalse( $type, $value ) {
273  if ( $value === false ) {
274  $this->assertTrue( true );
275  } else {
276  $this->assertInternalType( $type, $value );
277  }
278  }
279 
286  public function testSerialization( Site $site ) {
287  $this->assertInstanceOf( 'Serializable', $site );
288 
289  $serialization = serialize( $site );
290  $newInstance = unserialize( $serialization );
291 
292  $this->assertInstanceOf( 'Site', $newInstance );
293 
294  $this->assertEquals( $serialization, serialize( $newInstance ) );
295  }
296 }
SiteTest\testGetLinkPathType
testGetLinkPathType()
@covers Site::getLinkPathType
Definition: SiteTest.php:193
SiteTest\testSetLanguageCode
testSetLanguageCode(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:90
Site\getInterwikiIds
getInterwikiIds()
Returns the interwiki link identifiers that can be used for this site.
Definition: Site.php:533
SiteTest\testSetGlobalId
testSetGlobalId(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:118
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
SiteTest\testAddInterwikiId
testAddInterwikiId(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:71
TestSites\getSites
static getSites()
Definition: TestSites.php:39
Site\getType
getType()
Returns the type of the site (ie mediawiki).
Definition: Site.php:161
SiteTest\assertTypeOrFalse
assertTypeOrFalse( $type, $value)
Definition: SiteTest.php:272
Site\getPath
getPath( $pathType)
Returns the path of the provided type or false if there is no such path.
Definition: Site.php:592
SiteTest\testGetInterwikiIds
testGetInterwikiIds(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:43
Site\getLanguageCode
getLanguageCode()
Returns language code of the sites primary language.
Definition: Site.php:444
SiteTest\instanceProvider
instanceProvider()
Definition: SiteTest.php:34
true
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
Definition: hooks.txt:1530
SiteTest\testGetPageUrl
testGetPageUrl( $path, $page, $expected)
@dataProvider provideGetPageUrl @covers Site::getPageUrl
Definition: SiteTest.php:260
SiteTest\provideGetPageUrl
static provideGetPageUrl()
Definition: SiteTest.php:231
SiteTest\testAddNavigationId
testAddNavigationId(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:61
SiteTest\testSetPath
testSetPath()
@covers Site::setPath
Definition: SiteTest.php:208
SiteTest\testGetAllPaths
testGetAllPaths(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:148
SiteTest\testSetLinkPath
testSetLinkPath()
@covers Site::setLinkPath
Definition: SiteTest.php:182
Site\getGlobalId
getGlobalId()
Returns the global site identifier (ie enwiktionary).
Definition: Site.php:133
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
SiteTest\testGetNavigationIds
testGetNavigationIds(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:52
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SiteTest\testNormalizePageName
testNormalizePageName(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:100
Site\setLanguageCode
setLanguageCode( $languageCode)
Sets language code of the sites primary language.
Definition: Site.php:455
SiteTest\testGetType
testGetType(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:128
SiteTest\testGetPath
testGetPath(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:137
Site\addInterwikiId
addInterwikiId( $identifier)
Adds an interwiki id to the site.
Definition: Site.php:511
SiteTest\testSerialization
testSerialization(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:286
MediaWikiTestCase\arrayWrap
arrayWrap(array $elements)
Utility method taking an array of elements and wrapping each element in it's own array.
Definition: MediaWikiTestCase.php:743
Site
Definition: Site.php:29
Site\addNavigationId
addNavigationId( $identifier)
Adds a navigation id to the site.
Definition: Site.php:522
$value
$value
Definition: styleTest.css.php:45
MediaWikiTestCase\assertTypeOrValue
assertTypeOrValue( $type, $actual, $value=false, $message='')
Asserts that the provided variable is of the specified internal type or equals the $value argument.
Definition: MediaWikiTestCase.php:850
SiteTest
Definition: SiteTest.php:32
Site\setPath
setPath( $pathType, $fullUrl)
Sets the path used to construct links with.
Definition: Site.php:571
Site\getNavigationIds
getNavigationIds()
Returns the equivalent link identifiers that can be used to make the site show up in interfaces such ...
Definition: Site.php:545
Site\getAllPaths
getAllPaths()
Returns the paths as associative array.
Definition: Site.php:605
Site\removePath
removePath( $pathType)
Removes the path of the provided type if it's set.
Definition: Site.php:616
$count
$count
Definition: UtfNormalTest2.php:96
SiteTest\testGetGlobalId
testGetGlobalId(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:109
SiteTest\testGetLanguageCode
testGetLanguageCode(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:81
Site\setGlobalId
setGlobalId( $globalId)
Sets the global site identifier (ie enwiktionary).
Definition: Site.php:146
$path
$path
Definition: NoLocalSettings.php:35
Site\normalizePageName
normalizePageName( $pageName)
Returns $pageName without changes.
Definition: Site.php:388
SiteTest\testProtocolRelativePath
testProtocolRelativePath()
@covers Site::setPath @covers Site::getProtocol
Definition: SiteTest.php:221
SiteTest\testSetAndRemovePath
testSetAndRemovePath(Site $site)
@dataProvider instanceProvider
Definition: SiteTest.php:158
$type
$type
Definition: testCompression.php:46