You are here

public function EntityTypeOrBundleExcludeTest::testIsExcluded in Acquia Content Hub 8.2

Tests that expected entities are excluded.

File

tests/src/Kernel/EntityTypeOrBundleExcludeTest.php, line 55

Class

EntityTypeOrBundleExcludeTest
Tests that selected entities are successfully excluded for the queue.

Namespace

Drupal\Tests\acquia_contenthub\Kernel

Code

public function testIsExcluded() {

  // Makes sure queue is empty before this test.
  $this->contentHubQueue
    ->purgeQueues();
  NodeType::create([
    'type' => 'bundle_test',
  ])
    ->save();
  NodeType::create([
    'type' => 'bundle_test_2',
  ])
    ->save();
  $this
    ->assertEquals($this->contentHubQueue
    ->getQueueCount(), 0, 'Node type config entity not queued.');

  // Creates a new user an assert is excluded as expected.
  $user = User::create([
    'name' => $this
      ->randomString(),
    'mail' => 'email1@example.com',
  ]);
  $user
    ->save();
  $this
    ->assertEquals($this->contentHubQueue
    ->getQueueCount(), 0, 'User not queued.');

  // Creates a new published node of an excluded bundle.
  $node_exclude = Node::create([
    'type' => 'bundle_test',
    'title' => 'Should not queue',
  ]);
  $node_exclude
    ->setPublished();
  $node_exclude
    ->save();
  $this
    ->assertEquals($this->contentHubQueue
    ->getQueueCount(), 0, 'Node not queued.');

  // Creates a new published node of a not excluded bundle.
  $node_exclude = Node::create([
    'type' => 'bundle_test_2',
    'title' => 'Should queue',
  ]);
  $node_exclude
    ->setPublished();
  $node_exclude
    ->save();
  $this
    ->assertEquals($this->contentHubQueue
    ->getQueueCount(), 1, 'Node queued.');
}