You are here

public function NodeThumbsUpWidgetTest::testVoting in Rate 8

Same name in this branch
  1. 8 tests/src/Functional/NodeThumbsUpWidgetTest.php \Drupal\Tests\rate\Functional\NodeThumbsUpWidgetTest::testVoting()
  2. 8 tests/src/FunctionalJavascript/NodeThumbsUpWidgetTest.php \Drupal\Tests\rate\FunctionalJavascript\NodeThumbsUpWidgetTest::testVoting()

Tests voting.

File

tests/src/FunctionalJavascript/NodeThumbsUpWidgetTest.php, line 25

Class

NodeThumbsUpWidgetTest
Tests for the "Thumbs Up" widget.

Namespace

Drupal\Tests\rate\FunctionalJavascript

Code

public function testVoting() {
  $session = $this
    ->assertSession();

  // Log in as first user.
  $this
    ->drupalLogin($this->users[0]);
  $this
    ->drupalGet('node/1');
  $this
    ->assertThumbsUp(0);
  $session
    ->linkNotExists('Undo');

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertThumbsUp(1);
  $session
    ->linkExists('Undo');

  // Unvote 'Up'.
  $this
    ->clickLink('Undo');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertThumbsUp(0);
  $session
    ->linkNotExists('Undo');

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertThumbsUp(1);
  $session
    ->linkExists('Undo');

  // Log in as different user.
  $this
    ->drupalLogin($this->users[1]);
  $this
    ->drupalGet('node/1');
  $this
    ->assertThumbsUp(1);
  $session
    ->linkNotExists('Undo');

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertThumbsUp(2);
  $session
    ->linkExists('Undo');
}