Split SiteLookup interface from SiteStore
[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 * @group Site
28 *
29 * @licence GNU GPL v2+
30 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
31 */
32 class TestSites {
33
34 /**
35 * @since 1.21
36 *
37 * @return array
38 */
39 public static function getSites() {
40 $sites = array();
41
42 $site = new Site();
43 $site->setGlobalId( 'foobar' );
44 $sites[] = $site;
45
46 $site = new MediaWikiSite();
47 $site->setGlobalId( 'enwiktionary' );
48 $site->setGroup( 'wiktionary' );
49 $site->setLanguageCode( 'en' );
50 $site->addNavigationId( 'enwiktionary' );
51 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
52 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
53 $sites[] = $site;
54
55 $site = new MediaWikiSite();
56 $site->setGlobalId( 'dewiktionary' );
57 $site->setGroup( 'wiktionary' );
58 $site->setLanguageCode( 'de' );
59 $site->addInterwikiId( 'dewiktionary' );
60 $site->addInterwikiId( 'wiktionaryde' );
61 $site->setPath( MediaWikiSite::PATH_PAGE, "https://de.wiktionary.org/wiki/$1" );
62 $site->setPath( MediaWikiSite::PATH_FILE, "https://de.wiktionary.org/w/$1" );
63 $sites[] = $site;
64
65 $site = new Site();
66 $site->setGlobalId( 'spam' );
67 $site->setGroup( 'spam' );
68 $site->setLanguageCode( 'en' );
69 $site->addNavigationId( 'spam' );
70 $site->addNavigationId( 'spamz' );
71 $site->addInterwikiId( 'spamzz' );
72 $site->setLinkPath( "http://spamzz.test/testing/" );
73 $sites[] = $site;
74
75 /**
76 * Add at least one right-to-left language (current RTL languages in MediaWiki core are:
77 * aeb, ar, arc, arz, azb, bcc, bqi, ckb, dv, en_rtl, fa, glk, he, khw, kk_arab, kk_cn,
78 * ks_arab, ku_arab, lrc, mzn, pnb, ps, sd, ug_arab, ur, yi).
79 */
80 $languageCodes = array(
81 'de',
82 'en',
83 'fa', //right-to-left
84 'nl',
85 'nn',
86 'no',
87 'sr',
88 'sv',
89 );
90 foreach ( $languageCodes as $langCode ) {
91 $site = new MediaWikiSite();
92 $site->setGlobalId( $langCode . 'wiki' );
93 $site->setGroup( 'wikipedia' );
94 $site->setLanguageCode( $langCode );
95 $site->addInterwikiId( $langCode );
96 $site->addNavigationId( $langCode );
97 $site->setPath( MediaWikiSite::PATH_PAGE, "https://$langCode.wikipedia.org/wiki/$1" );
98 $site->setPath( MediaWikiSite::PATH_FILE, "https://$langCode.wikipedia.org/w/$1" );
99 $sites[] = $site;
100 }
101
102 return $sites;
103 }
104
105 /**
106 * Inserts sites into the database for the unit tests that need them.
107 *
108 * @since 0.1
109 */
110 public static function insertIntoDb() {
111 $sitesTable = new DBSiteStore();
112 $sitesTable->clear();
113 $sitesTable->saveSites( TestSites::getSites() );
114 }
115 }