ContentModerationWorkflowTypeTest.php 3.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

namespace Drupal\Tests\content_moderation\Functional;

use Drupal\Tests\BrowserTestBase;

/**
 * Test the workflow type plugin in the content_moderation module.
 *
 * @group content_moderation
 */
class ContentModerationWorkflowTypeTest extends BrowserTestBase {

  /**
   * Modules to install.
   *
   * @var array
   */
  public static $modules = [
    'content_moderation',
    'node',
22
    'entity_test',
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  ];

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    $admin = $this->drupalCreateUser([
      'administer workflows',
    ]);
    $this->drupalLogin($admin);
  }

  /**
   * Test creating a new workflow using the content moderation plugin.
   */
  public function testNewWorkflow() {
40
41
42
43
    $types[] = $this->createContentType();
    $types[] = $this->createContentType();
    $types[] = $this->createContentType();

44
45
46
    $entity_bundle_info = \Drupal::service('entity_type.bundle.info');

    $this->drupalPostForm('admin/config/workflow/workflows/add', [
47
48
      'label' => 'Test',
      'id' => 'test',
49
50
      'workflow_type' => 'content_moderation',
    ], 'Save');
51

52
    $session = $this->assertSession();
53
    // Make sure the test workflow includes the default states and transitions.
54
55
56
57
    $session->pageTextContains('Draft');
    $session->pageTextContains('Published');
    $session->pageTextContains('Create New Draft');
    $session->pageTextContains('Publish');
58

59
60
    $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/draft/delete');
    $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/state/published/delete');
61

62
63
64
65
66
    // Ensure after a workflow is created, the bundle information can be
    // refreshed.
    $entity_bundle_info->clearCachedBundles();
    $this->assertNotEmpty($entity_bundle_info->getAllBundleInfo());

67
    $this->clickLink('Add a new state');
68
69
70
    $this->submitForm([
      'label' => 'Test State',
      'id' => 'test_state',
71
72
      'type_settings[published]' => TRUE,
      'type_settings[default_revision]' => FALSE,
73
    ], 'Save');
74
75
    $session->pageTextContains('Created Test State state.');
    $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/state/test_state/delete');
76
77

    // Check there is a link to delete a default transition.
78
    $session->linkByHrefExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
79
    // Delete the transition.
80
    $this->drupalGet('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
81
82
    $this->submitForm([], 'Delete');
    // The link to delete the transition should now be gone.
83
    $session->linkByHrefNotExists('/admin/config/workflow/workflows/manage/test/transition/publish/delete');
84
85

    // Ensure that the published settings cannot be changed.
86
87
88
    $this->drupalGet('admin/config/workflow/workflows/manage/test/state/published');
    $session->fieldDisabled('type_settings[published]');
    $session->fieldDisabled('type_settings[default_revision]');
89
90

    // Ensure that the draft settings cannot be changed.
91
92
93
94
95
    $this->drupalGet('admin/config/workflow/workflows/manage/test/state/draft');
    $session->fieldDisabled('type_settings[published]');
    $session->fieldDisabled('type_settings[default_revision]');

    $this->drupalGet('admin/config/workflow/workflows/manage/test/type/node');
96
    $session->pageTextContains('Select the content types for the Test workflow');
97
98
    foreach ($types as $type) {
      $session->pageTextContains($type->label());
99
      $session->elementContains('css', sprintf('.form-item-bundles-%s label', $type->id()), sprintf('Update %s', $type->label()));
100
    }
101
102
103
104

    // Ensure warning message are displayed for unsupported features.
    $this->drupalGet('admin/config/workflow/workflows/manage/test/type/entity_test_rev');
    $this->assertSession()->pageTextContains('Test entity - revisions entities do not support publishing statuses. For example, even after transitioning from a published workflow state to an unpublished workflow state they will still be visible to site visitors.');
105
106
107
  }

}