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 protected function setUp() {
34 $this->cacheFile
= $this->getCacheFile();
37 protected function tearDown() {
38 unlink( $this->cacheFile
);
41 public function testGetSites() {
42 $sites = $this->getSites();
43 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites );
44 $cacheBuilder->build();
46 $cache = new SiteListFileCache( $this->cacheFile
);
47 $this->assertEquals( $sites, $cache->getSites() );
50 public function testGetSite() {
51 $sites = $this->getSites();
52 $cacheBuilder = $this->newSiteListFileCacheBuilder( $sites );
53 $cacheBuilder->build();
55 $cache = new SiteListFileCache( $this->cacheFile
);
57 $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
60 private function newSiteListFileCacheBuilder( SiteList
$sites ) {
61 return new SiteListFileCacheBuilder(
62 $this->getSiteSQLStore( $sites ),
67 private function getSiteSQLStore( SiteList
$sites ) {
68 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
69 ->disableOriginalConstructor()
72 $siteSQLStore->expects( $this->any() )
73 ->method( 'getSites' )
74 ->will( $this->returnValue( $sites ) );
79 private function getSites() {
83 $site->setGlobalId( 'foobar' );
86 $site = new MediaWikiSite();
87 $site->setGlobalId( 'enwiktionary' );
88 $site->setGroup( 'wiktionary' );
89 $site->setLanguageCode( 'en' );
90 $site->addNavigationId( 'enwiktionary' );
91 $site->setPath( MediaWikiSite
::PATH_PAGE
, "https://en.wiktionary.org/wiki/$1" );
92 $site->setPath( MediaWikiSite
::PATH_FILE
, "https://en.wiktionary.org/w/$1" );
95 return new SiteList( $sites );
98 private function getCacheFile() {
99 return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );