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 SiteListFileCacheBuilder
28 * @licence GNU GPL v2+
29 * @author Katie Filbert < aude.wiki@gmail.com >
31 class SiteListFileCacheBuilderTest
extends PHPUnit_Framework_TestCase
{
33 public function testBuild() {
34 $cacheFile = $this->getCacheFile();
36 $cacheBuilder = $this->newSiteListFileCacheBuilder( $this->getSites(), $cacheFile );
37 $cacheBuilder->build();
39 $contents = file_get_contents( $cacheFile );
40 $this->assertEquals( json_encode( $this->getExpectedData() ), $contents );
43 private function getExpectedData() {
47 'globalid' => 'foobar',
52 'localids' => array(),
57 'identifiers' => array()
59 'enwiktionary' => array(
60 'globalid' => 'enwiktionary',
61 'type' => 'mediawiki',
62 'group' => 'wiktionary',
66 'equivalent' => array( 'enwiktionary' )
71 'page_path' => 'https://en.wiktionary.org/wiki/$1',
72 'file_path' => 'https://en.wiktionary.org/w/$1'
77 'identifiers' => array(
79 'type' => 'equivalent',
80 'key' => 'enwiktionary'
88 private function newSiteListFileCacheBuilder( SiteList
$sites, $cacheFile ) {
89 return new SiteListFileCacheBuilder(
90 $this->getSiteSQLStore( $sites ),
95 private function getSiteSQLStore( SiteList
$sites ) {
96 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
97 ->disableOriginalConstructor()
100 $siteSQLStore->expects( $this->any() )
101 ->method( 'getSites' )
102 ->will( $this->returnValue( $sites ) );
104 return $siteSQLStore;
107 private function getSites() {
111 $site->setGlobalId( 'foobar' );
114 $site = new MediaWikiSite();
115 $site->setGlobalId( 'enwiktionary' );
116 $site->setGroup( 'wiktionary' );
117 $site->setLanguageCode( 'en' );
118 $site->addNavigationId( 'enwiktionary' );
119 $site->setPath( MediaWikiSite
::PATH_PAGE
, "https://en.wiktionary.org/wiki/$1" );
120 $site->setPath( MediaWikiSite
::PATH_FILE
, "https://en.wiktionary.org/w/$1" );
123 return new SiteList( $sites );
126 private function getCacheFile() {
127 return sys_get_temp_dir() . '/sites-' . time() . '.json';