You are here

trait NodeVoteTrait in Rate 8

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/NodeVoteTrait.php \Drupal\Tests\rate\Traits\NodeVoteTrait

Provides methods to voting on nodes.

This trait is meant to be used only by Functional and FunctionalJavascript test classes.

Hierarchy

7 files declare their use of NodeVoteTrait
NodeFivestarWidgetTest.php in tests/src/Functional/NodeFivestarWidgetTest.php
NodeFivestarWidgetTest.php in tests/src/FunctionalJavascript/NodeFivestarWidgetTest.php
NodeMultipleWidgetTest.php in tests/src/Functional/NodeMultipleWidgetTest.php
NodeMultipleWidgetTest.php in tests/src/FunctionalJavascript/NodeMultipleWidgetTest.php
RateMultilingualTest.php in tests/src/Functional/RateMultilingualTest.php

... See full list

File

tests/src/Traits/NodeVoteTrait.php, line 11

Namespace

Drupal\Tests\rate\Traits
View source
trait NodeVoteTrait {

  /**
   * Vote "Fivestar" by node id.
   *
   * @param int $nid
   *   The node id.
   * @param int $stars
   *   The number of stars vote (from 1 to 5).
   */
  protected function voteFivestarById($nid, $stars) {
    $this
      ->assertSession()
      ->elementExists('css', '.rate-fivestar-1');
    $node_selector = '[data-drupal-selector="rate-node-' . $nid . '"]';
    $this
      ->click($node_selector . ' .rate-fivestar-' . $stars);
  }

  /**
   * Un-vote "Fivestar" by node id.
   *
   * @param int $nid
   *   The node id.
   */
  protected function unVoteFivestarById($nid) {
    $this
      ->assertSession()
      ->elementExists('css', '.rate-fivestar-1');
    $node_selector = '[data-drupal-selector="rate-node-' . $nid . '"]';
    $this
      ->click($node_selector . ' .rate-undo');
  }

  /**
   * Vote Fivestar for the single node.
   *
   * @param int $stars
   *   The number of stars vote (from 1 to 5).
   */
  protected function voteFivestar($stars) {
    $this
      ->assertSession()
      ->elementExists('css', '.rate-widget-fivestar');
    $this
      ->click('.rate-fivestar-' . $stars);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NodeVoteTrait::unVoteFivestarById protected function Un-vote "Fivestar" by node id.
NodeVoteTrait::voteFivestar protected function Vote Fivestar for the single node.
NodeVoteTrait::voteFivestarById protected function Vote "Fivestar" by node id.