function PollJsAddChoiceTest::testAddChoice

Tests adding a new choice to a poll.

File

drupal/core/modules/poll/lib/Drupal/poll/Tests/PollJsAddChoiceTest.php, line 35
Definition of Drupal\poll\Tests\PollJsAddChoiceTest.

Class

PollJsAddChoiceTest
Tests adding new choices to a poll.

Namespace

Drupal\poll\Tests

Code

function testAddChoice() {
  $web_user = $this
    ->drupalCreateUser(array(
    'create poll content',
    'access content',
  ));
  $this
    ->drupalLogin($web_user);
  $this
    ->drupalGet('node/add/poll');
  $edit = array(
    "title" => $this
      ->randomName(),
    'choice[new:0][chtext]' => $this
      ->randomName(),
    'choice[new:1][chtext]' => $this
      ->randomName(),
  );

  // Press 'add choice' button through Ajax, and place the expected HTML result
  // as the tested content.
  $commands = $this
    ->drupalPostAJAX(NULL, $edit, array(
    'op' => t('Add another choice'),
  ));
  $this->content = $commands[1]['data'];
  $this
    ->assertFieldByName('choice[chid:0][chtext]', $edit['choice[new:0][chtext]'], format_string('Field !i found', array(
    '!i' => 0,
  )));
  $this
    ->assertFieldByName('choice[chid:1][chtext]', $edit['choice[new:1][chtext]'], format_string('Field !i found', array(
    '!i' => 1,
  )));
  $this
    ->assertFieldByName('choice[new:0][chtext]', '', format_string('Field !i found', array(
    '!i' => 2,
  )));
}