/**
  * @param ItemId $id
  * @param ItemId $target
  *
  * @throws RuntimeException
  * @return EntityContent
  */
 protected function makeItemRedirectContent(ItemId $id, ItemId $target)
 {
     $title = Title::newFromText($target->getSerialization());
     $redirect = new EntityRedirect($id, $target);
     $content = ItemContent::newFromRedirect($redirect, $title);
     return $content;
 }
 public function itemProvider()
 {
     $emptyItem = new Item(new ItemId('Q1'));
     $item = new Item(new ItemId('Q11'));
     $item->setDescription('en', 'ohi there');
     $item->setLabel('de', 'o_O');
     $item->setAliases('nl', array('foo', 'bar'));
     $item2 = new Item(new ItemId('Q12'));
     $item2->setLabel('de', 'o_O');
     $item2->setLabel('en', 'O_o');
     $item2->setAliases('nl', array('daaaah'));
     $redirect = new EntityRedirect(new ItemId('Q11'), new ItemId('Q21'));
     $redirect2 = new EntityRedirect(new ItemId('Q11'), new ItemId('Q22'));
     $insTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <ins>foo</ins>' => array('tag' => 'ins', 'content' => 'foo'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <ins>bar</ins>' => array('tag' => 'ins', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <ins>ohi there</ins>' => array('tag' => 'ins', 'content' => 'ohi there'));
     $delTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <del>bar</del>' => array('tag' => 'del', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <del>ohi there</del>' => array('tag' => 'del', 'content' => 'ohi there'));
     $changeTags = array('has <td>label / en</td>' => array('tag' => 'td', 'content' => 'label / en'), 'has <ins>O_o</ins>' => array('tag' => 'ins', 'content' => 'O_o'), 'has <td>aliases / nl / 0</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 0'), 'has <ins>daaaah</ins>' => array('tag' => 'ins', 'content' => 'daaaah'), 'has <td>aliases / nl / 1</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 1'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>aliases / nl / 2</td>' => array('tag' => 'td', 'content' => 'aliases / nl / 2'), 'has <del>bar</del>' => array('tag' => 'del', 'content' => 'bar'), 'has <td>description / en</td>' => array('tag' => 'td', 'content' => 'description / en'), 'has <del>ohi there</del>' => array('tag' => 'del', 'content' => 'ohi there'));
     $fromRedirTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <ins>foo</ins>' => array('tag' => 'ins', 'content' => 'foo'), 'has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <del>Q21</del>' => array('tag' => 'del', 'content' => 'Q21'));
     $toRedirTags = array('has <td>label / de</td>' => array('tag' => 'td', 'content' => 'label / de'), 'has <del>foo</del>' => array('tag' => 'del', 'content' => 'foo'), 'has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <ins>Q21</ins>' => array('tag' => 'ins', 'content' => 'Q21'));
     $changeRedirTags = array('has <td>redirect</td>' => array('tag' => 'td', 'content' => 'redirect'), 'has <del>Q21</del>' => array('tag' => 'del', 'content' => 'Q21'), 'has <ins>Q22</del>' => array('tag' => 'ins', 'content' => 'Q22'));
     $empty = ItemContent::newFromItem($emptyItem);
     $itemContent = ItemContent::newFromItem($item);
     $itemContent2 = ItemContent::newFromItem($item2);
     $redirectContent = ItemContent::newFromRedirect($redirect, Title::newFromText($redirect->getEntityId()->getSerialization()));
     $redirectContent2 = ItemContent::newFromRedirect($redirect2, Title::newFromText($redirect2->getEntityId()->getSerialization()));
     return array('empty' => array($empty, $empty, array('empty' => '/^$/')), 'same' => array($itemContent, $itemContent, array('empty' => '/^$/')), 'from emtpy' => array($empty, $itemContent, $insTags), 'to empty' => array($itemContent, $empty, $delTags), 'changed' => array($itemContent, $itemContent2, $changeTags), 'to redirect' => array($itemContent, $redirectContent, $toRedirTags), 'from redirect' => array($redirectContent, $itemContent, $fromRedirTags), 'redirect changed' => array($redirectContent, $redirectContent2, $changeRedirTags));
 }
 public function changeOpAliasesProvider()
 {
     // "INVALID" is invalid
     $validatorFactory = $this->getTermValidatorFactory();
     $enAliases = array('en-alias1', 'en-alias2', 'en-alias3');
     $existingEnAliases = array('en-existingAlias1', 'en-existingAlias2');
     $itemContent = ItemContent::newEmpty();
     $item = $itemContent->getEntity();
     $item->setAliases('en', $existingEnAliases);
     return array('add' => array($item->copy(), new ChangeOpAliases('en', $enAliases, 'add', $validatorFactory), array_merge($existingEnAliases, $enAliases)), 'set' => array($item->copy(), new ChangeOpAliases('en', $enAliases, 'set', $validatorFactory), $enAliases), 'set (default)' => array($item->copy(), new ChangeOpAliases('en', $enAliases, '', $validatorFactory), $enAliases), 'remove' => array($item->copy(), new ChangeOpAliases('en', $existingEnAliases, 'remove', $validatorFactory), null));
 }
 /**
  * @param Status $inputStatus
  * @param Entity|EntityRedirect|null $new
  * @param array $expected
  *
  * @dataProvider runData
  */
 public function testRun_hooksAreCalled(Status $inputStatus, $new, array $expected)
 {
     $hooks = array_merge($GLOBALS['wgHooks'], array('EditFilterMergedContent' => array()));
     $testCase = $this;
     $hooks['EditFilterMergedContent'][] = function (IContextSource $context, Content $content, Status $status, $summary, User $user, $minoredit) use($testCase, $expected, $inputStatus) {
         $testCase->assertEquals($expected['title'], $context->getTitle()->getFullText());
         $testCase->assertSame($context->getTitle(), $context->getWikiPage()->getTitle());
         $testCase->assertEquals($expected['namespace'], $context->getTitle()->getNamespace());
         $testCase->assertEquals(ItemContent::newEmpty(), $content);
         $testCase->assertTrue($status->isGood());
         $testCase->assertTrue(is_string($summary));
         $testCase->assertEquals('EditFilterHookRunnerTestUser', $user->getName());
         $testCase->assertTrue(is_bool($minoredit));
         //Change the status
         $status->merge($inputStatus);
     };
     $this->setMwGlobals(array('wgHooks' => $hooks));
     $runner = $this->getEditFilterHookRunner();
     $status = $runner->run($new, User::newFromName('EditFilterHookRunnerTestUser'), 'summary');
     $this->assertEquals($expected['status'], $status);
 }
 public function testIsStub_nonStubItem()
 {
     $item = new Item();
     $item->getStatements()->addNewStatement(new PropertyNoValueSnak(42));
     $content = ItemContent::newFromItem($item);
     $this->assertFalse($content->isStub());
 }
 public function testSetRevisionInfo()
 {
     if (!defined('WB_VERSION')) {
         $this->markTestSkipped('Need to be able to create entity content in order to test with Revision objects.');
     }
     $id = new ItemId('Q7');
     $item = new Item($id);
     $entityChange = $this->newEntityChange($id);
     $timestamp = '20140523' . '174422';
     $revision = new Revision(array('id' => 5, 'page' => 6, 'user' => 7, 'parent_id' => 3, 'user_text' => 'Mr. Kittens', 'timestamp' => $timestamp, 'content' => ItemContent::newFromItem($item), 'comment' => 'Test!'));
     $entityChange->setRevisionInfo($revision);
     $this->assertEquals(5, $entityChange->getField('revision_id'), 'revision_id');
     $this->assertEquals(7, $entityChange->getField('user_id'), 'user_id');
     $this->assertEquals('q7', $entityChange->getObjectId(), 'object_id');
     $this->assertEquals($timestamp, $entityChange->getTime(), 'timestamp');
     $this->assertEquals('Test!', $entityChange->getComment(), 'comment');
     $metadata = $entityChange->getMetadata();
     $this->assertEquals(3, $metadata['parent_id'], 'parent_id');
     $this->assertEquals(6, $metadata['page_id'], 'page_id');
     $this->assertEquals(5, $metadata['rev_id'], 'rev_id');
     $this->assertEquals('Mr. Kittens', $metadata['user_text'], 'user_text');
 }