MediaWiki  1.31.0
FileBasedSiteLookupTest.php
Go to the documentation of this file.
1 <?php
2 
30 class FileBasedSiteLookupTest extends PHPUnit\Framework\TestCase {
31 
32  use MediaWikiCoversValidator;
33 
34  protected function setUp() {
35  $this->cacheFile = $this->getCacheFile();
36  }
37 
38  protected function tearDown() {
39  unlink( $this->cacheFile );
40  }
41 
42  public function testGetSites() {
43  $sites = $this->getSites();
44  $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
45  $cacheBuilder->build();
46 
47  $cache = new FileBasedSiteLookup( $this->cacheFile );
48  $this->assertEquals( $sites, $cache->getSites() );
49  }
50 
51  public function testGetSite() {
52  $sites = $this->getSites();
53  $cacheBuilder = $this->newSitesCacheFileBuilder( $sites );
54  $cacheBuilder->build();
55 
56  $cache = new FileBasedSiteLookup( $this->cacheFile );
57 
58  $this->assertEquals( $sites->getSite( 'enwiktionary' ), $cache->getSite( 'enwiktionary' ) );
59  }
60 
61  private function newSitesCacheFileBuilder( SiteList $sites ) {
62  return new SitesCacheFileBuilder(
63  $this->getSiteLookup( $sites ),
64  $this->cacheFile
65  );
66  }
67 
68  private function getSiteLookup( SiteList $sites ) {
69  $siteLookup = $this->getMockBuilder( SiteLookup::class )
70  ->disableOriginalConstructor()
71  ->getMock();
72 
73  $siteLookup->expects( $this->any() )
74  ->method( 'getSites' )
75  ->will( $this->returnValue( $sites ) );
76 
77  return $siteLookup;
78  }
79 
80  private function getSites() {
81  $sites = [];
82 
83  $site = new Site();
84  $site->setGlobalId( 'foobar' );
85  $sites[] = $site;
86 
87  $site = new MediaWikiSite();
88  $site->setGlobalId( 'enwiktionary' );
89  $site->setGroup( 'wiktionary' );
90  $site->setLanguageCode( 'en' );
91  $site->addNavigationId( 'enwiktionary' );
92  $site->setPath( MediaWikiSite::PATH_PAGE, "https://en.wiktionary.org/wiki/$1" );
93  $site->setPath( MediaWikiSite::PATH_FILE, "https://en.wiktionary.org/w/$1" );
94  $sites[] = $site;
95 
96  return new SiteList( $sites );
97  }
98 
99  private function getCacheFile() {
100  return tempnam( sys_get_temp_dir(), 'mw-test-sitelist' );
101  }
102 
103 }
FileBasedSiteLookupTest\getSiteLookup
getSiteLookup(SiteList $sites)
Definition: FileBasedSiteLookupTest.php:68
SitesCacheFileBuilder
Definition: SitesCacheFileBuilder.php:25
FileBasedSiteLookup
Provides a file-based cache of a SiteStore.
Definition: FileBasedSiteLookup.php:33
FileBasedSiteLookupTest
Definition: FileBasedSiteLookupTest.php:30
FileBasedSiteLookupTest\testGetSites
testGetSites()
Definition: FileBasedSiteLookupTest.php:42
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
FileBasedSiteLookupTest\newSitesCacheFileBuilder
newSitesCacheFileBuilder(SiteList $sites)
Definition: FileBasedSiteLookupTest.php:61
SiteList
Definition: SiteList.php:29
MediaWikiSite\PATH_FILE
const PATH_FILE
Definition: MediaWikiSite.php:39
Site
Definition: Site.php:29
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
FileBasedSiteLookupTest\testGetSite
testGetSite()
Definition: FileBasedSiteLookupTest.php:51
FileBasedSiteLookupTest\setUp
setUp()
Definition: FileBasedSiteLookupTest.php:34
MediaWikiSite\PATH_PAGE
const PATH_PAGE
Definition: MediaWikiSite.php:40
FileBasedSiteLookupTest\getSites
getSites()
Definition: FileBasedSiteLookupTest.php:80
$cache
$cache
Definition: mcc.php:33
MediaWikiSite
Class representing a MediaWiki site.
Definition: MediaWikiSite.php:38
FileBasedSiteLookupTest\tearDown
tearDown()
Definition: FileBasedSiteLookupTest.php:38
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
FileBasedSiteLookupTest\getCacheFile
getCacheFile()
Definition: FileBasedSiteLookupTest.php:99