Ejemplo n.º 1
0
 public function testScript()
 {
     $dumpScript = new DumpRdf();
     $mockRepo = new MockRepository();
     $mockEntityPerPage = new MockEntityPerPage();
     $snakList = new SnakList();
     $snakList->addSnak(new PropertySomeValueSnak(new PropertyId('P12')));
     $snakList->addSnak(new PropertyValueSnak(new PropertyId('P12'), new StringValue('stringVal')));
     /** @var Entity[] $testEntities */
     $testEntities = array(new Item(new ItemId('Q1')), new Property(new PropertyId('P1'), null, 'string'), new Property(new PropertyId('P12'), null, 'string', new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P999')), null, null, 'GUID1')))), new Item(new ItemId('Q2'), new Fingerprint(new TermList(array(new Term('en', 'en-label'), new Term('de', 'de-label'))), new TermList(array(new Term('fr', 'en-desc'), new Term('de', 'de-desc'))), new AliasGroupList(array(new AliasGroup('en', array('ali1', 'ali2')), new AliasGroup('dv', array('ali11', 'ali22'))))), new SiteLinkList(array(new SiteLink('enwiki', 'Berlin'), new SiteLink('dewiki', 'England', array(new ItemId('Q1'))))), new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P12')), null, null, 'GUID1'), new Statement(new PropertySomeValueSnak(new PropertyId('P12')), $snakList, new ReferenceList(array(new Reference(array(new PropertyValueSnak(new PropertyId('P12'), new StringValue('refSnakVal')), new PropertyNoValueSnak(new PropertyId('P12')))))), 'GUID2')))));
     foreach ($testEntities as $key => $testEntity) {
         $mockRepo->putEntity($testEntity, $key, '20000101000000');
         $mockEntityPerPage->addEntityPage($testEntity->getId(), $key);
     }
     // Note: We are testing with the actual RDF bindings, so we can check for actual RDF output.
     $rdfBuilder = WikibaseRepo::getDefaultInstance()->getValueSnakRdfBuilderFactory();
     $dumpScript->setServices($mockEntityPerPage, new NullEntityPrefetcher(), MockSiteStore::newFromTestSites(), $this->getMockPropertyDataTypeLookup(), $rdfBuilder, $mockRepo, 'fooUri');
     $logFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $outFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpRdfTest");
     $dumpScript->loadParamsAndArgs(null, array('log' => $logFileName, 'output' => $outFileName, 'format' => 'n-triples'));
     $dumpScript->execute();
     $expectedLog = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-log.txt');
     $expectedOut = file_get_contents(__DIR__ . '/../data/maintenance/dumpRdf-out.txt');
     $actualOut = file_get_contents($outFileName);
     $actualOut = preg_replace('/<http:\\/\\/wikiba.se\\/ontology-beta#Dump> <http:\\/\\/schema.org\\/dateModified> "[^"]+"/', "<http://wikiba.se/ontology-beta#Dump> <http://schema.org/dateModified> \"2015-01-01T00:00:00Z\"", $actualOut);
     $this->assertEquals($this->fixLineEndings($expectedLog), $this->fixLineEndings(file_get_contents($logFileName)));
     $this->assertEquals($this->fixLineEndings($expectedOut), $this->fixLineEndings($actualOut));
 }
 public function testScript()
 {
     $dumpScript = new DumpJson();
     $mockRepo = new MockRepository();
     $mockEntityPerPage = new MockEntityPerPage();
     $snakList = new SnakList();
     $snakList->addSnak(new PropertySomeValueSnak(new PropertyId('P12')));
     $snakList->addSnak(new PropertyValueSnak(new PropertyId('P12'), new StringValue('stringVal')));
     /** @var Entity[] $testEntities */
     $testEntities = array(new Item(new ItemId('Q1')), new Property(new PropertyId('P1'), null, 'string'), new Property(new PropertyId('P12'), null, 'string', new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P999')), null, null, 'GUID1')))), new Item(new ItemId('Q2'), new Fingerprint(new TermList(array(new Term('en', 'en-label'), new Term('de', 'de-label'))), new TermList(array(new Term('fr', 'en-desc'), new Term('de', 'de-desc'))), new AliasGroupList(array(new AliasGroup('en', array('ali1', 'ali2')), new AliasGroup('dv', array('ali11', 'ali22'))))), new SiteLinkList(array(new SiteLink('enwiki', 'Berlin'), new SiteLink('dewiki', 'England', array(new ItemId('Q1'))))), new StatementList(array(new Statement(new PropertySomeValueSnak(new PropertyId('P12')), null, null, 'GUID1'), new Statement(new PropertySomeValueSnak(new PropertyId('P12')), $snakList, new ReferenceList(array(new Reference(array(new PropertyValueSnak(new PropertyId('P12'), new StringValue('refSnakVal')), new PropertyNoValueSnak(new PropertyId('P12')))))), 'GUID2')))));
     foreach ($testEntities as $key => $testEntity) {
         $mockRepo->putEntity($testEntity);
         $mockEntityPerPage->addEntityPage($testEntity->getId(), $key);
     }
     $dumpScript->setServices($mockEntityPerPage, new NullEntityPrefetcher(), $this->getMockPropertyDataTypeLookup(), $mockRepo);
     $logFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpJsonTest");
     $outFileName = tempnam(sys_get_temp_dir(), "Wikibase-DumpJsonTest");
     $dumpScript->loadParamsAndArgs(null, array('log' => $logFileName, 'output' => $outFileName));
     $dumpScript->execute();
     $expectedLog = file_get_contents(__DIR__ . '/../data/maintenance/dumpJson-log.txt');
     $expectedOut = file_get_contents(__DIR__ . '/../data/maintenance/dumpJson-out.txt');
     $this->assertEquals($this->fixLineEndings($expectedLog), $this->fixLineEndings(file_get_contents($logFileName)));
     $this->assertEquals($this->fixLineEndings($expectedOut), $this->fixLineEndings(file_get_contents($outFileName)));
 }