You are here

trait NodeVoteTrait in Rate 8.2

Same name and namespace in other branches
  1. 8 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

1 file declares its use of NodeVoteTrait
NodeRateWidgetTestBase.php in tests/src/FunctionalJavascript/NodeRateWidgetTestBase.php

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.