You are here

public function ModerationDashboardComponentsTest::testModerationElement in Moderation Dashboard 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ModerationDashboardComponentsTest.php \Drupal\Tests\moderation_dashboard\Functional\ModerationDashboardComponentsTest::testModerationElement()

Tests that blocks and other elements exist on the user dashboard.

File

tests/src/Functional/ModerationDashboardComponentsTest.php, line 66

Class

ModerationDashboardComponentsTest
Tests moderation dashboard components.

Namespace

Drupal\Tests\moderation_dashboard\Functional

Code

public function testModerationElement() {
  $this
    ->drupalCreateNode([
    'title' => 'Draft node',
    'moderation_state' => 'draft',
  ]);
  $this
    ->drupalCreateNode([
    'title' => 'Published node',
    'moderation_state' => 'published',
  ]);
  $this
    ->drupalGet('/user/' . $this->user
    ->id() . '/moderation-dashboard');
  foreach ($this->moderationElements as $selector => $asserts) {
    $contains = !empty($asserts['contains']) ? $asserts['contains'] : [];
    $not_contains = !empty($asserts['not_contains']) ? $asserts['not_contains'] : [];
    $moderation_element = $this
      ->assertSession()
      ->elementExists('css', $selector);
    $this
      ->assertSame(FALSE, strpos($moderation_element
      ->getText(), 'This block is broken or missing.'));
    foreach ($contains as $text) {
      $this
        ->assertNotSame(FALSE, strpos($moderation_element
        ->getText(), $text));
    }
    foreach ($not_contains as $text) {
      $this
        ->assertSame(FALSE, strpos($moderation_element
        ->getText(), $text));
    }
  }
}