class PollJSAddChoice

Test adding new choices.

Hierarchy

Expanded class hierarchy of PollJSAddChoice

File

modules/poll/poll.test, line 441

View source
class PollJSAddChoice extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Poll add choice',
      'description' => 'Submits a POST request for an additional poll choice.',
      'group' => 'Poll',
    );
  }
  function setUp() {
    parent::setUp('poll');
  }
  
  /**
   * Test adding a new choice.
   */
  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('More choices'),
    ));
    $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,
    )));
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.