예제 #1
0
 /**
  * @depends testCreateItem
  */
 public function testSetAliases()
 {
     $factory = $factory = TestEnvironment::newDefault()->getFactory();
     $aliasFr = new AliasGroup('fr', array('aa', 'bb'));
     $r = $factory->newAliasGroupSetter()->set($aliasFr, self::$itemId);
     $this->assertTrue($r);
     self::$localItem->getFingerprint()->getAliasGroups()->setGroup($aliasFr);
 }
예제 #2
0
 public function testPatchesLabels()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('en', 'foo');
     $item->getFingerprint()->setLabel('de', 'bar');
     $patch = new ItemDiff(array('label' => new Diff(array('en' => new DiffOpChange('foo', 'spam'), 'nl' => new DiffOpAdd('baz')))));
     $patchedItem = $this->getPatchedItem($item, $patch);
     $this->assertSame(array('en' => 'spam', 'de' => 'bar', 'nl' => 'baz'), $patchedItem->getFingerprint()->getLabels()->toTextArray());
 }
예제 #3
0
 private function toDiffArray(Item $item)
 {
     $array = array();
     $array['aliases'] = $item->getFingerprint()->getAliasGroups()->toTextArray();
     $array['label'] = $item->getFingerprint()->getLabels()->toTextArray();
     $array['description'] = $item->getFingerprint()->getDescriptions()->toTextArray();
     $array['links'] = $this->getLinksInDiffFormat($item);
     return $array;
 }
 private function setUpEntities()
 {
     global $wgUser;
     static $setup = false;
     if ($setup) {
         return;
     }
     $setup = true;
     $store = WikibaseRepo::getDefaultInstance()->getStore()->getEntityStore();
     // remove entities we care about
     $idsToDelete = array(new ItemId('Q404'), new ItemId('Q23'), new PropertyId('P404'));
     foreach ($idsToDelete as $id) {
         try {
             $store->deleteEntity($id, 'test', $wgUser);
         } catch (StorageException $ex) {
             // ignore
         }
     }
     // Set up Q23
     $item = new Item(new ItemId('Q23'));
     $item->getFingerprint()->setLabel('en', 'George Washington');
     // Set up P42
     $property = new Property(new PropertyId('P42'), null, 'string');
     $store->saveEntity($item, 'testing', $wgUser, EDIT_NEW);
     $store->saveEntity($property, 'testing', $wgUser, EDIT_NEW);
 }
예제 #5
0
 private function generateAliasesChangeOps()
 {
     foreach ($this->fromItem->getFingerprint()->getAliasGroups()->toTextArray() as $langCode => $aliases) {
         $this->fromChangeOps->add($this->getFingerprintChangeOpFactory()->newRemoveAliasesOp($langCode, $aliases));
         $this->toChangeOps->add($this->getFingerprintChangeOpFactory()->newAddAliasesOp($langCode, $aliases));
     }
 }
예제 #6
0
 private function patchItem(Item $item, EntityDiff $patch)
 {
     $this->fingerprintPatcher->patchFingerprint($item->getFingerprint(), $patch);
     if ($patch instanceof ItemDiff) {
         $item->setSiteLinkList($this->siteLinkListPatcher->getPatchedSiteLinkList($item->getSiteLinkList(), $patch->getSiteLinkDiff()));
     }
     $item->setStatements($this->statementListPatcher->getPatchedStatementList($item->getStatements(), $patch->getClaimsDiff()));
 }
 /**
  * @param Item $item
  *
  * @return string
  */
 public function generate(Item $item)
 {
     $fingerprintGenerator = new FingerprintSearchTextGenerator();
     $text = $fingerprintGenerator->generate($item->getFingerprint());
     foreach ($item->getSiteLinkList()->toArray() as $siteLink) {
         $text .= "\n" . $siteLink->getPageName();
     }
     return trim($text, "\n");
 }
 public function testGivenKnownItemId_itemLabelIsReturned()
 {
     $item = new Item(new ItemId('Q1337'));
     $item->getFingerprint()->setAliasGroup('en', ['foo', 'bar', 'baz']);
     $this->testEnvironment->insertItem($item);
     $client = $this->createClient();
     $client->request('GET', '/items/Q1337/aliases');
     $this->assertSuccessResponse(['foo', 'bar', 'baz'], $client->getResponse());
 }
 public function testGivenUntrimmedPageName_generateDoesNotTrim()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('en', ' untrimmed label ');
     $item->getSiteLinkList()->addNewSiteLink('enwiki', ' untrimmed pageName ');
     $generator = new ItemSearchTextGenerator();
     $text = $generator->generate($item);
     $this->assertSame(" untrimmed label \n untrimmed pageName ", $text);
 }
예제 #10
0
 public function testConstructionDiffContainsAddOperations()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('en', 'foo');
     $item->getSiteLinkList()->addNewSiteLink('bar', 'baz');
     $differ = new ItemDiffer();
     $diff = $differ->getConstructionDiff($item);
     $this->assertEquals(new Diff(array('en' => new DiffOpAdd('foo'))), $diff->getLabelsDiff());
     $this->assertEquals(new Diff(array('bar' => new Diff(array('name' => new DiffOpAdd('baz'))))), $diff->getSiteLinkDiff());
 }
 protected static function getItem()
 {
     $item = new Item();
     $fingerprint = $item->getFingerprint();
     $fingerprint->setLabel('en', 'Venezuela');
     $fingerprint->setDescription('en', 'a country');
     $fingerprint->setAliasGroup('en', array('Bolivarian Republic of Venezuela'));
     $siteLinks = $item->getSiteLinkList();
     $siteLinks->addNewSiteLink('enwiki', 'Venezuela');
     $siteLinks->addNewSiteLink('jawiki', 'ベネズエラ');
     $siteLinks->addNewSiteLink('cawiki', 'Veneçuela');
     return $item;
 }
 public function testAttemptSave()
 {
     $mockApiBase = $this->getMockApiBase();
     $mockApiBase->expects($this->once())->method('isWriteMode')->will($this->returnValue(true));
     $mockApiBase->expects($this->atLeastOnce())->method('getContext')->will($this->returnValue($this->newContext()));
     $mockApiBase->expects($this->atLeastOnce())->method('extractRequestParams')->will($this->returnValue(array()));
     $helper = new EntitySavingHelper($mockApiBase, $this->getMockErrorReporter(), $this->getMockSummaryFormatter(), $this->getMockEditEntityFactory(1));
     $entity = new Item();
     $entity->setId(new ItemId('Q444'));
     $entity->getFingerprint()->setLabel('en', 'Foo');
     $entity->getSiteLinkList()->addNewSiteLink('enwiki', 'APage');
     $entity->getStatements()->addNewStatement(new PropertyNoValueSnak(new PropertyId('P8')));
     $summary = 'A String Summary';
     $flags = 0;
     $status = $helper->attemptSaveEntity($entity, $summary, $flags);
     $this->assertTrue($status->isGood());
 }
 /**
  * Returns a MockRepository. The following entities are defined:
  *
  * - Items Q23
  * - Item Q42
  * - Redirect Q2233 -> Q23
  * - Redirect Q222333 -> Q23
  * - Property P5 (item reference)
  *
  * @return MockRepository
  */
 private function getMockRepository()
 {
     $mockRepo = new MockRepository();
     $p5 = new Property(new PropertyId('P5'), null, 'wikibase-item');
     $p5->getFingerprint()->setLabel('en', 'Label5');
     $mockRepo->putEntity($p5);
     $q23 = new Item(new ItemId('Q23'));
     $q23->getFingerprint()->setLabel('en', 'Label23');
     $mockRepo->putEntity($q23);
     $q2233 = new EntityRedirect(new ItemId('Q2233'), new ItemId('Q23'));
     $mockRepo->putRedirect($q2233);
     $q222333 = new EntityRedirect(new ItemId('Q222333'), new ItemId('Q23'));
     $mockRepo->putRedirect($q222333);
     $q42 = new Item(new ItemId('Q42'));
     $q42->getFingerprint()->setLabel('en', 'Label42');
     $snak = new PropertyValueSnak($p5->getId(), new EntityIdValue($q2233->getEntityId()));
     $q42->getStatements()->addNewStatement($snak, null, null, 'Q42$DEADBEEF');
     $mockRepo->putEntity($q42);
     return $mockRepo;
 }
예제 #14
0
 public function deserializationProvider()
 {
     $provider = array(array(new Item(), array('type' => 'item')));
     $item = new Item(new ItemId('Q42'));
     $provider[] = array($item, array('type' => 'item', 'id' => 'Q42'));
     $item = new Item();
     $item->getFingerprint()->setLabel('en', 'foo');
     $provider[] = array($item, array('type' => 'item', 'labels' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
     $item = new Item();
     $item->getFingerprint()->setDescription('en', 'foo');
     $provider[] = array($item, array('type' => 'item', 'descriptions' => array('en' => array('lang' => 'en', 'value' => 'foo'))));
     $item = new Item();
     $item->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $provider[] = array($item, array('type' => 'item', 'aliases' => array('en' => array('lang' => 'en', 'values' => array('foo', 'bar')))));
     $item = new Item();
     $item->getStatements()->addNewStatement(new PropertyNoValueSnak(42), null, null, 'test');
     $provider[] = array($item, array('type' => 'item', 'claims' => array('P42' => array(array('mainsnak' => array('snaktype' => 'novalue', 'property' => 'P42'), 'type' => 'statement', 'rank' => 'normal')))));
     $item = new Item();
     $item->addSiteLink(new SiteLink('enwiki', 'Nyan Cat'));
     $provider[] = array($item, array('type' => 'item', 'sitelinks' => array('enwiki' => array('site' => 'enwiki', 'title' => 'Nyan Cat', 'badges' => array()))));
     return $provider;
 }
 public function execute()
 {
     global $wgUser;
     $user = $wgUser;
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     if (!defined('WB_VERSION')) {
         $this->output("You need to have Wikibase enabled in order to use this maintenance script!\n\n");
         exit;
     }
     $report = function ($message) {
         echo $message . "\n";
     };
     $items = array('Q1' => 'Universe', 'Q2' => 'Earth', 'Q3' => 'Life', 'Q4' => 'Death', 'Q5' => 'Human', 'Q8' => 'Happiness', 'Q13' => 'Triskaidekaphobia', 'Q23' => 'George Washington', 'Q24' => 'Jack Bauer', 'Q42' => 'Douglas Adams', 'Q80' => 'Tim Berners-Lee', 'Q666' => 'Number of the Beast', 'Q1337' => 'Leet', 'Q1868' => 'Paul Otlet', 'Q1971' => 'Imagine (song)', 'Q2001' => 'Stanley Kubrick', 'Q2012' => 'Maya calendar', 'Q2013' => 'Wikidata');
     $report('Starting import...');
     foreach ($items as $id => $name) {
         $report("   Importing {$name} as item {$id}...");
         $item = new Item(new ItemId($id));
         $item->getFingerprint()->setLabel('en', $name);
         $item->getSiteLinkList()->addNewSiteLink('enwiki', $name);
         $store->saveEntity($item, 'Import', $user, EDIT_NEW);
     }
     $report('Import completed.');
 }
예제 #16
0
 public function testCopyRetainsLabels()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('en', 'foo');
     $item->getFingerprint()->setLabel('de', 'bar');
     $newItem = $item->copy();
     $this->assertTrue($newItem->getFingerprint()->getLabels()->hasTermForLanguage('en'));
     $this->assertTrue($newItem->getFingerprint()->getLabels()->hasTermForLanguage('de'));
 }
예제 #17
0
 private function setTermsFromSerialization(array $serialization, Item $item)
 {
     if (array_key_exists('labels', $serialization)) {
         $this->assertAttributeIsArray($serialization, 'labels');
         $item->getFingerprint()->setLabels($this->termListDeserializer->deserialize($serialization['labels']));
     }
     if (array_key_exists('descriptions', $serialization)) {
         $this->assertAttributeIsArray($serialization, 'descriptions');
         $item->getFingerprint()->setDescriptions($this->termListDeserializer->deserialize($serialization['descriptions']));
     }
     if (array_key_exists('aliases', $serialization)) {
         $this->assertAttributeIsArray($serialization, 'aliases');
         $item->getFingerprint()->setAliasGroups($this->aliasGroupListDeserializer->deserialize($serialization['aliases']));
     }
 }
예제 #18
0
 private function getBaseItem()
 {
     $item = new Item(new ItemId('Q42'));
     $item->getFingerprint()->setLabel('en', 'Same');
     $item->getFingerprint()->setDescription('en', 'Same');
     $item->getFingerprint()->setAliasGroup('en', array('Same'));
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Same');
     $item->getStatements()->addNewStatement(new PropertyNoValueSnak(42));
     return $item;
 }
 private function getContent()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('en', 'Kitten');
     $item->getSiteLinkList()->addNewSiteLink('enwiki', 'Kitten');
     $item->getStatements()->addNewStatement(new PropertyNoValueSnak(new PropertyId('P1')));
     $entityContentFactory = WikibaseRepo::getDefaultInstance()->getEntityContentFactory();
     return $entityContentFactory->newFromEntity($item);
 }
 /**
  * @param ItemId $id
  * @param string[] $labels
  * @param Statement[]|null $statements
  * @param SiteLink[]|null $siteLinks
  *
  * @return Item
  */
 private function createTestItem(ItemId $id, array $labels, array $statements = null, array $siteLinks = null)
 {
     $item = new Item($id);
     $item->getFingerprint()->setDescription('de', 'Description of ' . $id->getSerialization());
     foreach ($labels as $lang => $label) {
         $item->setLabel($lang, $label);
     }
     if ($statements !== null) {
         $item->setStatements(new StatementList($statements));
     }
     if ($siteLinks !== null) {
         $item->setSiteLinkList(new SiteLinkList($siteLinks));
     }
     $this->siteLinkLookup->putEntity($item);
     return $item;
 }
예제 #21
0
 private function addTermsToSerialization(Item $item, array &$serialization)
 {
     $fingerprint = $item->getFingerprint();
     $serialization['labels'] = $this->termListSerializer->serialize($fingerprint->getLabels());
     $serialization['descriptions'] = $this->termListSerializer->serialize($fingerprint->getDescriptions());
     $serialization['aliases'] = $this->aliasGroupListSerializer->serialize($fingerprint->getAliasGroups());
 }
 /**
  * @see EntityInfoBuilder::collectTerms
  *
  * @param string[]|null $types Which types of terms to include (e.g. "label", "description", "aliases").
  * @param string[]|null $languages Which languages to include
  */
 public function collectTerms(array $types = null, array $languages = null)
 {
     foreach ($this->entityInfo as $id => &$entityRecord) {
         $id = $this->parseId($id);
         $entity = $this->getEntity($id);
         if (!$entity) {
             // hack: fake an empty entity, so the field get initialized
             $entity = new Item();
         }
         // FIXME: OCP violation
         // This code does not allow extensions that define new entity types with
         // new types of terms to register appropriate support for those here.
         if ($entity instanceof FingerprintProvider) {
             $this->injectFingerprint($types, $entityRecord, $entity->getFingerprint(), $languages);
         }
     }
 }
 public function testAddEntityRevisionWithLanguagesFilter()
 {
     $item = new Item(new ItemId('Q123099'));
     $item->getFingerprint()->setLabel('en', 'text');
     $item->getFingerprint()->setLabel('de', 'text');
     $item->getFingerprint()->setDescription('en', 'text');
     $item->getFingerprint()->setDescription('de', 'text');
     $item->getFingerprint()->setAliasGroup('en', array('text'));
     $item->getFingerprint()->setAliasGroup('de', array('text'));
     $entityRevision = new EntityRevision($item);
     $result = $this->getDefaultResult();
     $resultBuilder = $this->getResultBuilder($result);
     $resultBuilder->addEntityRevision(null, $entityRevision, array('labels', 'descriptions', 'aliases'), array(), array('de'));
     $expected = array('entities' => array('Q123099' => array('id' => 'Q123099', 'type' => 'item', 'labels' => array('de' => array('language' => 'de', 'value' => 'text')), 'descriptions' => array('de' => array('language' => 'de', 'value' => 'text')), 'aliases' => array('de' => array(array('language' => 'de', 'value' => 'text'))))), '_type' => 'assoc');
     $data = $result->getResultData();
     $this->assertEquals($expected, $data);
 }
예제 #24
0
 /**
  * @return array 1=>from 2=>to 3=>expectedFrom 4=>expectedTo
  */
 public function provideData()
 {
     $testCases = array();
     $itemWithEnLabel = new Item();
     $itemWithEnLabel->getFingerprint()->setLabel('en', 'foo');
     $testCases['labelMerge'] = array($itemWithEnLabel->copy(), new Item(), new Item(), $itemWithEnLabel->copy());
     $testCases['identicalLabelMerge'] = array($itemWithEnLabel->copy(), $itemWithEnLabel->copy(), new Item(), $itemWithEnLabel->copy());
     $itemWithEnBarLabel = new Item();
     $itemWithEnBarLabel->getFingerprint()->setLabel('en', 'bar');
     $itemWithLabelAndAlias = new Item();
     $itemWithLabelAndAlias->getFingerprint()->setLabel('en', 'bar');
     $itemWithLabelAndAlias->getFingerprint()->setAliasGroup('en', array('foo'));
     $testCases['labelAsAliasMerge'] = array($itemWithEnLabel->copy(), $itemWithEnBarLabel->copy(), new Item(), $itemWithLabelAndAlias->copy());
     $itemWithDescription = new Item();
     $itemWithDescription->getFingerprint()->setDescription('en', 'foo');
     $testCases['descriptionMerge'] = array($itemWithDescription->copy(), new Item(), new Item(), $itemWithDescription->copy());
     $testCases['identicalDescriptionMerge'] = array($itemWithDescription->copy(), $itemWithDescription->copy(), new Item(), $itemWithDescription->copy());
     $itemWithBarDescription = new Item();
     $itemWithBarDescription->getFingerprint()->setDescription('en', 'bar');
     $testCases['ignoreConflictDescriptionMerge'] = array($itemWithDescription->copy(), $itemWithBarDescription->copy(), $itemWithDescription->copy(), $itemWithBarDescription->copy(), array('description'));
     $itemWithFooBarAliases = new Item();
     $itemWithFooBarAliases->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $testCases['aliasMerge'] = array($itemWithFooBarAliases->copy(), new Item(), new Item(), $itemWithFooBarAliases->copy());
     $itemWithFooBarBazAliases = new Item();
     $itemWithFooBarBazAliases->getFingerprint()->setAliasGroup('en', array('foo', 'bar', 'baz'));
     $testCases['duplicateAliasMerge'] = array($itemWithFooBarAliases->copy(), $itemWithFooBarBazAliases->copy(), new Item(), $itemWithFooBarBazAliases->copy());
     $itemWithLink = new Item();
     $itemWithLink->getSiteLinkList()->addNewSiteLink('enwiki', 'foo');
     $testCases['linkMerge'] = array($itemWithLink->copy(), new Item(), new Item(), $itemWithLink->copy());
     $testCases['sameLinkLinkMerge'] = array($itemWithLink->copy(), $itemWithLink->copy(), new Item(), $itemWithLink->copy());
     $itemWithBarLink = new Item();
     $itemWithBarLink->getSiteLinkList()->addNewSiteLink('enwiki', 'bar');
     $testCases['ignoreConflictLinkMerge'] = array($itemWithLink->copy(), $itemWithBarLink->copy(), $itemWithLink->copy(), $itemWithBarLink->copy(), array('sitelink'));
     $statement = new Statement(new PropertyNoValueSnak(new PropertyId('P56')));
     $statement->setGuid('Q111$D8404CDA-25E4-4334-AF13-A390BCD9C556');
     $itemWithStatement = new Item();
     $itemWithStatement->getStatements()->addStatement($statement);
     $testCases['statementMerge'] = array($itemWithStatement->copy(), new Item(), new Item(), $itemWithStatement->copy());
     $qualifiedStatement = new Statement(new PropertyNoValueSnak(new PropertyId('P56')), new SnakList(array(new PropertyNoValueSnak(new PropertyId('P56')))));
     $qualifiedStatement->setGuid('Q111$D8404CDA-25E4-4334-AF13-A390BCD9C556');
     $itemWithQualifiedStatement = new Item();
     $itemWithQualifiedStatement->getStatements()->addStatement($qualifiedStatement);
     $testCases['statementWithQualifierMerge'] = array($itemWithQualifiedStatement->copy(), new Item(), new Item(), $itemWithQualifiedStatement->copy());
     $anotherQualifiedStatement = new Statement(new PropertyNoValueSnak(new PropertyId('P88')), new SnakList(array(new PropertyNoValueSnak(new PropertyId('P88')))));
     $anotherQualifiedStatement->setGuid('Q111$D8404CDA-25E4-4334-AF88-A3290BCD9C0F');
     $selfReferencingStatement = new Statement(new PropertyValueSnak(new PropertyId('P42'), new EntityIdValue(new ItemId('Q111'))));
     $selfReferencingStatement->setGuid('Q111$D74D43D7-BD8F-4240-A058-24C5171ABBFA');
     $bigItem = new Item();
     $bigItem->setId(111);
     $bigItem->getFingerprint()->setLabel('en', 'foo');
     $bigItem->getFingerprint()->setLabel('pt', 'ptfoo');
     $bigItem->getFingerprint()->setDescription('en', 'foo');
     $bigItem->getFingerprint()->setDescription('pl', 'pldesc');
     $bigItem->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $bigItem->getFingerprint()->setAliasGroup('de', array('defoo', 'debar'));
     $bigItem->getSiteLinkList()->addNewSiteLink('dewiki', 'foo');
     $bigItem->getStatements()->addStatement($anotherQualifiedStatement);
     $bigItem->getStatements()->addStatement($selfReferencingStatement);
     $testCases['itemMerge'] = array($bigItem->copy(), new Item(), new Item(), $bigItem->copy());
     $referencingStatement = new Statement(new PropertyValueSnak(new PropertyId('P42'), new EntityIdValue(new ItemId('Q222'))));
     $referencingStatement->setGuid('Q111$949A4D27-0EBC-46A7-BF5F-AA2DD33C0443');
     $bigItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'bar');
     $bigItem->getStatements()->addStatement($referencingStatement);
     $smallerItem = new Item();
     $smallerItem->setId(222);
     $smallerItem->getFingerprint()->setLabel('en', 'toLabel');
     $smallerItem->getFingerprint()->setDescription('pl', 'toDescription');
     $smallerItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'toLink');
     $smallerMergedItem = new Item();
     $smallerMergedItem->setId(222);
     $smallerMergedItem->getFingerprint()->setDescription('pl', 'pldesc');
     $smallerMergedItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'bar');
     $bigMergedItem = new Item();
     $bigMergedItem->setId(111);
     $bigMergedItem->getFingerprint()->setLabel('en', 'toLabel');
     $bigMergedItem->getFingerprint()->setLabel('pt', 'ptfoo');
     $bigMergedItem->getFingerprint()->setDescription('en', 'foo');
     $bigMergedItem->getFingerprint()->setDescription('pl', 'toDescription');
     $bigMergedItem->getFingerprint()->setAliasGroup('en', array('foo', 'bar'));
     $bigMergedItem->getFingerprint()->setAliasGroup('de', array('defoo', 'debar'));
     $bigMergedItem->getSiteLinkList()->addNewSiteLink('dewiki', 'foo');
     $bigMergedItem->getSiteLinkList()->addNewSiteLink('nlwiki', 'toLink');
     $bigMergedItem->setStatements(new StatementList($anotherQualifiedStatement, $selfReferencingStatement, $referencingStatement));
     $testCases['ignoreConflictItemMerge'] = array($bigItem->copy(), $smallerItem->copy(), $smallerMergedItem->copy(), $bigMergedItem->copy(), array('description', 'sitelink', 'statement'));
     return $testCases;
 }
예제 #25
0
 public function testValidate_()
 {
     $item = new Item();
     $changeOp = $this->getMockBuilder('\\Wikibase\\ChangeOp\\ChangeOp')->disableOriginalConstructor()->getMock();
     $changeOp->expects($this->any())->method('validate')->will($this->returnCallback(function (Item $item) {
         // Fail when the label is already set (by a previous apply call).
         return $item->getFingerprint()->hasLabel('en') ? Result::newError(array()) : Result::newSuccess();
     }));
     $changeOp->expects($this->any())->method('apply')->will($this->returnCallback(function (Item $item) {
         $item->setLabel('en', 'Label');
     }));
     $changeOps = new ChangeOps();
     $changeOps->add($changeOp);
     $changeOps->add($changeOp);
     $result = $changeOps->validate($item);
     $this->assertFalse($result->isValid(), 'Validate must fail with this mock');
     $this->assertTrue($item->isEmpty(), 'Item must still be empty');
 }
예제 #26
0
 private function addAliases()
 {
     if ($this->item->getFingerprint()->hasAliasGroup($this->languageCode)) {
         $this->simpleItem->aliases = $this->item->getFingerprint()->getAliasGroup($this->languageCode)->getAliases();
     }
 }
 public function getFieldDataProvider()
 {
     $item = new Item();
     $item->getFingerprint()->setLabel('es', 'Gato');
     return array(array(1, $item), array(0, Property::newFromType('string')));
 }