4 * @covers CategoriesRdf
5 * @covers DumpCategoriesAsRdf
7 class CategoriesRdfTest
extends MediaWikiLangTestCase
{
8 public function getCategoryIterator() {
13 'page_title' => 'Category One',
15 'pp_propname' => null,
17 'cat_subcats' => '10',
21 'page_title' => '2 Category Two',
23 'pp_propname' => 'hiddencat',
32 'page_title' => 'Третья категория',
34 'pp_propname' => null,
43 public function getCategoryLinksIterator( $dbr, array $ids ) {
45 foreach ( $ids as $pageid ) {
46 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
51 public function testCategoriesDump() {
52 $this->setMwGlobals( [
53 'wgServer' => 'http://acme.test',
54 'wgCanonicalServer' => 'http://acme.test',
55 'wgArticlePath' => '/wiki/$1',
56 'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
60 $this->getMockBuilder( DumpCategoriesAsRdf
::class )
61 ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
64 $dumpScript->expects( $this->once() )
65 ->method( 'getCategoryIterator' )
66 ->willReturn( $this->getCategoryIterator() );
68 $dumpScript->expects( $this->any() )
69 ->method( 'getCategoryLinksIterator' )
70 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
72 /** @var DumpCategoriesAsRdf $dumpScript */
73 $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
74 $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
76 $dumpScript->loadParamsAndArgs(
79 'log' => $logFileName,
80 'output' => $outFileName,
85 $dumpScript->execute();
86 $actualOut = file_get_contents( $outFileName );
87 $actualOut = preg_replace(
88 '|<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "[^"]+?"|',
89 '<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "{DATE}"',
93 $outFile = __DIR__
. '/../data/categoriesrdf/categoriesRdf-out.nt';
94 $this->assertFileContains( $outFile, $actualOut );