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
25 * @covers SiteListFileCache
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 ),
63 private function getSiteSQLStore( SiteList
$sites ) {
64 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
65 ->disableOriginalConstructor()
68 $siteSQLStore->expects( $this->any() )
69 ->method( 'getSites' )
70 ->will( $this->returnValue( $sites ) );
75 private function getSites() {
79 $site->setGlobalId( 'foobar' );
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" );
91 return new SiteList( $sites );
94 private function getCacheFile() {
95 return sys_get_temp_dir() . '/sites-' . time() . '.json';