You are here

protected function PollTestBase::getChoiceIdByLabel in Poll 8

Get the Choice ID of a poll from the label.

Parameters

\Drupal\poll\PollInterface $poll: The poll of the choice.

string $label: The label of the choice.

Return value

int $id Returns the choice id or an error.

Throws

InvalidArgumentException Throws it if the poll does not have the choice label.

1 call to PollTestBase::getChoiceIdByLabel()
PollVoteMultilingualTest::testPollVoteMultilingual in tests/src/Functional/PollVoteMultilingualTest.php
Tests multilingual voting on a poll.

File

tests/src/Functional/PollTestBase.php, line 282

Class

PollTestBase
Defines a base class for testing the Poll module.

Namespace

Drupal\Tests\poll\Functional

Code

protected function getChoiceIdByLabel(PollInterface $poll, $label) {
  $options = $poll
    ->getOptions();
  foreach ($options as $id => $option) {
    if ($label == $option) {
      return $id;
    }
  }
  throw new InvalidArgumentException();
}