You are here

public function NodeNumberUpDownWidgetTest::testVoting in Rate 8

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

Tests voting.

File

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

Class

NodeNumberUpDownWidgetTest
Tests for the "Number Up / Down" 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
    ->assertNumberUpDown('0');

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

  // Tests unvote.
  $this
    ->clickLink('Undo');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertNumberUpDown('0');
  $session
    ->linkNotExists('Undo');

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

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

  // Vote -1.
  $this
    ->clickLink('Down');
  $session
    ->assertWaitOnAjaxRequest();
  $this
    ->assertNumberUpDown('-2');
  $session
    ->linkExists('Undo');
}