MediaWiki REL1_31
categoriesRdfTest.php
Go to the documentation of this file.
1<?php
2
4
7
13 public function getCategoryIterator() {
14 return [
15 // batch 1
16 [
17 (object)[
18 'page_title' => 'Category One',
19 'page_id' => 1,
20 'pp_propname' => null,
21 'cat_pages' => '20',
22 'cat_subcats' => '10',
23 'cat_files' => '3'
24 ],
25 (object)[
26 'page_title' => '2 Category Two',
27 'page_id' => 2,
28 'pp_propname' => 'hiddencat',
29 'cat_pages' => 20,
30 'cat_subcats' => 0,
31 'cat_files' => 3
32 ],
33 ],
34 // batch 2
35 [
36 (object)[
37 'page_title' => 'Третья категория',
38 'page_id' => 3,
39 'pp_propname' => null,
40 'cat_pages' => '0',
41 'cat_subcats' => '0',
42 'cat_files' => '0'
43 ],
44 ]
45 ];
46 }
47
48 public function getCategoryLinksIterator( $dbr, array $ids ) {
49 $res = [];
50 foreach ( $ids as $pageid ) {
51 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
52 }
53 return $res;
54 }
55
56 public function testCategoriesDump() {
57 $this->setMwGlobals( [
58 'wgServer' => 'http://acme.test',
59 'wgCanonicalServer' => 'http://acme.test',
60 'wgArticlePath' => '/wiki/$1',
61 'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
62 ] );
63
64 $dumpScript =
65 $this->getMockBuilder( DumpCategoriesAsRdf::class )
66 ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
67 ->getMock();
68
69 $dumpScript->expects( $this->once() )
70 ->method( 'getCategoryIterator' )
71 ->willReturn( $this->getCategoryIterator() );
72
73 $dumpScript->expects( $this->any() )
74 ->method( 'getCategoryLinksIterator' )
75 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
76
78 $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
79 $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
80
81 $dumpScript->loadParamsAndArgs(
82 null,
83 [
84 'log' => $logFileName,
85 'output' => $outFileName,
86 'format' => 'nt',
87 ]
88 );
89
90 $dumpScript->execute();
91 $actualOut = file_get_contents( $outFileName );
92 $actualOut = preg_replace(
93 '|<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "[^"]+?"|',
94 '<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "{DATE}"',
95 $actualOut
96 );
97
98 $outFile = __DIR__ . '/../data/categoriesrdf/categoriesRdf-out.nt';
99 $this->assertFileContains( $outFile, $actualOut );
100 }
101
102}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
Maintenance script to provide RDF representation of the category tree.
Base class that store and restore the Language objects.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
assertFileContains( $fileName, $actualData, $createIfMissing=true, $msg='')
Check whether file contains given data.
$res
Definition database.txt:21
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:64