public function testAddAutoCommentArgs() { $summary = new Summary('summarytest'); $summary->addAutoCommentArgs("one"); $summary->addAutoCommentArgs(2, new ItemId('Q3')); $summary->addAutoCommentArgs(array("four", "five")); $expected = array('one', 2, new ItemId('Q3'), 'four', 'five'); $this->assertEquals($expected, $summary->getCommentArgs()); }
/** * Checks what has actually changed inside a statement by looking at a ClaimDifference, * constructs an edit-summary based upon that information and returns * a Summary object holding this edit-summary * * @param Statement|null $oldStatement * @param Statement $newStatement * * @return Summary */ public function buildClaimSummary(Statement $oldStatement = null, Statement $newStatement) { $guid = $newStatement->getGuid(); $summary = new Summary($this->apiModuleName); // Only one statement touched, so we're always having singular here. $summary->addAutoCommentArgs(1); $summaryArgs = $this->buildSummaryArgs($newStatement, $guid); $summary->addAutoSummaryArgs($summaryArgs); if ($oldStatement !== null) { //claim is changed $claimDifference = $this->claimDiffer->diffClaims($oldStatement, $newStatement); if ($claimDifference->isAtomic()) { if ($claimDifference->getMainSnakChange() !== null) { $summary->setAction('update'); } elseif ($claimDifference->getQualifierChanges()->isEmpty() === false) { $summary->addAutoCommentArgs($claimDifference->getQualifierChanges()->count()); $summary->setAction('update-qualifiers'); } elseif ($claimDifference->getReferenceChanges()->isEmpty() === false) { $summary->addAutoCommentArgs($claimDifference->getReferenceChanges()->count()); $summary->setAction('update-references'); } elseif ($claimDifference->getRankChange() !== null) { $summary->setAction('update-rank'); } else { // something "else" has changed inside the claim, so falling back to plain update message $summary->setAction('update'); } } else { // TODO: decide what to do if changes affect multiple part of the claim // e.g. concat several autocomments into one? $summary->setAction('update'); } } else { //new claim is added $summary->setAction('create'); } return $summary; }
/** * @dataProvider provideToStringArgs */ public function testToStringArgHandling(array $commentArgs, array $summaryArgs, $expected) { $summary = new Summary('foobar'); $summary->addAutoCommentArgs($commentArgs); $summary->addAutoSummaryArgs($summaryArgs); $formatter = $this->newFormatter(); $this->assertEquals($expected, $formatter->formatSummary($summary)); }
/** * Create a redirect at $fromId pointing to $toId. * * @param EntityId $fromId The ID of the entity to be replaced by the redirect. The entity * must exist and be empty (or be a redirect already). * @param EntityId $toId The ID of the entity the redirect should point to. The Entity must * exist and must not be a redirect. * @param bool $bot Whether the edit should be marked as bot * * @return EntityRedirect * * @throws RedirectCreationException If creating the redirect fails. Calling code may use * RedirectCreationException::getErrorCode() to get further information about the cause of * the failure. An explanation of the error codes can be obtained from getErrorCodeInfo(). */ public function createRedirect(EntityId $fromId, EntityId $toId, $bot) { $this->checkCompatible($fromId, $toId); $this->checkPermissions($fromId); $this->checkExistsNoRedirect($toId); $this->checkEmpty($fromId); $summary = new Summary('wbcreateredirect'); $summary->addAutoCommentArgs($fromId->getSerialization(), $toId->getSerialization()); $redirect = new EntityRedirect($fromId, $toId); $this->saveRedirect($redirect, $summary, $bot); return $redirect; }