Implement extension registration from an extension.json file
[mediawiki.git] / tests / phpunit / includes / site / SiteListFileCacheTest.php
blobb598eedab177d36ef1e8dc28047f47b17c284526
1 <?php
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.
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.
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
19 * @file
20 * @since 1.25
22 * @ingroup Site
23 * @ingroup Test
25 * @covers SiteListFileCache
26 * @group Site
28 * @licence GNU GPL v2+
29 * @author Katie Filbert < aude.wiki@gmail.com >
31 class SiteListFileCacheTest extends PHPUnit_Framework_TestCase {
33 public function testGetSites() {
34 $cacheFile = $this->getCacheFile();
36 $sites = $this->getSites();
37 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites, $cacheFile );
38 $cacheBuilder->build();
40 $cache = new SiteListFileCache( $cacheFile );
41 $this->assertEquals( $sites, $cache->getSites() );
44 public function testGetSite() {
45 $cacheFile = $this->getCacheFile();
47 $sites = $this->getSites();
48 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites, $cacheFile );
49 $cacheBuilder->build();
51 $cache = new SiteListFileCache( $cacheFile );
53 $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
56 private function newSiteListFileCacheBuilder( SiteList $sites, $cacheFile ) {
57 return new SiteListFileCacheBuilder(
58 $this->getSiteSQLStore( $sites ),
59 $cacheFile
63 private function getSiteSQLStore( SiteList $sites ) {
64 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
65 ->disableOriginalConstructor()
66 ->getMock();
68 $siteSQLStore->expects( $this->any() )
69 ->method( 'getSites' )
70 ->will( $this->returnValue( $sites ) );
72 return $siteSQLStore;
75 private function getSites() {
76 $sites = array();
78 $site = new Site();
79 $site->setGlobalId( 'foobar' );
80 $sites[] = $site;
82 $site = new MediaWikiSite();
83 $site->setGlobalId( 'enwiktionary' );
84 $site->setGroup( 'wiktionary' );
85 $site->setLanguageCode( 'en' );
86 $site->addNavigationId( 'enwiktionary' );
87 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
88 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
89 $sites[] = $site;
91 return new SiteList( $sites );
94 private function getCacheFile() {
95 return sys_get_temp_dir() . '/sites-' . time() . '.json';