function DrupalWebTestCase::assertOptionSelected

Asserts that a select option in the current page is checked.

@todo $id is unusable. Replace with $name.

Parameters

$id: ID of select field to assert.

$option: Option to assert.

$message: (optional) Message to display.

Return value

TRUE on pass, FALSE on fail.

6 calls to DrupalWebTestCase::assertOptionSelected()
DateFormatTestCase::testDefaultDateFormats in modules/system/system.test
Test the default date type formats are consistent.
FormsTestCase::testRequiredCheckboxesRadio in modules/simpletest/tests/form.test
Tests validation for required checkbox, select, and radio elements.
MenuNodeTestCase::testMenuNodeFormWidget in modules/menu/menu.test
Test creating, editing, deleting menu links via node form widget.
MenuUpgradePathTestCase::testMenuUpgrade in modules/simpletest/tests/upgrade/upgrade.menu.test
Test a successful upgrade.
OptionsWidgetsTestCase::testSelectListMultiple in modules/field/modules/options/options.test
Tests the 'options_select' widget (multiple select).

... See full list

File

modules/simpletest/drupal_web_test_case.php, line 3829

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function assertOptionSelected($id, $option, $message = '') {
    $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', array(
        ':id' => $id,
        ':option' => $option,
    ));
    return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['selected']), $message ? $message : t('Option @option for field @id is selected.', array(
        '@option' => $option,
        '@id' => $id,
    )), t('Browser'));
}

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