You are here

public function ContentModerationNotificationTest::testPreSave in Content Moderation Notifications 8.2

Same name and namespace in other branches
  1. 8.3 tests/src/Unit/Entity/ContentModerationNotificationTest.php \Drupal\Tests\content_moderation_notifications\Unit\Entity\ContentModerationNotificationTest::testPreSave()

@covers ::preSave

File

tests/src/Unit/Entity/ContentModerationNotificationTest.php, line 106

Class

ContentModerationNotificationTest
Tests for the notification entity.

Namespace

Drupal\Tests\content_moderation_notifications\Unit\Entity

Code

public function testPreSave() {
  $data = static::$data;
  $data['roles']['not_set'] = 0;
  $data['transitions']['not_set'] = 0;
  $notification = new ContentModerationNotification($data, 'content_moderation_notification');

  // Mock out some necessary services.
  $container = new ContainerBuilder();
  $entity_manager = $this
    ->prophesize(EntityManagerInterface::class);
  $entity_type = $this
    ->prophesize(EntityTypeInterface::class)
    ->reveal();
  $entity_manager
    ->getDefinition('content_moderation_notification')
    ->willReturn($entity_type);
  $container
    ->set('entity.manager', $entity_manager
    ->reveal());
  \Drupal::setContainer($container);
  $storage = $this
    ->prophesize(EntityStorageInterface::class);
  $query = $this
    ->prophesize(QueryInterface::class);
  $query
    ->execute()
    ->willReturn([]);
  $query
    ->condition('uuid', NULL)
    ->willReturn($query
    ->reveal());
  $storage
    ->getQuery()
    ->willReturn($query
    ->reveal());
  $storage
    ->loadUnchanged('foo')
    ->willReturn($notification);
  $notification
    ->preSave($storage
    ->reveal());
  $this
    ->assertEquals(static::$data['roles'], $notification
    ->getRoleIds());
  $this
    ->assertEquals(static::$data['transitions'], $notification
    ->getTransitions());
}