You are here

public function ModerationSidebarTaxonomyTermTest::testModerationSidebar in Moderation Sidebar 8

Tests that the Moderation Sidebar is working as expected.

File

tests/src/FunctionalJavascript/ModerationSidebarTaxonomyTermTest.php, line 72

Class

ModerationSidebarTaxonomyTermTest
Contains Moderation Sidebar integration tests.

Namespace

Drupal\Tests\moderation_sidebar\FunctionalJavascript

Code

public function testModerationSidebar() {

  // Create a new term.
  $term = $this
    ->createTerm($this->vocabulary);
  $this
    ->drupalGet($term
    ->toUrl()
    ->toString());

  // Open the moderation sidebar.
  $this
    ->clickLink('Tasks');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->elementExists('css', '.moderation-sidebar-info');
  $this
    ->assertSession()
    ->elementTextContains('css', '.moderation-sidebar-info', 'Published');
  $this
    ->assertSession()
    ->elementTextContains('css', 'a.moderation-sidebar-link', 'View');
  $this
    ->assertSession()
    ->elementAttributeContains('css', 'a.moderation-sidebar-link', 'href', $term
    ->toUrl()
    ->toString());

  // We don't have permission to edit.
  $this
    ->assertSession()
    ->elementNotExists('css', 'a.moderation-sidebar-link + a.moderation-sidebar-link');

  // Login as user able to edit the term.
  $user = $this
    ->drupalCreateUser([
    'access toolbar',
    'use moderation sidebar',
    'access content',
    'edit terms in ' . $this->vocabulary
      ->id(),
  ]);
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet($term
    ->toUrl()
    ->toString());
  $this
    ->clickLink('Tasks');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $this
    ->assertSession()
    ->elementTextContains('css', 'a.moderation-sidebar-link', 'View');
  $this
    ->assertSession()
    ->elementExists('css', 'a.moderation-sidebar-link + a.moderation-sidebar-link');
  $this
    ->assertSession()
    ->elementTextContains('css', 'a.moderation-sidebar-link + a.moderation-sidebar-link', 'Edit');
  $this
    ->assertSession()
    ->elementAttributeContains('css', 'a.moderation-sidebar-link + a.moderation-sidebar-link', 'href', $term
    ->toUrl()
    ->toString() . '/edit');
}