Merge "Update some external conversion tables to latest versions"
[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 = Sites::newSite( 'foobar' );
43 $sites[] = $site;
44
45 $site = Sites::newSite( 'enwiktionary' );
46 $site->setGroup( 'wiktionary' );
47 $site->setType( Site::TYPE_MEDIAWIKI );
48 $site->setLanguageCode( 'en' );
49 $site->addNavigationId( 'enwiktionary' );
50 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
51 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
52 $sites[] = $site;
53
54 $site = Sites::newSite( 'dewiktionary' );
55 $site->setGroup( 'wiktionary' );
56 $site->setType( Site::TYPE_MEDIAWIKI );
57 $site->setLanguageCode( 'de' );
58 $site->addInterwikiId( 'dewiktionary' );
59 $site->addInterwikiId( 'wiktionaryde' );
60 $site->setPath( MediaWikiSite::PATH_PAGE, "https://de.wiktionary.org/wiki/$1" );
61 $site->setPath( MediaWikiSite::PATH_FILE, "https://de.wiktionary.org/w/$1" );
62 $sites[] = $site;
63
64 $site = Sites::newSite( 'spam' );
65 $site->setGroup( 'spam' );
66 $site->setType( Site::TYPE_UNKNOWN );
67 $site->setLanguageCode( 'en' );
68 $site->addNavigationId( 'spam' );
69 $site->addNavigationId( 'spamz' );
70 $site->addInterwikiId( 'spamzz' );
71 $site->setLinkPath( "http://spamzz.test/testing/" );
72 $sites[] = $site;
73
74 foreach ( array( 'en', 'de', 'nl', 'sv', 'sr', 'no', 'nn' ) as $langCode ) {
75 $site = Sites::newSite( $langCode . 'wiki' );
76 $site->setGroup( 'wikipedia' );
77 $site->setType( Site::TYPE_MEDIAWIKI );
78 $site->setLanguageCode( $langCode );
79 $site->addInterwikiId( $langCode );
80 $site->addNavigationId( $langCode );
81 $site->setPath( MediaWikiSite::PATH_PAGE, "https://$langCode.wikipedia.org/wiki/$1" );
82 $site->setPath( MediaWikiSite::PATH_FILE, "https://$langCode.wikipedia.org/w/$1" );
83 $sites[] = $site;
84 }
85
86 return $sites;
87 }
88
89 /**
90 * Inserts sites into the database for the unit tests that need them.
91 *
92 * @since 0.1
93 */
94 public static function insertIntoDb() {
95 $dbw = wfGetDB( DB_MASTER );
96
97 $dbw->begin( __METHOD__ );
98
99 $dbw->delete( 'sites', '*', __METHOD__ );
100 $dbw->delete( 'site_identifiers', '*', __METHOD__ );
101
102 /**
103 * @var Site $site
104 */
105 foreach ( TestSites::getSites() as $site ) {
106 $site->save();
107 }
108
109 $dbw->commit( __METHOD__ );
110
111 Sites::singleton()->getSites( false ); // re-cache
112 }
113
114 }