3 namespace MediaWiki\Tests\Maintenance
;
5 use DumpCategoriesAsRdf
;
6 use MediaWikiLangTestCase
;
9 * @covers CategoriesRdf
10 * @covers DumpCategoriesAsRdf
12 class CategoriesRdfTest
extends MediaWikiLangTestCase
{
13 public function getCategoryIterator() {
17 (object)[ 'page_title' => 'Category One', 'page_id' => 1 ],
18 (object)[ 'page_title' => '2 Category Two', 'page_id' => 2 ],
22 (object)[ 'page_title' => 'Третья категория', 'page_id' => 3 ],
27 public function getCategoryLinksIterator( $dbr, array $ids ) {
29 foreach ( $ids as $pageid ) {
30 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
35 public function testCategoriesDump() {
36 $this->setMwGlobals( [
37 'wgServer' => 'http://acme.test',
38 'wgCanonicalServer' => 'http://acme.test',
39 'wgArticlePath' => '/wiki/$1',
40 'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
44 $this->getMockBuilder( DumpCategoriesAsRdf
::class )
45 ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
48 $dumpScript->expects( $this->once() )
49 ->method( 'getCategoryIterator' )
50 ->willReturn( $this->getCategoryIterator() );
52 $dumpScript->expects( $this->any() )
53 ->method( 'getCategoryLinksIterator' )
54 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
56 /** @var DumpCategoriesAsRdf $dumpScript */
57 $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
58 $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
60 $dumpScript->loadParamsAndArgs(
63 'log' => $logFileName,
64 'output' => $outFileName,
69 $dumpScript->execute();
70 $actualOut = file_get_contents( $outFileName );
71 $actualOut = preg_replace(
72 '|<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "[^"]+?"|',
73 '<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "{DATE}"',
77 $outFile = __DIR__
. '/../data/categoriesrdf/categoriesRdf-out.nt';
78 $this->assertFileContains( $outFile, $actualOut );