Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / CategoriesRdfTest.php
blobba5f78f2460c18abc3525bc20f3ae9573bfb1182
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use DumpCategoriesAsRdf;
6 use MediaWiki\MainConfigNames;
7 use MediaWikiLangTestCase;
8 use Wikimedia\Rdbms\IMaintainableDatabase;
10 /**
11 * @covers \MediaWiki\Category\CategoriesRdf
12 * @covers \DumpCategoriesAsRdf
14 class CategoriesRdfTest extends MediaWikiLangTestCase {
15 public function getCategoryIterator() {
16 return [
17 // batch 1
19 (object)[
20 'page_title' => 'Category One',
21 'page_id' => 1,
22 'pp_propname' => null,
23 'cat_pages' => '20',
24 'cat_subcats' => '10',
25 'cat_files' => '3'
27 (object)[
28 'page_title' => '2 Category Two',
29 'page_id' => 2,
30 'pp_propname' => 'hiddencat',
31 'cat_pages' => 20,
32 'cat_subcats' => 0,
33 'cat_files' => 3
36 // batch 2
38 (object)[
39 'page_title' => 'Третья категория',
40 'page_id' => 3,
41 'pp_propname' => null,
42 'cat_pages' => '0',
43 'cat_subcats' => '0',
44 'cat_files' => '0'
50 public function getCategoryLinksIterator( $dbr, array $ids ) {
51 $res = [];
52 foreach ( $ids as $pageid ) {
53 $res[] = (object)[ 'cl_from' => $pageid, 'cl_to' => "Parent of $pageid" ];
55 return $res;
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/',
63 ] );
65 $dumpScript =
66 $this->getMockBuilder( DumpCategoriesAsRdf::class )
67 ->onlyMethods( [ 'getDB', 'getCategoryIterator', 'getCategoryLinksIterator' ] )
68 ->getMock();
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(
84 null,
86 'log' => $logFileName,
87 'output' => $outFileName,
88 'format' => 'nt',
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}"',
97 $actualOut
100 $outFile = __DIR__ . '/../data/categoriesrdf/categoriesRdf-out.nt';
101 $this->assertFileContains( $outFile, $actualOut );