You are here

public function PollVoteTest::testClosedPollVoteCancel in Poll 8

Test closed poll with "Cancel vote" button.

File

tests/src/Functional/PollVoteTest.php, line 159

Class

PollVoteTest
Tests voting on a poll.

Namespace

Drupal\Tests\poll\Functional

Code

public function testClosedPollVoteCancel() {

  /** @var PollInterface $poll */
  $poll = $this
    ->pollCreate();
  $this
    ->drupalLogin($this->web_user);
  $choices = $poll->choice
    ->getValue();
  $this
    ->drupalGet('poll/' . $poll
    ->id());

  // Vote on a poll.
  $edit = array(
    'choice' => $choices[0]['target_id'],
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Vote'));
  $elements = $this
    ->xpath('//input[@value="Cancel vote"]');
  $this
    ->assertTrue(isset($elements[0]), "'Cancel your vote' button appears.");

  // Close a poll.
  $this
    ->drupalLogin($this->admin_user);
  $this
    ->drupalGet('poll/' . $poll
    ->id() . '/edit');
  $edit = [
    'status[value]' => FALSE,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));

  // Check closed poll with "Cancel vote" button.
  $this
    ->drupalLogin($this->web_user);
  $this
    ->drupalGet('poll/' . $poll
    ->id());
  $elements = $this
    ->xpath('//input[@value="Cancel vote"]');
  $this
    ->assertFalse(isset($elements[0]), "'Cancel your vote' button not appears.");
}