You are here

public function ConfigEntityRevisionsRevertFormBaseTest::revertedVersionOfRevisionGeneratedCorrectly in Config Entity Revisions 1.x

Same name and namespace in other branches
  1. 8.2 tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php \Drupal\Tests\config_entity_revisions\Unit\ConfigEntityRevisionsRevertFormBaseTest::revertedVersionOfRevisionGeneratedCorrectly()
  2. 8 tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php \Drupal\Tests\config_entity_revisions\Unit\ConfigEntityRevisionsRevertFormBaseTest::revertedVersionOfRevisionGeneratedCorrectly()

Check that preparation of a reverted revision does all it should.

@test

File

tests/src/Unit/ConfigEntityRevisionsRevertFormBaseTest.php, line 320

Class

ConfigEntityRevisionsRevertFormBaseTest

Namespace

Drupal\Tests\config_entity_revisions\Unit

Code

public function revertedVersionOfRevisionGeneratedCorrectly() {
  $this->instance = $this
    ->getMockInstance(300);
  $revision = $this->mockOldRevision;
  $revision
    ->setNewRevision()
    ->shouldBeCalled();
  $revision
    ->isDefaultRevision(Argument::type('bool'))
    ->shouldBeCalled()
    ->should(function ($calls) {
    if (!$calls || !$calls[0]
      ->getArguments()[0]) {
      throw new \Exception("isDefaultRevision wasn't set to TRUE.");
    }
  });
  $revision
    ->getRevisionLogMessage()
    ->willReturn('Vanity of vanities!');
  $savedMessage = NULL;
  $revision
    ->setRevisionLogMessage(Argument::type("Drupal\\Core\\StringTranslation\\TranslatableMarkup"))
    ->will(function ($newMessage) use (&$savedMessage) {
    $savedMessage = $newMessage[0];
  });
  $savedUserId = NULL;
  $revision
    ->setRevisionUserId(Argument::type('int'))
    ->will(function ($newUserId) use (&$savedUserId) {
    $savedUserId = $newUserId[0];
  });
  $savedCreationTime = NULL;
  $revision
    ->setRevisionCreationTime(Argument::type('int'))
    ->will(function ($newCreationTime) use (&$savedCreationTime) {
    $savedCreationTime = $newCreationTime[0];
  });
  $savedChangedTime = NULL;
  $revision
    ->setChangedTime(Argument::type('int'))
    ->will(function ($newChangedTime) use (&$savedChangedTime) {
    $savedChangedTime = $newChangedTime[0];
  });
  $publicationStatus = NULL;
  $revision
    ->setUnpublished()
    ->shouldBeCalled();
  $key_value_pairs = [];
  $revision
    ->set(Argument::type('string'), Argument::any())
    ->will(function ($arguments) use (&$key_value_pairs) {
    $key_value_pairs[$arguments[0]] = $arguments[1];
  });
  $this->instance
    ->prepareRevertedRevision($revision
    ->reveal());
  $this
    ->assertEquals('Copy of the revision from %date (%message).', $savedMessage
    ->getUntranslatedString());
  $this
    ->assertEquals(1717, $savedUserId);
  $this
    ->assertEquals(1260, $savedCreationTime);
  $this
    ->assertEquals(1260, $savedChangedTime);
  $this
    ->assertEquals([
    'moderation_state' => 'draft',
  ], $key_value_pairs);

  // And without a revision log message.
  $revision
    ->getRevisionLogMessage()
    ->willReturn();
  $this->instance
    ->prepareRevertedRevision($revision
    ->reveal());
  $this
    ->assertEquals('Copy of the revision from %date.', $savedMessage
    ->getUntranslatedString());
  $this
    ->assertEquals(1717, $savedUserId);
  $this
    ->assertEquals(1260, $savedCreationTime);
  $this
    ->assertEquals(1260, $savedChangedTime);
  $this
    ->assertEquals([
    'moderation_state' => 'draft',
  ], $key_value_pairs);
}