You are here

protected function AssertRateWidgetTrait::assertFivestarById in Rate 8

Same name and namespace in other branches
  1. 8.2 tests/src/Traits/AssertRateWidgetTrait.php \Drupal\Tests\rate\Traits\AssertRateWidgetTrait::assertFivestarById()

Assert "Fivestar" by node id.

Parameters

int $nid: The node id.

int $expected: The expected number of stars (from 0 to 5).

1 call to AssertRateWidgetTrait::assertFivestarById()
ViewsFivestarWidgetTest::testFivestarViewsWidget in tests/src/FunctionalJavascript/ViewsFivestarWidgetTest.php
Tests a fivestar views widget.

File

tests/src/Traits/AssertRateWidgetTrait.php, line 38

Class

AssertRateWidgetTrait
Assert methods to verify results of voting for a single node.

Namespace

Drupal\Tests\rate\Traits

Code

protected function assertFivestarById($nid, $expected) {
  $session = $this
    ->assertSession();
  $node_selector = '[data-drupal-selector="rate-node-' . $nid . '"]';
  $session
    ->elementExists('css', '.rate-fivestar-1');
  if ($expected > 0) {
    $session
      ->elementExists('css', $node_selector . ' .rate-fivestar-btn-filled.rate-fivestar-' . $expected);
  }
  if ($expected < 5) {
    $session
      ->elementExists('css', $node_selector . ' .rate-fivestar-btn-empty.rate-fivestar-' . ++$expected);
  }
}