View source
<?php
namespace Drupal\Tests\lingotek\Functional\Form;
use Drupal\Tests\content_moderation\Traits\ContentModerationTestTrait;
use Drupal\workflows\Entity\Workflow;
class LingotekNodeBulkFormWithContentModerationTest extends LingotekNodeBulkFormTest {
use ContentModerationTestTrait;
public static $modules = [
'block',
'node',
'content_moderation',
];
protected $node;
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block', [
'region' => 'content',
'weight' => -5,
]);
$this
->drupalPlaceBlock('local_tasks_block', [
'region' => 'content',
'weight' => -10,
]);
$workflow = $this
->createEditorialWorkflow();
$this
->enableModerationThroughUI('article');
$this
->addReviewStateToEditorialWorkflow();
$this
->saveLingotekContentTranslationSettings([
'node' => [
'article' => [
'profiles' => 'automatic',
'fields' => [
'title' => 1,
'body' => 1,
],
'moderation' => [
'upload_status' => 'published',
'download_transition' => 'request_review',
],
],
],
]);
}
public function testContentStateFilter() {
$assert_session = $this
->assertSession();
$edit = [];
$edit['title[0][value]'] = 'Llamas are cool';
$edit['body[0][value]'] = 'Llamas are very cool';
$edit['langcode[0][value]'] = 'en';
$edit['lingotek_translation_management[lingotek_translation_profile]'] = 'manual';
$this
->saveAsNewDraftNodeForm($edit);
$this
->goToContentBulkManagementForm();
$assert_session
->optionExists('filters[advanced_options][content_state]', 'All');
$assert_session
->optionExists('filters[advanced_options][content_state]', 'archived');
$assert_session
->optionExists('filters[advanced_options][content_state]', 'published');
$assert_session
->optionExists('filters[advanced_options][content_state]', 'draft');
$update = [
'filters[advanced_options][content_state]' => 'draft',
];
$this
->drupalPostForm(NULL, $update, 'edit-filters-actions-submit');
$assert_session
->linkExists('Llamas are cool');
$this
->assertFieldByName('filters[advanced_options][content_state]', 'draft', 'The value is retained in the filter.');
$this
->saveAndKeepPublishedNodeForm($edit, 1);
$this
->goToContentBulkManagementForm();
$update = [
'filters[advanced_options][content_state]' => 'published',
];
$this
->drupalPostForm(NULL, $update, 'edit-filters-actions-submit');
$assert_session
->linkExists('Llamas are cool');
$this
->assertFieldByName('filters[advanced_options][content_state]', 'published', 'The value is retained in the filter.');
$this
->saveAndArchiveNodeForm($edit, 1);
$this
->goToContentBulkManagementForm();
$update = [
'filters[advanced_options][content_state]' => 'archived',
];
$this
->drupalPostForm(NULL, $update, 'edit-filters-actions-submit');
$assert_session
->linkExists('Llamas are cool');
$this
->assertFieldByName('filters[advanced_options][content_state]', 'archived', 'The value is retained in the filter.');
$update = [
'filters[advanced_options][content_state]' => 'published',
];
$this
->drupalPostForm(NULL, $update, 'edit-filters-actions-submit');
$assert_session
->linkNotExists('Llamas are cool');
}
protected function enableModerationThroughUI($content_type_id) {
$this
->drupalGet('/admin/config/workflow/workflows/manage/editorial/type/node');
$this
->assertFieldByName("bundles[{$content_type_id}]");
$edit["bundles[{$content_type_id}]"] = TRUE;
$this
->drupalPostForm(NULL, $edit, t('Save'));
}
protected function addReviewStateToEditorialWorkflow() {
$workflow = Workflow::load('editorial');
$definition = $workflow
->getTypePlugin();
$definition
->addState('needs_review', 'Needs Review');
$definition
->addTransition('request_review', 'Request Review', [
'draft',
], 'needs_review');
$definition
->addTransition('publish_review', 'Publish Review', [
'needs_review',
], 'published');
$definition
->addTransition('back_to_draft', 'Back to Draft', [
'needs_review',
], 'draft');
$workflow
->save();
}
}