You are here

public function NodeFivestarWidgetTest::testVoting in Rate 8

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

Tests voting.

File

tests/src/FunctionalJavascript/NodeFivestarWidgetTest.php, line 29

Class

NodeFivestarWidgetTest
Tests for the "Fivestar" 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
    ->assertFivestar(0);
  $session
    ->linkExists('Star');
  $session
    ->linkNotExists('Undo');

  // Vote 5 stars.
  $this
    ->voteFivestar(5);
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertFivestar(5);
  $session
    ->linkExists('Undo');

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

  // Vote 3 stars.
  $this
    ->voteFivestar(3);
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertFivestar(4);
  $session
    ->linkExists('Undo');

  // Tests unvote.
  $this
    ->clickLink('Undo');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertFivestar(5);
  $session
    ->linkNotExists('Undo');
}