View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
class RevisionIsCurrentTest extends QueueingTestBase {
use ContentModerationTestTrait;
public static $modules = [
'node',
'language',
'workflows',
'user',
'content_translation',
'content_moderation',
];
protected $contentTranslationManager;
protected function setUp() : void {
parent::setUp();
$this->contentTranslationManager = $this->container
->get('content_translation.manager');
$this
->installEntitySchema('node');
$this
->installEntitySchema('user');
$this
->installEntitySchema('content_moderation_state');
$this
->installSchema('node', [
'node_access',
]);
$this
->installConfig('content_moderation');
ConfigurableLanguage::createFromLangcode('es')
->save();
$this
->createTranslatableNodeTypeWithWorkflow();
}
protected function createTranslatableNodeTypeWithWorkflow() {
NodeType::create([
'type' => 'bundle_test',
'new_revision' => TRUE,
])
->save();
$workflow = $this
->createEditorialWorkflow();
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', 'bundle_test');
$workflow
->save();
$this->contentTranslationManager
->setEnabled('node', 'bundle_test', TRUE);
}
public function testRevisionIsCurrent(array $moderation_states, array $expected_queue_count, array $langcodes, array $message) {
$this->contentHubQueue
->purgeQueues();
$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) {
$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]);
}
}
public function testRevisionIsCurrentDataProvider() {
return [
[
[
'draft',
'published',
'archived',
],
[
0,
1,
1,
],
[
'en',
'en',
'en',
],
[
'Node transitioned to draft from draft state.',
'Node transitioned to published from draft state.',
'Node transitioned to archived from published state.',
],
],
[
[
'published',
'draft',
'published',
'archived',
'archived',
],
[
1,
1,
1,
1,
0,
],
[
'en',
'en',
'en',
'en',
'en',
],
[
'Node transitioned to published from draft state.',
'Node transitioned to draft from published state.',
'Node transitioned to published from draft state.',
'Node transitioned to archived from published state.',
'Node transitioned to draft from archived state.',
],
],
[
[
'published',
'published',
'archived',
'archived',
'draft',
'draft',
],
[
1,
1,
1,
1,
0,
0,
],
[
'en',
'es',
'en',
'es',
'en',
'es',
],
[
'Node transitioned to published from draft state. (EN)',
'Node transitioned to published from draft state. (ES)',
'Node transitioned to archived from published state. (EN)',
'Node transitioned to archived from published state. (ES)',
'Node transitioned to draft from archived state. (EN)',
'Node transitioned to draft from archived state. (ES)',
],
],
];
}
}