Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / site / FileBasedSiteLookupTest.php
blob7984795b9917c482f6e959a5df26ee7a4ffdf467
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 FileBasedSiteLookup
26 * @group Site
28 * @author Katie Filbert < aude.wiki@gmail.com >
30 class FileBasedSiteLookupTest extends PHPUnit_Framework_TestCase {
32 protected function setUp() {
33 $this->cacheFile = $this->getCacheFile();
36 protected function tearDown() {
37 unlink( $this->cacheFile );
40 public function testGetSites() {
41 $sites = $this->getSites();
42 $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
43 $cacheBuilder->build();
45 $cache = new FileBasedSiteLookup( $this->cacheFile );
46 $this->assertEquals( $sites, $cache->getSites() );
49 public function testGetSite() {
50 $sites = $this->getSites();
51 $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
52 $cacheBuilder->build();
54 $cache = new FileBasedSiteLookup( $this->cacheFile );
56 $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
59 private function newSitesCacheFileBuilder( SiteList $sites ) {
60 return new SitesCacheFileBuilder(
61 $this->getSiteLookup( $sites ),
62 $this->cacheFile
66 private function getSiteLookup( SiteList $sites ) {
67 $siteLookup = $this->getMockBuilder( 'SiteLookup' )
68 ->disableOriginalConstructor()
69 ->getMock();
71 $siteLookup->expects( $this->any() )
72 ->method( 'getSites' )
73 ->will( $this->returnValue( $sites ) );
75 return $siteLookup;
78 private function getSites() {
79 $sites = [];
81 $site = new Site();
82 $site->setGlobalId( 'foobar' );
83 $sites[] = $site;
85 $site = new MediaWikiSite();
86 $site->setGlobalId( 'enwiktionary' );
87 $site->setGroup( 'wiktionary' );
88 $site->setLanguageCode( 'en' );
89 $site->addNavigationId( 'enwiktionary' );
90 $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
91 $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
92 $sites[] = $site;
94 return new SiteList( $sites );
97 private function getCacheFile() {
98 return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );