Debian Codegraph @

tests/phpunit/includes/site/TestSites.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Site;
4
5 use MediaWiki\MediaWikiServices;
6 use MediaWiki\Site\MediaWikiSite;
7 use MediaWiki\Site\Site;
8
9 /**
10 * Holds sites for testing purposes.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 * http://www.gnu.org/copyleft/gpl.html
26 *
27 * @file
28 * @since 1.21
29 *
30 * @ingroup Site
31 * @ingroup Test
32 *
33 * @author Jeroen De Dauw < [email protected] >
34 */
35 class TestSites {
36
37 /**
38 * @since 1.21
39 *
40 * @return array
41 */
42 public static function getSites() {
43 $sites = [];
44
45 $site = new Site();
46 $site->setGlobalId( 'foobar' );
47 $sites[] = $site;
48
49 $site = new MediaWikiSite();
50 $site->setGlobalId( 'enwiktionary' );
51 $site->setGroup( 'wiktionary' );
52 $site->setLanguageCode( 'en' );
53 $site->addNavigationId( 'enwiktionary' );
54 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
55 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
56 $sites[] = $site;
57
58 $site = new MediaWikiSite();
59 $site->setGlobalId( 'dewiktionary' );
60 $site->setGroup( 'wiktionary' );
61 $site->setLanguageCode( 'de' );
62 $site->addInterwikiId( 'dewiktionary' );
63 $site->addInterwikiId( 'wiktionaryde' );
64 $site->setPath( MediaWikiSite::PATH_PAGE, "https://de.wiktionary.org/wiki/$1" );
65 $site->setPath( MediaWikiSite::PATH_FILE, "https://de.wiktionary.org/w/$1" );
66 $sites[] = $site;
67
68 $site = new Site();
69 $site->setGlobalId( 'spam' );
70 $site->setGroup( 'spam' );
71 $site->setLanguageCode( 'en' );
72 $site->addNavigationId( 'spam' );
73 $site->addNavigationId( 'spamz' );
74 $site->addInterwikiId( 'spamzz' );
75 $site->setLinkPath( "http://spamzz.test/testing/" );
76 $sites[] = $site;
77
78 /**
79 * Add at least one right-to-left language (current RTL languages in MediaWiki core are:
80 * aeb, ar, arc, arz, azb, bcc, bqi, ckb, dv, en_rtl, fa, glk, he, khw, kk_arab, kk_cn,
81 * ks_arab, ku_arab, lrc, mzn, pnb, ps, sd, ug_arab, ur, yi).
82 */
83 $languageCodes = [
84 'de',
85 'en',
86 'fa', // right-to-left
87 'nl',
88 'nn',
89 'no',
90 'sr',
91 'sv',
92 ];
93 foreach ( $languageCodes as $langCode ) {
94 $site = new MediaWikiSite();
95 $site->setGlobalId( $langCode . 'wiki' );
96 $site->setGroup( 'wikipedia' );
97 $site->setLanguageCode( $langCode );
98 $site->addInterwikiId( $langCode );
99 $site->addNavigationId( $langCode );
100 $site->setPath( MediaWikiSite::PATH_PAGE, "https://$langCode.wikipedia.org/wiki/$1" );
101 $site->setPath( MediaWikiSite::PATH_FILE, "https://$langCode.wikipedia.org/w/$1" );
102 $sites[] = $site;
103 }
104
105 return $sites;
106 }
107
108 /**
109 * Inserts sites into the database for the unit tests that need them.
110 *
111 * @since 0.1
112 */
113 public static function insertIntoDb() {
114 $sitesTable = MediaWikiServices::getInstance()->getSiteStore();
115 $sitesTable->clear();
116 $sitesTable->saveSites( self::getSites() );
117 }
118 }
119
120 /** @deprecated class alias since 1.42 */
121 class_alias( TestSites::class, 'TestSites' );