3 class CategoriesRdfTest
extends MediaWikiLangTestCase
{
4 public function getCategoryIterator() {
8 (object)[ 'page_title' => 'Category One', 'page_id' => 1 ],
9 (object)[ 'page_title' => '2 Category Two', 'page_id' => 2 ],
13 (object)[ 'page_title' => 'Третья категория', 'page_id' => 3 ],
18 public function getCategoryLinksIterator( $dbr, array $ids ) {
20 foreach ( $ids as $pageid ) {
21 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
26 public function testCategoriesDump() {
27 $this->setMwGlobals( [
28 'wgServer' => 'http://acme.test',
29 'wgCanonicalServer' => 'http://acme.test',
30 'wgArticlePath' => '/wiki/$1',
31 'wgRightsUrl' => '//creativecommons.org/licenses/by-sa/3.0/',
35 $this->getMockBuilder( DumpCategoriesAsRdf
::class )
36 ->setMethods( [ 'getCategoryIterator', 'getCategoryLinksIterator' ] )
39 $dumpScript->expects( $this->once() )
40 ->method( 'getCategoryIterator' )
41 ->willReturn( $this->getCategoryIterator() );
43 $dumpScript->expects( $this->any() )
44 ->method( 'getCategoryLinksIterator' )
45 ->willReturnCallback( [ $this, 'getCategoryLinksIterator' ] );
47 /** @var DumpCategoriesAsRdf $dumpScript */
48 $logFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
49 $outFileName = tempnam( sys_get_temp_dir(), "Categories-DumpRdfTest" );
51 $dumpScript->loadParamsAndArgs(
54 'log' => $logFileName,
55 'output' => $outFileName,
60 $dumpScript->execute();
61 $actualOut = file_get_contents( $outFileName );
62 $actualOut = preg_replace(
63 '|<http://acme.test/categoriesDump> <http://schema.org/dateModified> "[^"]+?"|',
64 '<http://acme.test/categoriesDump> <http://schema.org/dateModified> "{DATE}"',
68 $outFile = __DIR__
. '/../data/categoriesrdf/categoriesRdf-out.nt';
69 $this->assertFileContains( $outFile, $actualOut );