You are here

public function EntitySubqueuePreSaveTest::testNewRevision in Acquia Content Hub 8.2

Tests CreateNewRevision event subscriber.

@covers ::onPreEntitySave

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Kernel/EventSubscriber/PreEntitySave/EntitySubqueuePreSaveTest.php, line 51

Class

EntitySubqueuePreSaveTest
Test that new revisions are handled correctly in PreEntitySave event.

Namespace

Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\PreEntitySave

Code

public function testNewRevision() {

  // Create a test content type.
  $this
    ->createContentType();

  // Create a test node.
  $node = $this
    ->createNode();

  // Add a entity queue with minimum data only.
  $entity_queue = EntityQueue::create([
    'id' => $this
      ->randomMachineName(),
    'label' => $this
      ->randomString(),
    'handler' => 'simple',
    'entity_settings' => [
      'target_type' => 'node',
    ],
  ]);
  $entity_queue
    ->save();
  $entity_subqueue = EntitySubqueue::load($entity_queue
    ->id());
  $entity_subqueue_uuid = $entity_subqueue
    ->uuid();

  // Not saving entity subqueue due to integrity constraints.
  $subqueue = EntitySubqueue::create([
    'queue' => $entity_queue
      ->id(),
    'name' => $entity_queue
      ->id(),
    'title' => 'Actual entity subqueue',
    'langcode' => $entity_queue
      ->language()
      ->getId(),
    'attached_entity' => $node,
  ]);
  $settings = $this->clientFactory
    ->getClient()
    ->getSettings();
  $cdf = new CDFObject('drupal8_content_entity', $subqueue
    ->uuid(), date('c'), date('c'), $settings
    ->getUuid());
  $event = new PreEntitySaveEvent($subqueue, new DependencyStack(), $cdf);
  $database = \Drupal::service('database');
  $create_new_revision = new EntitySubqueuePreSave($database);
  $create_new_revision
    ->onPreEntitySave($event);
  $this
    ->assertTrue($event
    ->isPropagationStopped());
  $subqueue_deleted = $this->entityTypeManager
    ->getStorage('entity_subqueue')
    ->loadByProperties([
    'uuid' => $entity_subqueue_uuid,
  ]);
  $this
    ->assertEmpty($subqueue_deleted);
}