You are here

public function NodeMultipleWidgetTest::testVoting in Rate 8

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

Tests voting.

File

tests/src/FunctionalJavascript/NodeMultipleWidgetTest.php, line 92

Class

NodeMultipleWidgetTest
Tests of multiple widgets for different nodes.

Namespace

Drupal\Tests\rate\FunctionalJavascript

Code

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

  // Tests 'Fivestar' voting on Article.
  $this
    ->drupalLogin($this->users[0]);
  $this
    ->drupalGet('node/1');
  $this
    ->assertFivestar(0);
  $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');

  // Tests 'Thumbs Up / Down' voting on Basic Page.
  $this
    ->drupalLogin($this->users[0]);
  $this
    ->drupalGet('node/2');
  $this
    ->assertThumbsUpDown(0, 0);

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

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

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

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

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

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

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