MediaWiki REL1_30
SiteExporterTest.php
Go to the documentation of this file.
1<?php
2
32class SiteExporterTest extends PHPUnit_Framework_TestCase {
33
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}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
newSiteStore(SiteList $sites)
testRoundTrip(SiteList $sites)
provideRoundTrip()
setSite(Site $site)
Sets a site in the list.
Definition SiteList.php:263
const TYPE_MEDIAWIKI
Definition Site.php:31
static newForType( $siteType)
Definition Site.php:644
const PATH_LINK
Definition Site.php:40
const TYPE_UNKNOWN
Definition Site.php:30
const ID_EQUIVALENT
Definition Site.php:36
const ID_INTERWIKI
Definition Site.php:35