MediaWiki  1.33.0
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 }
MediaWiki\Tests\Maintenance\CategoriesRdfTest
CategoriesRdf DumpCategoriesAsRdf.
Definition: categoriesRdfTest.php:12
$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\assertFileContains
assertFileContains( $fileName, $actualData, $createIfMissing=false, $msg='')
Check whether file contains given data.
Definition: MediaWikiTestCase.php:2338
$dbr
$dbr
Definition: testCompression.php:50
MediaWiki\Tests\Maintenance
Definition: backup_LogTest.php:3
MediaWiki\Tests\Maintenance\CategoriesRdfTest\getCategoryIterator
getCategoryIterator()
Definition: categoriesRdfTest.php:13
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:709
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
array
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))
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:8
MediaWiki\Tests\Maintenance\CategoriesRdfTest\testCategoriesDump
testCategoriesDump()
Definition: categoriesRdfTest.php:56
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
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 $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
MediaWiki\Tests\Maintenance\CategoriesRdfTest\getCategoryLinksIterator
getCategoryLinksIterator( $dbr, array $ids)
Definition: categoriesRdfTest.php:48
DumpCategoriesAsRdf
Maintenance script to provide RDF representation of the category tree.
Definition: dumpCategoriesAsRdf.php:31