PollHtmlSpecialCharactersTest.php in Poll 8
File
tests/src/Functional/PollHtmlSpecialCharactersTest.php
View source
<?php
namespace Drupal\Tests\poll\Functional;
class PollHtmlSpecialCharactersTest extends PollTestBase {
function setUp() {
parent::setUp();
$this->special_choice = '> old & spice <';
$this->page_title = 'Salt & pepper > here';
$this->poll
->setQuestion($this->page_title)
->setAnonymousVoteAllow(TRUE)
->save();
}
public function testPollQuestion() {
$this
->drupalGet('poll/' . $this->poll
->id());
$this
->assertResponse(200);
$result = $this
->xpath("//div[contains(concat(' ', @class, ' '), ' block-page-title-block ')]/h1");
$this
->assertEqual($this->page_title, $result[0]
->getText(), 'HTML entities displayed correctly in page title.');
$this
->drupalPostForm('poll/' . $this->poll
->id(), [
'choice' => 1,
], t('Vote'));
$this
->assertText('Your vote has been recorded.');
$this
->drupalGet('polls');
$this
->assertSession()
->elementTextContains('css', 'h3.poll-question', $this->page_title);
}
public function testPollChoice() {
$poll = $this->poll;
$poll->choice[0]->entity
->setChoice($this->special_choice);
$poll->choice[0]->entity
->save();
$this
->drupalGet('poll/' . $this->poll
->id());
$this
->assertResponse(200);
$result = $this
->xpath("//div[@id='edit-choice']/div[1]/label/text()");
$this
->assertEqual($this->special_choice, $result[0]
->getText(), 'HTML entities displayed correctly in choice option.');
$this
->drupalPostForm('poll/' . $this->poll
->id(), [
'choice' => 1,
], t('Vote'));
$this
->assertText('Your vote has been recorded.');
$this
->assertText('Total votes: 1');
$result = $this
->xpath('//*[@id="poll-view-form-1"]/div/dl/dt[1]/text()');
$this
->assertEqual($this->special_choice, $result[0]
->getText(), 'HTML entities displayed correctly in vote results.');
}
}