/**
  * @dataProvider provideConstruction
  *
  * @param EntityDiff $entityDiff
  * @param Diff $redirectDiff
  */
 public function testConstruction(EntityDiff $entityDiff, Diff $redirectDiff)
 {
     $diff = new EntityContentDiff($entityDiff, $redirectDiff);
     $this->assertArrayEquals($entityDiff->getOperations(), $diff->getEntityDiff()->getOperations());
     $this->assertEmpty(array_diff(array_keys($entityDiff->getOperations()), array_keys($diff->getEntityDiff()->getOperations())));
     $this->assertArrayEquals($redirectDiff->getOperations(), $diff->getRedirectDiff()->getOperations());
     $this->assertEmpty(array_diff(array_keys($redirectDiff->getOperations()), array_keys($diff->getRedirectDiff()->getOperations())));
 }
 /**
  * @param EntityDiff $entityDiff
  * @param Diff $redirectDiff
  */
 public function __construct(EntityDiff $entityDiff, Diff $redirectDiff)
 {
     $operations = array();
     $this->entityDiff = $entityDiff;
     $this->redirectDiff = $redirectDiff;
     $operations = array_merge($operations, $this->entityDiff->getOperations());
     $operations = array_merge($operations, $this->redirectDiff->getOperations());
     parent::__construct($operations, true);
 }
Example #3
0
 /**
  * @dataProvider getApplicableDiffProvider
  *
  * @param Diff $diff
  * @param array $currentObject
  * @param Diff $expected
  * @param string|null $message
  */
 public function testGetApplicableDiff(Diff $diff, array $currentObject, Diff $expected, $message = null)
 {
     $patcher = new ListPatcher();
     $actual = $patcher->getApplicableDiff($currentObject, $diff);
     $this->assertEquals($expected->getOperations(), $actual->getOperations(), $message);
 }
Example #4
0
 public function testEmptyElementsInRecursiveDiff()
 {
     $old = array('en' => array('a' => 'en-foo', 'b' => 'en-bar'));
     $new = array('en' => array('a' => 'en-foo', 'b' => 'en-bar'));
     $differ = new MapDiffer(true);
     $diff = new Diff($differ->doDiff($old, $new));
     $this->assertTrue($diff->isEmpty());
     $this->assertTrue($diff->getOperations() === array());
 }
Example #5
0
 /**
  * @dataProvider instanceProvider
  */
 public function testGetOperations(Diff $diff)
 {
     $ops = $diff->getOperations();
     $this->assertInternalType('array', $ops);
     $this->assertContainsOnlyInstancesOf('Diff\\DiffOp\\DiffOp', $ops);
     $this->assertArrayEquals($ops, $diff->getOperations());
 }
 /**
  * Returns an array structure suitable for building an edit summary for the respective
  * change to site links.
  *
  * @param string $action e.g. 'remove', see the constants in EntityChange
  * @param Diff $siteLinkDiff The change's site link diff
  * @param Title|null $title The page we create an edit summary for
  *
  * @return array|null
  */
 private function getSiteLinkMessage($action, Diff $siteLinkDiff, Title $title = null)
 {
     if ($siteLinkDiff->isEmpty()) {
         return null;
     }
     //TODO: Implement comments specific to the affected page.
     //       Different pages may be affected in different ways by the same change.
     //       Also, merged changes may affect the same page in multiple ways.
     $diffOps = $siteLinkDiff->getOperations();
     $siteId = $this->siteId;
     // change involved site link to client wiki
     if (array_key_exists($siteId, $diffOps)) {
         // $siteLinkDiff changed from containing atomic diffs to
         // containing map diffs. For B/C, handle both cases.
         $diffOp = $diffOps[$siteId];
         if ($diffOp instanceof Diff) {
             if (array_key_exists('name', $diffOp)) {
                 $diffOp = $diffOp['name'];
             } else {
                 // change to badges only, use original message
                 return null;
             }
         }
         $params = $this->getSiteLinkAddRemoveParams($diffOp, $action, $siteId, $title);
     } else {
         $diffOpCount = count($diffOps);
         if ($diffOpCount === 1) {
             $params = $this->getSiteLinkChangeParams($diffOps);
         } else {
             // multiple changes, use original message
             return null;
         }
     }
     return $params;
 }