You are here

public function GatsbyEntityLoggerTest::testEntityInsert in Gatsby Live Preview & Incremental Builds 8

Same name and namespace in other branches
  1. 2.0.x modules/gatsby_fastbuilds/tests/src/Kernel/GatsbyEntityLoggerTest.php \Drupal\Tests\gatsby_fastbuilds\Kernel\GatsbyEntityLoggerTest::testEntityInsert()

Tests entity insert.

File

modules/gatsby_fastbuilds/tests/src/Kernel/GatsbyEntityLoggerTest.php, line 82

Class

GatsbyEntityLoggerTest
Defines a test for the GatsbyEntityLogger.

Namespace

Drupal\Tests\gatsby_fastbuilds\Kernel

Code

public function testEntityInsert() {
  $log_storage = \Drupal::entityTypeManager()
    ->getStorage('gatsby_log_entity');
  $this
    ->assertCount(0, $log_storage
    ->loadMultiple());
  $entity = Node::create([
    'type' => 'page',
    'status' => 1,
    'title' => 'foo',
    'moderation_state' => 'published',
  ]);
  $entity
    ->save();
  $logs = $log_storage
    ->loadMultiple();
  $this
    ->assertCount(1, $logs);
  $log = reset($logs);
  $this
    ->assertEquals('insert', $log->action->value);
  $this
    ->assertEquals('node', $log->entity->value);
  $this
    ->assertEquals('page', $log->bundle->value);
  $this
    ->assertEquals($entity
    ->uuid(), $log->entity_uuid->value);
  $entity->status = 0;
  $entity->moderation_state = 'draft';
  $entity
    ->setNewRevision();
  $entity
    ->save();
  $log_storage
    ->resetCache();
  $logs = $log_storage
    ->loadMultiple();
  $this
    ->assertCount(1, $logs);
  $log = reset($logs);
  $this
    ->assertEquals('insert', $log->action->value);
  $this
    ->assertEquals('node', $log->entity->value);
  $this
    ->assertEquals('page', $log->bundle->value);
  $this
    ->assertEquals($entity
    ->uuid(), $log->entity_uuid->value);
}