function PollCreateTest::testPollClose in Poll 8
Tests creating, editing, and closing a poll.
File
- tests/
src/ Functional/ PollCreateTest.php, line 60
Class
- PollCreateTest
- Tests creating a poll.
Namespace
Drupal\Tests\poll\FunctionalCode
function testPollClose() {
$poll = $this->poll;
$poll
->close();
$poll
->save();
$this
->drupalLogin($this->web_user);
// Poll create disallowed.
$this
->drupalGet('poll/add');
$this
->assertResponse(403);
// Get a poll.
$this
->drupalGet('poll/' . $poll
->id());
// Verify 'Vote' button no longer appears.
$elements = $this
->xpath('//input[@value="Vote"]');
$this
->assertTrue(empty($elements), "Vote button doesn't appear.");
// Verify 'View Poll' button no longer appears.
$elements = $this
->xpath('value="View poll"');
$this
->assertTrue(empty($elements), "View poll button doesn't appear.");
// Edit the poll and re-activate.
$poll
->open();
$poll
->save();
$this
->drupalGet('poll/' . $poll
->id());
// Verify 'Vote' button no appears.
$elements = $this
->xpath('//input[@value="Vote"]');
$this
->assertFalse(empty($elements), "Vote button appears.");
// Check to see if the vote was recorded and that the user may cancel their vote.
$edit = array(
'choice' => 1,
);
$this
->drupalPostForm(NULL, $edit, t('Vote'));
$this
->assertText('Your vote has been recorded.');
$elements = $this
->xpath('//input[@value="Cancel vote"]');
$this
->assertTrue(isset($elements[0]), "'Cancel vote' button appears.");
// Verify 'Cancel your vote' button no longer appears after poll is closed.
$poll
->close();
$poll
->save();
$this
->drupalGet('poll/' . $poll
->id());
$elements = $this
->xpath('//input[@value="Cancel your vote"]');
$this
->assertTrue(empty($elements), "'Cancel your vote' button no longer appears.");
}