You are here

public function NodeThumbsUpDownWidgetTest::testVoting in Rate 8

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

Tests voting.

File

tests/src/Functional/NodeThumbsUpDownWidgetTest.php, line 25

Class

NodeThumbsUpDownWidgetTest
Tests for the "Thumbs Up / Down" widget.

Namespace

Drupal\Tests\rate\Functional

Code

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

  // Log in as first user.
  $this
    ->drupalLogin($this->users[0]);
  $this
    ->drupalGet('node/1');
  $this
    ->assertThumbsUpDown(0, 0);

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $this
    ->assertThumbsUpDown(100, 0);
  $session
    ->linkExists('Undo');

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

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $this
    ->assertThumbsUpDown(100, 0);
  $session
    ->linkExists('Undo');

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

  // Vote 'Down'.
  $this
    ->clickLink('Down');
  $this
    ->assertThumbsUpDown(50, 50);
  $session
    ->linkExists('Undo');

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

  // Vote 'Up'.
  $this
    ->clickLink('Up');
  $this
    ->assertThumbsUpDown(67, 33);
  $session
    ->linkExists('Undo');
}