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 protected function setUp() {
34 $this->cacheFile
= $this->getCacheFile();
37 protected function tearDown() {
38 unlink( $this->cacheFile
);
41 public function testBuild() {
42 $cacheBuilder = $this->newSiteListFileCacheBuilder( $this->getSites() );
43 $cacheBuilder->build();
45 $contents = file_get_contents( $this->cacheFile
);
46 $this->assertEquals( json_encode( $this->getExpectedData() ), $contents );
49 private function getExpectedData() {
53 'globalid' => 'foobar',
58 'localids' => array(),
63 'identifiers' => array()
65 'enwiktionary' => array(
66 'globalid' => 'enwiktionary',
67 'type' => 'mediawiki',
68 'group' => 'wiktionary',
72 'equivalent' => array( 'enwiktionary' )
77 'page_path' => 'https://en.wiktionary.org/wiki/$1',
78 'file_path' => 'https://en.wiktionary.org/w/$1'
83 'identifiers' => array(
85 'type' => 'equivalent',
86 'key' => 'enwiktionary'
94 private function newSiteListFileCacheBuilder( SiteList
$sites ) {
95 return new SiteListFileCacheBuilder(
96 $this->getSiteSQLStore( $sites ),
101 private function getSiteSQLStore( SiteList
$sites ) {
102 $siteSQLStore = $this->getMockBuilder( 'SiteSQLStore' )
103 ->disableOriginalConstructor()
106 $siteSQLStore->expects( $this->any() )
107 ->method( 'getSites' )
108 ->will( $this->returnValue( $sites ) );
110 return $siteSQLStore;
113 private function getSites() {
117 $site->setGlobalId( 'foobar' );
120 $site = new MediaWikiSite();
121 $site->setGlobalId( 'enwiktionary' );
122 $site->setGroup( 'wiktionary' );
123 $site->setLanguageCode( 'en' );
124 $site->addNavigationId( 'enwiktionary' );
125 $site->setPath( MediaWikiSite
::PATH_PAGE
, "https://en.wiktionary.org/wiki/$1" );
126 $site->setPath( MediaWikiSite
::PATH_FILE
, "https://en.wiktionary.org/w/$1" );
129 return new SiteList( $sites );
132 private function getCacheFile() {
133 return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );