MediaWiki  1.30.0
categoriesRdfTest.php
Go to the documentation of this file.
1 <?php
2 
4  public function getCategoryIterator() {
5  return [
6  // batch 1
7  [
8  (object)[ 'page_title' => 'Category One', 'page_id' => 1 ],
9  (object)[ 'page_title' => '2 Category Two', 'page_id' => 2 ],
10  ],
11  // batch 2
12  [
13  (object)[ 'page_title' => 'Третья категория', 'page_id' => 3 ],
14  ]
15  ];
16  }
17 
18  public function getCategoryLinksIterator( $dbr, array $ids ) {
19  $res = [];
20  foreach ( $ids as $pageid ) {
21  $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
22  }
23  return $res;
24  }
25 
26  public function testCategoriesDump() {
27  $this->setMwGlobals( [
28  'wgServer' => 'http://acme.test',
29  'wgCanonicalServer' => 'http://acme.test',
30  'wgArticlePath' => '/wiki/$1',
31  'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
32  ] );
33 
34  $dumpScript =
35  $this->getMockBuilder( DumpCategoriesAsRdf::class )
36  ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
37  ->getMock();
38 
39  $dumpScript->expects( $this->once() )
40  ->method( 'getCategoryIterator' )
41  ->willReturn( $this->getCategoryIterator() );
42 
43  $dumpScript->expects( $this->any() )
44  ->method( 'getCategoryLinksIterator' )
45  ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
46 
48  $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
49  $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
50 
51  $dumpScript->loadParamsAndArgs(
52  null,
53  [
54  'log' => $logFileName,
55  'output' => $outFileName,
56  'format' => 'nt',
57  ]
58  );
59 
60  $dumpScript->execute();
61  $actualOut = file_get_contents( $outFileName );
62  $actualOut = preg_replace(
63  '|<http://acme.test/categoriesDump> <http://schema.org/dateModified> "[^"]+?"|',
64  '<http://acme.test/categoriesDump> <http://schema.org/dateModified> "{DATE}"',
65  $actualOut
66  );
67 
68  $outFile = __DIR__ . '/../data/categoriesrdf/categoriesRdf-out.nt';
69  $this->assertFileContains( $outFile, $actualOut );
70  }
71 
72 }
object
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
MediaWikiTestCase\assertFileContains
assertFileContains( $fileName, $actualData, $createIfMissing=true, $msg='')
Check whether file contains given data.
Definition: MediaWikiTestCase.php:1863
CategoriesRdfTest\testCategoriesDump
testCategoriesDump()
Definition: categoriesRdfTest.php:26
$res
$res
Definition: database.txt:21
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
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
CategoriesRdfTest\getCategoryIterator
getCategoryIterator()
Definition: categoriesRdfTest.php:4
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
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:6
CategoriesRdfTest\getCategoryLinksIterator
getCategoryLinksIterator( $dbr, array $ids)
Definition: categoriesRdfTest.php:18
$dbr
if(! $regexes) $dbr
Definition: cleanup.php:94
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
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
DumpCategoriesAsRdf
Maintenance script to provide RDF representation of the category tree.
Definition: dumpCategoriesAsRdf.php:31
array
the array() calling protocol came about after MediaWiki 1.4rc1.
CategoriesRdfTest
Definition: categoriesRdfTest.php:3