private function newSiteLinks()
 {
     $links = new SiteLinkList();
     $links->addNewSiteLink('enwiki', 'En Page');
     $links->addNewSiteLink('dewiki', 'De Page');
     return $links;
 }
 public function testPatchesMultipleSiteLinks()
 {
     $links = new SiteLinkList();
     $links->addNewSiteLink('dewiki', 'bar');
     $links->addNewSiteLink('nlwiki', 'baz', array(new ItemId('Q42')));
     $patch = new Diff(array('nlwiki' => new Diff(array('name' => new DiffOpChange('baz', 'kittens'), 'badges' => new Diff(array(new DiffOpRemove('Q42')), false))), 'frwiki' => new Diff(array('name' => new DiffOpAdd('Berlin'), 'badges' => new Diff(array(new DiffOpAdd('Q42')), false)))));
     $expectedLinks = new SiteLinkList();
     $expectedLinks->addNewSiteLink('dewiki', 'bar');
     $expectedLinks->addNewSiteLink('nlwiki', 'kittens');
     $expectedLinks->addNewSiteLink('frwiki', 'Berlin', array(new ItemId('Q42')));
     $this->assertLinksResultsFromPatch($expectedLinks, $links, $patch);
 }
 public function entitiesProvider()
 {
     $statements = new StatementList();
     $statements->addNewStatement(new PropertyNoValueSnak(1));
     $q1 = new Item(null, null, null, $statements);
     $siteLinks = new SiteLinkList();
     $siteLinks->addNewSiteLink('enwiki', 'Title');
     $q2 = new Item(null, null, $siteLinks);
     return array(array(array(), 0, 0), array(array($q1), 1, 0), array(array($q2), 0, 1), array(array($q1, $q2), 1, 1));
 }
 /**
  * @param SiteLinkList $siteLinks
  * @param Diff $patch
  *
  * @return SiteLinkList
  * @throws InvalidArgumentException
  */
 public function getPatchedSiteLinkList(SiteLinkList $siteLinks, Diff $patch)
 {
     $baseData = $this->getSiteLinksInDiffFormat($siteLinks);
     $patchedData = $this->patcher->patch($baseData, $patch);
     $patchedSiteLinks = new SiteLinkList();
     foreach ($patchedData as $siteId => $siteLinkData) {
         if (array_key_exists('name', $siteLinkData)) {
             $patchedSiteLinks->addNewSiteLink($siteId, $siteLinkData['name'], $this->getBadgesFromSiteLinkData($siteLinkData));
         }
     }
     return $patchedSiteLinks;
 }
 public function entityIdProvider()
 {
     $set1 = new StatementList();
     $this->addStatement($set1, 'Q1');
     $set2 = new StatementList();
     $this->addStatement($set2, 'Q20');
     $this->addStatement($set2, 'Q21');
     $set2->addNewStatement(new PropertyValueSnak(1, QuantityValue::newFromNumber(1, self::UNIT_PREFIX . 'Q22')));
     $siteLinks = new SiteLinkList();
     $siteLinks->addNewSiteLink('siteId', 'pageName', array(new ItemId('Q1')));
     return array(array(new StatementList(), null, array()), array($set1, null, array('P1', 'Q1')), array(new StatementList(), $siteLinks, array('Q1')), array($set1, $siteLinks, array('P1', 'Q1')), array($set2, null, array('P1', 'Q20', 'Q21', 'Q22')), array($set2, $siteLinks, array('P1', 'Q20', 'Q21', 'Q22', 'Q1')));
 }
 public function testGivenSiteLinkWithExistingId_setNewSiteLinkReplacesIt()
 {
     $list = new SiteLinkList();
     $list->addNewSiteLink('enwiki', 'foo');
     $list->addNewSiteLink('dewiki', 'bar');
     $list->setNewSiteLink('enwiki', 'HAX');
     $expectedList = new SiteLinkList();
     $expectedList->addNewSiteLink('enwiki', 'HAX');
     $expectedList->addNewSiteLink('dewiki', 'bar');
     $this->assertEquals($expectedList, $list);
 }