public function RevisionIsCurrentTest::testRevisionIsCurrent in Acquia Content Hub 8.2
Tests that only current published revisions are enqueued.
@dataProvider testRevisionIsCurrentDataProvider
Parameters
array $moderation_states: Array containing the moderation states.
array $expected_queue_count: Array containing the number, how many queue items we expect after transition.
array $langcodes: Langcodes that defines which translation are we working with.
array $message: Messages displayed on failure.
Throws
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Kernel/ RevisionIsCurrentTest.php, line 96
Class
- RevisionIsCurrentTest
- Tests that only current published revisions are enqueued.
Namespace
Drupal\Tests\acquia_contenthub\KernelCode
public function testRevisionIsCurrent(array $moderation_states, array $expected_queue_count, array $langcodes, array $message) {
// Makes sure queue is empty before this test.
$this->contentHubQueue
->purgeQueues();
// Creates and translates a draft, make sure it isn't added yet.
/** @var \Drupal\node\NodeInterface $node */
$node = Node::create([
'type' => 'bundle_test',
'moderation_state' => 'draft',
'langcode' => 'en',
'title' => 'Test EN',
]);
$node
->save();
$this
->assertEqual($this->contentHubQueue
->getQueueCount(), 0, 'Node created as draft not queued.');
$node
->addTranslation('es', [
'moderation_state' => 'draft',
'title' => 'Test ES',
]);
$node
->save();
$this
->assertEqual($this->contentHubQueue
->getQueueCount(), 0, 'Translation created as draft not queued.');
foreach ($moderation_states as $key => $moderation_state) {
// If we wouldn't purge the queues every time then the
// IsAlreadyEnqueued subscriber would prevent the queue creation
// and we would got false queue counts for the given scenarios.
$this->contentHubQueue
->purgeQueues();
$node = $node
->getTranslation($langcodes[$key]);
$node
->setNewRevision(TRUE);
$node
->set('moderation_state', $moderation_state);
$node
->save();
$this
->assertEqual($this->contentHubQueue
->getQueueCount(), $expected_queue_count[$key], $message[$key]);
}
}