MediaWiki  1.30.0
SiteExporterTest.php
Go to the documentation of this file.
1 <?php
2 
32 class SiteExporterTest extends PHPUnit_Framework_TestCase {
33 
34  public function testConstructor_InvalidArgument() {
35  $this->setExpectedException( 'InvalidArgumentException' );
36 
37  new SiteExporter( 'Foo' );
38  }
39 
40  public function testExportSites() {
42  $foo->setGlobalId( 'Foo' );
43 
45  $acme->setGlobalId( 'acme.com' );
46  $acme->setGroup( 'Test' );
47  $acme->addLocalId( Site::ID_INTERWIKI, 'acme' );
48  $acme->setPath( Site::PATH_LINK, 'http://acme.com/' );
49 
50  $tmp = tmpfile();
51  $exporter = new SiteExporter( $tmp );
52 
53  $exporter->exportSites( [ $foo, $acme ] );
54 
55  fseek( $tmp, 0 );
56  $xml = fread( $tmp, 16 * 1024 );
57 
58  $this->assertContains( '<sites ', $xml );
59  $this->assertContains( '<site>', $xml );
60  $this->assertContains( '<globalid>Foo</globalid>', $xml );
61  $this->assertContains( '</site>', $xml );
62  $this->assertContains( '<globalid>acme.com</globalid>', $xml );
63  $this->assertContains( '<group>Test</group>', $xml );
64  $this->assertContains( '<localid type="interwiki">acme</localid>', $xml );
65  $this->assertContains( '<path type="link">http://acme.com/</path>', $xml );
66  $this->assertContains( '</sites>', $xml );
67 
68  // NOTE: HHVM (at least on wmf Jenkins) doesn't like file URLs.
69  $xsdFile = __DIR__ . '/../../../../docs/sitelist-1.0.xsd';
70  $xsdData = file_get_contents( $xsdFile );
71 
72  $document = new DOMDocument();
73  $document->loadXML( $xml, LIBXML_NONET );
74  $document->schemaValidateSource( $xsdData );
75  }
76 
77  private function newSiteStore( SiteList $sites ) {
78  $store = $this->getMockBuilder( 'SiteStore' )->getMock();
79 
80  $store->expects( $this->once() )
81  ->method( 'saveSites' )
82  ->will( $this->returnCallback( function ( $moreSites ) use ( $sites ) {
83  foreach ( $moreSites as $site ) {
84  $sites->setSite( $site );
85  }
86  } ) );
87 
88  $store->expects( $this->any() )
89  ->method( 'getSites' )
90  ->will( $this->returnValue( new SiteList() ) );
91 
92  return $store;
93  }
94 
95  public function provideRoundTrip() {
97  $foo->setGlobalId( 'Foo' );
98 
100  $acme->setGlobalId( 'acme.com' );
101  $acme->setGroup( 'Test' );
102  $acme->addLocalId( Site::ID_INTERWIKI, 'acme' );
103  $acme->setPath( Site::PATH_LINK, 'http://acme.com/' );
104 
106  $dewiki->setGlobalId( 'dewiki' );
107  $dewiki->setGroup( 'wikipedia' );
108  $dewiki->setForward( true );
109  $dewiki->addLocalId( Site::ID_INTERWIKI, 'wikipedia' );
110  $dewiki->addLocalId( Site::ID_EQUIVALENT, 'de' );
111  $dewiki->setPath( Site::PATH_LINK, 'http://de.wikipedia.org/w/' );
112  $dewiki->setPath( MediaWikiSite::PATH_PAGE, 'http://de.wikipedia.org/wiki/' );
113  $dewiki->setSource( 'meta.wikimedia.org' );
114 
115  return [
116  'empty' => [
117  new SiteList()
118  ],
119 
120  'some' => [
121  new SiteList( [ $foo, $acme, $dewiki ] ),
122  ],
123  ];
124  }
125 
129  public function testRoundTrip( SiteList $sites ) {
130  $tmp = tmpfile();
131  $exporter = new SiteExporter( $tmp );
132 
133  $exporter->exportSites( $sites );
134 
135  fseek( $tmp, 0 );
136  $xml = fread( $tmp, 16 * 1024 );
137 
138  $actualSites = new SiteList();
139  $store = $this->newSiteStore( $actualSites );
140 
141  $importer = new SiteImporter( $store );
142  $importer->importFromXML( $xml );
143 
144  $this->assertEquals( $sites, $actualSites );
145  }
146 
147 }
Site\ID_EQUIVALENT
const ID_EQUIVALENT
Definition: Site.php:36
SiteExporterTest\testRoundTrip
testRoundTrip(SiteList $sites)
provideRoundTrip()
Definition: SiteExporterTest.php:129
SiteExporterTest\testExportSites
testExportSites()
Definition: SiteExporterTest.php:40
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
SiteImporter
Definition: SiteImporter.php:30
Site\ID_INTERWIKI
const ID_INTERWIKI
Definition: Site.php:35
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
Site\newForType
static newForType( $siteType)
Definition: Site.php:644
SiteExporterTest\newSiteStore
newSiteStore(SiteList $sites)
Definition: SiteExporterTest.php:77
SiteExporterTest\testConstructor_InvalidArgument
testConstructor_InvalidArgument()
Definition: SiteExporterTest.php:34
SiteExporterTest\provideRoundTrip
provideRoundTrip()
Definition: SiteExporterTest.php:95
Site\TYPE_UNKNOWN
const TYPE_UNKNOWN
Definition: Site.php:30
SiteList
Definition: SiteList.php:29
SiteExporterTest
Definition: SiteExporterTest.php:32
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
SiteList\setSite
setSite(Site $site)
Sets a site in the list.
Definition: SiteList.php:263
MediaWikiSite\PATH_PAGE
const PATH_PAGE
Definition: MediaWikiSite.php:40
SiteExporter
Definition: SiteExporter.php:30
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Site\PATH_LINK
const PATH_LINK
Definition: Site.php:40
Site\TYPE_MEDIAWIKI
const TYPE_MEDIAWIKI
Definition: Site.php:31