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