4 * @covers CategoriesRdf
5 * @covers DumpCategoriesAsRdf
7 class CategoriesRdfTest
extends MediaWikiLangTestCase
{
8 public function getCategoryIterator() {
12 (object)[ 'page_title' => 'Category One', 'page_id' => 1 ],
13 (object)[ 'page_title' => '2 Category Two', 'page_id' => 2 ],
17 (object)[ 'page_title' => 'Третья категория', 'page_id' => 3 ],
22 public function getCategoryLinksIterator( $dbr, array $ids ) {
24 foreach ( $ids as $pageid ) {
25 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
30 public function testCategoriesDump() {
31 $this->setMwGlobals( [
32 'wgServer' => 'http://acme.test',
33 'wgCanonicalServer' => 'http://acme.test',
34 'wgArticlePath' => '/wiki/$1',
35 'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
39 $this->getMockBuilder( DumpCategoriesAsRdf
::class )
40 ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
43 $dumpScript->expects( $this->once() )
44 ->method( 'getCategoryIterator' )
45 ->willReturn( $this->getCategoryIterator() );
47 $dumpScript->expects( $this->any() )
48 ->method( 'getCategoryLinksIterator' )
49 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
51 /** @var DumpCategoriesAsRdf $dumpScript */
52 $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
53 $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
55 $dumpScript->loadParamsAndArgs(
58 'log' => $logFileName,
59 'output' => $outFileName,
64 $dumpScript->execute();
65 $actualOut = file_get_contents( $outFileName );
66 $actualOut = preg_replace(
67 '|<http://acme.test/categoriesDump> <http://schema.org/dateModified> "[^"]+?"|',
68 '<http://acme.test/categoriesDump> <http://schema.org/dateModified> "{DATE}"',
72 $outFile = __DIR__
. '/../data/categoriesrdf/categoriesRdf-out.nt';
73 $this->assertFileContains( $outFile, $actualOut );