MediaWiki REL1_32
categoryChangesRdfTest.php
Go to the documentation of this file.
1<?php
2
8
9 public function setUp() {
10 parent::setUp();
11 $this->setMwGlobals( [
12 'wgServer' => 'http://acme.test',
13 'wgCanonicalServer' => 'http://acme.test',
14 'wgArticlePath' => '/wiki/$1',
15 ] );
16 }
17
18 public function provideCategoryData() {
19 return [
20 'delete category' => [
21 __DIR__ . "/../data/categoriesrdf/delete.sparql",
22 'getDeletedCatsIterator',
23 'handleDeletes',
24 [
25 (object)[ 'rc_title' => 'Test', 'rc_cur_id' => 1, '_processed' => 1 ],
26 (object)[ 'rc_title' => 'Test 2', 'rc_cur_id' => 2, '_processed' => 2 ],
27 ],
28 ],
29 'move category' => [
30 __DIR__ . "/../data/categoriesrdf/move.sparql",
31 'getMovedCatsIterator',
32 'handleMoves',
33 [
34 (object)[
35 'rc_title' => 'Test',
36 'rc_cur_id' => 4,
37 'page_title' => 'MovedTo',
38 'page_namespace' => NS_CATEGORY,
39 '_processed' => 4,
40 'pp_propname' => null,
41 'cat_pages' => 10,
42 'cat_subcats' => 2,
43 'cat_files' => 1,
44 ],
45 (object)[
46 'rc_title' => 'MovedTo',
47 'rc_cur_id' => 4,
48 'page_title' => 'MovedAgain',
49 'page_namespace' => NS_CATEGORY,
50 'pp_propname' => 'hiddencat',
51 'cat_pages' => 10,
52 'cat_subcats' => 2,
53 'cat_files' => 1,
54 ],
55 (object)[
56 'rc_title' => 'Test 2',
57 'rc_cur_id' => 5,
58 'page_title' => 'AlsoMoved',
59 'page_namespace' => NS_CATEGORY,
60 '_processed' => 5,
61 'pp_propname' => null,
62 'cat_pages' => 10,
63 'cat_subcats' => 2,
64 'cat_files' => 1,
65 ],
66 (object)[
67 'rc_title' => 'Test 3',
68 'rc_cur_id' => 6,
69 'page_title' => 'MovedOut',
70 'page_namespace' => NS_MAIN,
71 'pp_propname' => null,
72 'cat_pages' => 10,
73 'cat_subcats' => 2,
74 'cat_files' => 1,
75 ],
76 (object)[
77 'rc_title' => 'Test 4',
78 'rc_cur_id' => 7,
79 'page_title' => 'Already Done',
80 'page_namespace' => NS_CATEGORY,
81 'pp_propname' => null,
82 'cat_pages' => 10,
83 'cat_subcats' => 2,
84 'cat_files' => 1,
85 ],
86 ],
87 [ 7 => true ],
88 ],
89 'restore deleted category' => [
90 __DIR__ . "/../data/categoriesrdf/restore.sparql",
91 'getRestoredCatsIterator',
92 'handleRestores',
93 [
94 (object)[
95 'rc_title' => 'Restored cat',
96 'rc_cur_id' => 10,
97 '_processed' => 10,
98 'pp_propname' => null,
99 'cat_pages' => 10,
100 'cat_subcats' => 2,
101 'cat_files' => 1,
102 ],
103 (object)[
104 'rc_title' => 'Restored again',
105 'rc_cur_id' => 10,
106 'pp_propname' => null,
107 'cat_pages' => 10,
108 'cat_subcats' => 2,
109 'cat_files' => 1,
110 ],
111 (object)[
112 'rc_title' => 'Already seen',
113 'rc_cur_id' => 11,
114 'pp_propname' => null,
115 'cat_pages' => 10,
116 'cat_subcats' => 2,
117 'cat_files' => 1,
118 ],
119 ],
120 [ 11 => true ],
121 ],
122 'new page' => [
123 __DIR__ . "/../data/categoriesrdf/new.sparql",
124 'getNewCatsIterator',
125 'handleAdds',
126 [
127 (object)[
128 'rc_title' => 'New category',
129 'rc_cur_id' => 20,
130 '_processed' => 20,
131 'pp_propname' => null,
132 'cat_pages' => 10,
133 'cat_subcats' => 2,
134 'cat_files' => 1,
135 ],
136 (object)[
137 'rc_title' => 'Новая категория 😃',
138 'rc_cur_id' => 21,
139 '_processed' => 21,
140 'pp_propname' => 'hiddencat',
141 'cat_pages' => 10,
142 'cat_subcats' => 2,
143 'cat_files' => 1,
144 ],
145 (object)[
146 'rc_title' => 'Processed already',
147 'rc_cur_id' => 22,
148 ],
149 ],
150 [ 22 => true ],
151 ],
152 'edit category' => [
153 __DIR__ . "/../data/categoriesrdf/edit.sparql",
154 'getChangedCatsIterator',
155 'handleEdits',
156 [
157 (object)[
158 'rc_title' => 'Changed category',
159 'rc_cur_id' => 30,
160 '_processed' => 30,
161 'pp_propname' => null,
162 'cat_pages' => 10,
163 'cat_subcats' => 2,
164 'cat_files' => 1,
165 ],
166 (object)[
167 'rc_title' => 'Changed again',
168 'rc_cur_id' => 30,
169 'pp_propname' => null,
170 'cat_pages' => 12,
171 'cat_subcats' => 2,
172 'cat_files' => 1,
173 ],
174 (object)[
175 'rc_title' => 'Processed already',
176 'rc_cur_id' => 31,
177 'pp_propname' => null,
178 'cat_pages' => 10,
179 'cat_subcats' => 2,
180 'cat_files' => 1,
181 ],
182 ],
183 [ 31 => true ],
184 ],
185 // TODO: not sure how to test categorization changes, it uses the database select...
186 ];
187 }
188
195 public function getCategoryLinksIterator( $dbr, array $ids ) {
196 $res = [];
197 foreach ( $ids as $pageid ) {
198 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
199 }
200 return $res;
201 }
202
211 public function testSparqlUpdate( $testFileName, $iterator, $handler, $result,
212 array $preProcessed = [] ) {
213 $dumpScript =
214 $this->getMockBuilder( CategoryChangesAsRdf::class )
215 ->setMethods( [ $iterator, 'getCategoryLinksIterator' ] )
216 ->getMock();
217
218 $dumpScript->expects( $this->any() )
219 ->method( 'getCategoryLinksIterator' )
220 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
221
222 $dumpScript->expects( $this->once() )
223 ->method( $iterator )
224 ->willReturn( [ $result ] );
225
226 $ref = new ReflectionObject( $dumpScript );
227 $processedProperty = $ref->getProperty( 'processed' );
228 $processedProperty->setAccessible( true );
229 $processedProperty->setValue( $dumpScript, $preProcessed );
230
231 $output = fopen( "php://memory", "w+b" );
234 $dumpScript->initialize();
235 $dumpScript->getRdf();
236 $dumpScript->$handler( $dbr, $output );
237
238 rewind( $output );
239 $sparql = stream_get_contents( $output );
240 $this->assertFileContains( $testFileName, $sparql );
241
242 $processed = $processedProperty->getValue( $dumpScript );
243 $expectedProcessed = $preProcessed;
244 foreach ( $result as $row ) {
245 if ( isset( $row->_processed ) ) {
246 $this->assertArrayHasKey( $row->_processed, $processed,
247 "ID {$row->_processed} was not processed!" );
248 $expectedProcessed[] = $row->_processed;
249 }
250 }
251 $this->assertArrayEquals( $expectedProcessed, array_keys( $processed ),
252 'Processed array has wrong items' );
253 }
254
255 public function testUpdateTs() {
256 $dumpScript = new CategoryChangesAsRdf();
257 $dumpScript->initialize();
258 $update = $dumpScript->updateTS( 1503620949 );
259 $outFile = __DIR__ . '/../data/categoriesrdf/updatets.txt';
260 $this->assertFileContains( $outFile, $update );
261 }
262
263}
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition COPYING.txt:326
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Maintenance script to provide RDF representation of the recent changes in category tree.
Tests for CategoryChangesAsRdf recent changes exporter.
getCategoryLinksIterator( $dbr, array $ids)
Mock category links iterator.
testSparqlUpdate( $testFileName, $iterator, $handler, $result, array $preProcessed=[])
provideCategoryData
Base class that store and restore the Language objects.
assertFileContains( $fileName, $actualData, $createIfMissing=false, $msg='')
Check whether file contains given data.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
$res
Definition database.txt:21
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
Definition hooks.txt:2055
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition hooks.txt:933
static configuration should be added through ResourceLoaderGetConfigVars instead can be used to get the real title e g db for database replication lag or jobqueue for job queue size converted to pseudo seconds It is possible to add more fields and they will be returned to the user in the API response after the basic globals have been set but before ordinary actions take place $output
Definition hooks.txt:2317
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 $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:62
const NS_MAIN
Definition Defines.php:64
const NS_CATEGORY
Definition Defines.php:78
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
const DB_REPLICA
Definition defines.php:25