Make showDiffPage() protected
[lhc/web/wiklou.git] / tests / phpunit / includes / site / SiteListFileCacheTest.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 SiteListFileCache
26 * @group Site
27 *
28 * @licence GNU GPL v2+
29 * @author Katie Filbert < aude.wiki@gmail.com >
30 */
31 class SiteListFileCacheTest extends PHPUnit_Framework_TestCase {
32
33 public function testGetSites() {
34 $cacheFile = $this->getCacheFile();
35
36 $sites = $this->getSites();
37 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites, $cacheFile );
38 $cacheBuilder->build();
39
40 $cache = new SiteListFileCache( $cacheFile );
41 $this->assertEquals( $sites, $cache->getSites() );
42 }
43
44 public function testGetSite() {
45 $cacheFile = $this->getCacheFile();
46
47 $sites = $this->getSites();
48 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites, $cacheFile );
49 $cacheBuilder->build();
50
51 $cache = new SiteListFileCache( $cacheFile );
52
53 $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
54 }
55
56 private function newSiteListFileCacheBuilder( SiteList $sites, $cacheFile ) {
57 return new SiteListFileCacheBuilder(
58 $this->getSiteSQLStore( $sites ),
59 $cacheFile
60 );
61 }
62
63 private function getSiteSQLStore( SiteList $sites ) {
64 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
65 ->disableOriginalConstructor()
66 ->getMock();
67
68 $siteSQLStore->expects( $this->any() )
69 ->method( 'getSites' )
70 ->will( $this->returnValue( $sites ) );
71
72 return $siteSQLStore;
73 }
74
75 private function getSites() {
76 $sites = array();
77
78 $site = new Site();
79 $site->setGlobalId( 'foobar' );
80 $sites[] = $site;
81
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;
90
91 return new SiteList( $sites );
92 }
93
94 private function getCacheFile() {
95 return sys_get_temp_dir() . '/sites-' . time() . '.json';
96 }
97
98 }