Add autocomplete for WhatLinksHere subpages
[lhc/web/wiklou.git] / tests / phpunit / includes / site / SiteListFileCacheBuilderTest.php
1 <?php
2
3 /**
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 * http://www.gnu.org/copyleft/gpl.html
18 *
19 * @file
20 * @since 1.25
21 *
22 * @ingroup Site
23 * @ingroup Test
24 *
25 * @covers SiteListFileCacheBuilder
26 * @group Site
27 *
28 * @licence GNU GPL v2+
29 * @author Katie Filbert < aude.wiki@gmail.com >
30 */
31 class SiteListFileCacheBuilderTest extends PHPUnit_Framework_TestCase {
32
33 public function testBuild() {
34 $cacheFile = $this->getCacheFile();
35
36 $cacheBuilder = $this->newSiteListFileCacheBuilder( $this->getSites(), $cacheFile );
37 $cacheBuilder->build();
38
39 $contents = file_get_contents( $cacheFile );
40 $this->assertEquals( json_encode( $this->getExpectedData() ), $contents );
41 }
42
43 private function getExpectedData() {
44 return array(
45 'sites' => array(
46 'foobar' => array(
47 'globalid' => 'foobar',
48 'type' => 'unknown',
49 'group' => 'none',
50 'source' => 'local',
51 'language' => null,
52 'localids' => array(),
53 'config' => array(),
54 'data' => array(),
55 'forward' => false,
56 'internalid' => null,
57 'identifiers' => array()
58 ),
59 'enwiktionary' => array(
60 'globalid' => 'enwiktionary',
61 'type' => 'mediawiki',
62 'group' => 'wiktionary',
63 'source' => 'local',
64 'language' => 'en',
65 'localids' => array(
66 'equivalent' => array( 'enwiktionary' )
67 ),
68 'config' => array(),
69 'data' => array(
70 'paths' => array(
71 'page_path' => 'https://en.wiktionary.org/wiki/$1',
72 'file_path' => 'https://en.wiktionary.org/w/$1'
73 )
74 ),
75 'forward' => false,
76 'internalid' => null,
77 'identifiers' => array(
78 array(
79 'type' => 'equivalent',
80 'key' => 'enwiktionary'
81 )
82 )
83 )
84 )
85 );
86 }
87
88 private function newSiteListFileCacheBuilder( SiteList $sites, $cacheFile ) {
89 return new SiteListFileCacheBuilder(
90 $this->getSiteSQLStore( $sites ),
91 $cacheFile
92 );
93 }
94
95 private function getSiteSQLStore( SiteList $sites ) {
96 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
97 ->disableOriginalConstructor()
98 ->getMock();
99
100 $siteSQLStore->expects( $this->any() )
101 ->method( 'getSites' )
102 ->will( $this->returnValue( $sites ) );
103
104 return $siteSQLStore;
105 }
106
107 private function getSites() {
108 $sites = array();
109
110 $site = new Site();
111 $site->setGlobalId( 'foobar' );
112 $sites[] = $site;
113
114 $site = new MediaWikiSite();
115 $site->setGlobalId( 'enwiktionary' );
116 $site->setGroup( 'wiktionary' );
117 $site->setLanguageCode( 'en' );
118 $site->addNavigationId( 'enwiktionary' );
119 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
120 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
121 $sites[] = $site;
122
123 return new SiteList( $sites );
124 }
125
126 private function getCacheFile() {
127 return sys_get_temp_dir() . '/sites-' . time() . '.json';
128 }
129
130 }