/**
  * @param int $maxLength
  * @param string[] $languageCodes
  *
  * @return TermValidatorFactory
  */
 private function newFactory($maxLength, array $languageCodes)
 {
     $idParser = new BasicEntityIdParser();
     $mockProvider = new ChangeOpTestMockProvider($this);
     $dupeDetector = $mockProvider->getMockLabelDescriptionDuplicateDetector();
     $builders = new TermValidatorFactory($maxLength, $languageCodes, $idParser, $dupeDetector);
     return $builders;
 }
 /**
  * @dataProvider validateProvider
  */
 public function testValidate(EntityId $entityId, $guid, Snak $snak)
 {
     $changeOpMainSnak = new ChangeOpMainSnak($guid, $snak, new GuidGenerator(), $this->mockProvider->getMockSnakValidator());
     $entity = new Item($entityId);
     $result = $changeOpMainSnak->validate($entity);
     $this->assertFalse($result->isValid(), 'isValid()');
 }
 /**
  * @return MergeChangeOpsFactory
  */
 protected function newChangeOpFactory()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     $toItemId = new ItemId('Q3');
     $constraintProvider = $this->getMockBuilder('Wikibase\\Repo\\Validators\\EntityConstraintProvider')->disableOriginalConstructor()->getMock();
     $changeOpFactoryProvider = new ChangeOpFactoryProvider($constraintProvider, $mockProvider->getMockGuidGenerator(), $mockProvider->getMockGuidValidator(), $mockProvider->getMockGuidParser($toItemId), $mockProvider->getMockSnakValidator(), $mockProvider->getMockTermValidatorFactory(), MockSiteStore::newFromTestSites());
     return new MergeChangeOpsFactory($constraintProvider, $changeOpFactoryProvider, MockSiteStore::newFromTestSites());
 }
 protected function makeChangeOpsMerge(Item $fromItem, Item $toItem, array $ignoreConflicts = array(), $siteLookup = null)
 {
     if ($siteLookup === null) {
         $siteLookup = MockSiteStore::newFromTestSites();
     }
     // A validator which makes sure that no site link is for page 'DUPE'
     $siteLinkUniquenessValidator = $this->getMock('Wikibase\\Repo\\Validators\\EntityValidator');
     $siteLinkUniquenessValidator->expects($this->any())->method('validateEntity')->will($this->returnCallback(function (Item $item) {
         $siteLinks = $item->getSiteLinkList();
         foreach ($siteLinks as $siteLink) {
             if ($siteLink->getPageName() === 'DUPE') {
                 return Result::newError(array(Error::newError('SiteLink conflict')));
             }
         }
         return Result::newSuccess();
     }));
     $constraintProvider = $this->getMockBuilder('Wikibase\\Repo\\Validators\\EntityConstraintProvider')->disableOriginalConstructor()->getMock();
     $constraintProvider->expects($this->any())->method('getUpdateValidators')->will($this->returnValue(array($siteLinkUniquenessValidator)));
     $changeOpFactoryProvider = new ChangeOpFactoryProvider($constraintProvider, $this->mockProvider->getMockGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser($toItem->getId()), $this->mockProvider->getMockSnakValidator(), $this->mockProvider->getMockTermValidatorFactory(), $siteLookup);
     return new ChangeOpsMerge($fromItem, $toItem, $ignoreConflicts, $constraintProvider, $changeOpFactoryProvider, $siteLookup);
 }
 /**
  * @param Statement $statement
  * @param int|null $index
  *
  * @return ChangeOpStatement
  */
 private function newChangeOpStatement(Statement $statement, $index = null)
 {
     $idParser = new BasicEntityIdParser();
     return new ChangeOpStatement($statement, new GuidGenerator(), new StatementGuidValidator($idParser), new StatementGuidParser($idParser), $this->mockProvider->getMockSnakValidator(), $index);
 }
 /**
  * @dataProvider provideValidate
  */
 public function testValidate(Entity $entity, $claimGuid, Reference $reference, $referenceHash = '', $index = null)
 {
     $changeOpReference = new ChangeOpReference($claimGuid, $reference, $referenceHash, $this->mockProvider->getMockSnakValidator(), $index);
     $result = $changeOpReference->validate($entity);
     $this->assertFalse($result->isValid(), 'isValid()');
 }
 /**
  * @return FingerprintChangeOpFactory
  */
 protected function newChangeOpFactory()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     return new FingerprintChangeOpFactory($mockProvider->getMockTermValidatorFactory());
 }
 private function getTermValidatorFactory()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     return $mockProvider->getMockTermValidatorFactory();
 }
 /**
  * @return LabelDescriptionDuplicateDetector
  */
 private function getMockDupeDetector()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     return $mockProvider->getMockLabelDescriptionDuplicateDetector();
 }
 /**
  * @dataProvider validateProvider
  */
 public function testValidate(Entity $entity, $claimGuid, Snak $snak, $snakHash = '')
 {
     $changeOpQualifier = new ChangeOpQualifier($claimGuid, $snak, $snakHash, $this->mockProvider->getMockSnakValidator());
     $result = $changeOpQualifier->validate($entity);
     $this->assertFalse($result->isValid(), 'isValid()');
 }
 /**
  * @return ChangeOpFactoryProvider
  */
 protected function newChangeOpFactoryProvider()
 {
     $entityId = new ItemId('Q2');
     $constraintProvider = new EntityConstraintProvider($this->mockProvider->getMockLabelDescriptionDuplicateDetector(), $this->mockProvider->getMockSiteLinkConflictLookup());
     return new ChangeOpFactoryProvider($constraintProvider, $this->mockProvider->getMockGuidGenerator(), $this->mockProvider->getMockGuidValidator(), $this->mockProvider->getMockGuidParser($entityId), $this->mockProvider->getMockSnakValidator(), $this->mockProvider->getMockTermValidatorFactory(), new HashSiteStore(TestSites::getSites()));
 }
 /**
  * @return SiteLinkConflictLookup
  */
 private function getMockSiteLinkConflictLookup()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     return $mockProvider->getMockSiteLinkConflictLookup();
 }
 /**
  * @return StatementChangeOpFactory
  */
 protected function newChangeOpFactory()
 {
     $mockProvider = new ChangeOpTestMockProvider($this);
     $entityId = new PropertyId('P7');
     return new StatementChangeOpFactory($mockProvider->getMockGuidGenerator(), $mockProvider->getMockGuidValidator(), $mockProvider->getMockGuidParser($entityId), $mockProvider->getMockSnakValidator(), $mockProvider->getMockSnakValidator());
 }