From e7382618b55bc7c9e9b6c581c95c5763460adb9b Mon Sep 17 00:00:00 2001 From: babruix Date: Thu, 14 Mar 2013 15:37:11 +0100 Subject: [PATCH] Issue #1381140 by sun: Fixed #default_value = 0 for #type radios checks all radios. --- .../lib/Drupal/simpletest/WebTestBase.php | 3 ++- .../lib/Drupal/system/Tests/Form/ElementTest.php | 6 ++++++ .../tests/modules/form_test/form_test.module | 24 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 9e8b097..5ffa1f4 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -2797,7 +2797,8 @@ protected function assertNoFieldById($id, $value = '', $message = '', $group = ' */ protected function assertFieldChecked($id, $message = '', $group = 'Browser') { $elements = $this->xpath('//input[@id=:id]', array(':id' => $id)); - return $this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), $message ? $message : t('Checkbox field @id is checked.', array('@id' => $id)), $group); + $element_to_check = isset($elements[0]['@attributes']) ? $elements[0]['@attributes'] : $elements[0]; + return $this->assertTrue(isset($elements[0]) && !empty($element_to_check['checked']), $message ? $message : t('Checkbox field @id is checked.', array('@id' => $id)), $group); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ElementTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ElementTest.php index e3521cc..df3a469 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/ElementTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ElementTest.php @@ -91,6 +91,12 @@ function testOptions() { '%type' => $type, ))); } + + // Additionally verify that there is only one radio option checked. + $this->drupalGet('form-test/radios-default-value-checks-all'); + $elements = $this->xpath('//input[@type=:type and @checked="checked"]', array(':type' => 'radio')); + $this->assertEqual(count($elements), 1); + $this->assertIdentical((string) $elements[0]['value'], '0'); } /** diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index c7a85a3..6244c7b 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -204,6 +204,12 @@ function form_test_menu() { 'page arguments' => array('form_test_checkboxes_radios'), 'access callback' => TRUE, ); + $items['form-test/radios-default-value-checks-all'] = array( + 'title' => 'Radios default_value Checks All', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('form_test_radios_default_value_checks_all'), + 'access callback' => TRUE, + ); $items['form-test/email'] = array( 'title' => 'E-Mail fields', 'page callback' => 'drupal_get_form', @@ -1632,6 +1638,24 @@ function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) { return $form; } +/** + * Form constructor for testing whether settings a '#default_value' => 0 in + * a set of radio button #options using string keys checks all options. + * @ingroup forms + */ +function form_test_radios_default_value_checks_all($form, &$form_state){ + $form['radios'] = array( + '#type' => 'radios', + '#options' => array( + 0 => '- None -', + 'one' => 'one', + 'two' => 'two', + 'three' => 'three', + ), + '#default_value' => 0, + ); + return $form; +} /** * Form constructor for testing #type 'email' elements. -- 1.7.12.4 (Apple Git-37)