3 namespace MediaWiki\Tests\Maintenance
;
5 use DumpCategoriesAsRdf
;
6 use MediaWiki\MainConfigNames
;
7 use MediaWikiLangTestCase
;
8 use Wikimedia\Rdbms\IMaintainableDatabase
;
11 * @covers \MediaWiki\Category\CategoriesRdf
12 * @covers \DumpCategoriesAsRdf
14 class CategoriesRdfTest
extends MediaWikiLangTestCase
{
15 public function getCategoryIterator() {
20 'page_title' => 'Category One',
22 'pp_propname' => null,
24 'cat_subcats' => '10',
28 'page_title' => '2 Category Two',
30 'pp_propname' => 'hiddencat',
39 'page_title' => 'Третья категория',
41 'pp_propname' => null,
50 public function getCategoryLinksIterator( $dbr, array $ids ) {
52 foreach ( $ids as $pageid ) {
53 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
58 public function testCategoriesDump() {
59 $this->overrideConfigValues( [
60 MainConfigNames
::Server
=> 'http://acme.test',
61 MainConfigNames
::CanonicalServer
=> 'http://acme.test',
62 MainConfigNames
::RightsUrl
=> 'https://creativecommons.org/licenses/by-sa/3.0/',
66 $this->getMockBuilder( DumpCategoriesAsRdf
::class )
67 ->onlyMethods( [ 'getDB', 'getCategoryIterator', 'getCategoryLinksIterator' ] )
70 $dumpScript->method( 'getDB' )
71 ->willReturn( $this->createNoOpMock( IMaintainableDatabase
::class ) );
72 $dumpScript->expects( $this->once() )
73 ->method( 'getCategoryIterator' )
74 ->willReturn( $this->getCategoryIterator() );
76 $dumpScript->method( 'getCategoryLinksIterator' )
77 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
79 /** @var DumpCategoriesAsRdf $dumpScript */
80 $logFileName = $this->getNewTempFile();
81 $outFileName = $this->getNewTempFile();
83 $dumpScript->loadParamsAndArgs(
86 'log' => $logFileName,
87 'output' => $outFileName,
92 $dumpScript->execute();
93 $actualOut = file_get_contents( $outFileName );
94 $actualOut = preg_replace(
95 '|<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "[^"]+?"|',
96 '<http://acme.test/wiki/Special:CategoryDump> <http://schema.org/dateModified> "{DATE}"',
100 $outFile = __DIR__
. '/../data/categoriesrdf/categoriesRdf-out.nt';
101 $this->assertFileContains( $outFile, $actualOut );