function WorkflowUiNoTypeTest::testWorkflowUiWithNoType

Same name and namespace in other branches
  1. 10 core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php \Drupal\Tests\workflows\Functional\WorkflowUiNoTypeTest::testWorkflowUiWithNoType()
  2. 9 core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php \Drupal\Tests\workflows\Functional\WorkflowUiNoTypeTest::testWorkflowUiWithNoType()
  3. 8.9.x core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php \Drupal\Tests\workflows\Functional\WorkflowUiNoTypeTest::testWorkflowUiWithNoType()

Tests the creation of a workflow through the UI.

File

core/modules/workflows/tests/src/Functional/WorkflowUiNoTypeTest.php, line 41

Class

WorkflowUiNoTypeTest
Tests workflow UI when there are no types.

Namespace

Drupal\Tests\workflows\Functional

Code

public function testWorkflowUiWithNoType() : void {
  $this->drupalLogin($this->createUser([
    'access administration pages',
    'administer workflows',
  ]));
  $this->drupalGet('admin/config/workflow/workflows/add');
  // There are no workflow types so this should be a 403.
  $this->assertSession()
    ->statusCodeEquals(403);
  $this->drupalGet('admin/config/workflow/workflows');
  $this->assertSession()
    ->pageTextContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
  $this->assertSession()
    ->linkExists('Content Moderation');
  $this->assertSession()
    ->pageTextNotContains('Add workflow');
  $this->clickLink('Content Moderation');
  $modules_list_url_absolute = Url::fromRoute('system.modules_list', [], [
    'fragment' => 'module-content-moderation',
    'absolute' => TRUE,
  ])->toString();
  $this->assertSame($this->getSession()
    ->getCurrentUrl(), $modules_list_url_absolute);
  // The current user does not have the 'administer modules' permission.
  $this->assertSession()
    ->statusCodeEquals(403);
  $this->container
    ->get('module_installer')
    ->install([
    'workflow_type_test',
  ]);
  // The render cache needs to be cleared because although the cache tags are
  // correctly set the render cache does not pick it up.
  \Drupal::cache('render')->deleteAll();
  $this->drupalGet('admin/config/workflow/workflows');
  $this->assertSession()
    ->pageTextNotContains('There are no workflow types available. In order to create workflows you need to install a module that provides a workflow type. For example, the Content Moderation module provides a workflow type that enables workflows for content entities.');
  $this->assertSession()
    ->linkExists('Add workflow');
  $this->assertSession()
    ->pageTextContains('There are no workflows yet.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.