X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=inline;f=web%2Fcore%2Fmodules%2Fsystem%2Ftests%2Fsrc%2FFunctional%2FForm%2FCheckboxTest.php;fp=web%2Fcore%2Fmodules%2Fsystem%2Fsrc%2FTests%2FForm%2FCheckboxTest.php;h=60fad6a2e811f9202040616576e1266463c8162e;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=61e7bd9ba5804cd3567a7408f1add70d09e8715d;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website diff --git a/web/core/modules/system/src/Tests/Form/CheckboxTest.php b/web/core/modules/system/tests/src/Functional/Form/CheckboxTest.php similarity index 75% rename from web/core/modules/system/src/Tests/Form/CheckboxTest.php rename to web/core/modules/system/tests/src/Functional/Form/CheckboxTest.php index 61e7bd9ba..60fad6a2e 100644 --- a/web/core/modules/system/src/Tests/Form/CheckboxTest.php +++ b/web/core/modules/system/tests/src/Functional/Form/CheckboxTest.php @@ -1,8 +1,8 @@ getValues() is populated correctly for a // checkboxes group that includes a 0-indexed array of options. - $results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', [], 'Save')); + $this->drupalPostForm('form-test/checkboxes-zero/1', [], 'Save'); + $results = json_decode($this->getSession()->getPage()->getContent()); $this->assertIdentical($results->checkbox_off, [0, 0, 0], 'All three in checkbox_off are zeroes: off.'); $this->assertIdentical($results->checkbox_zero_default, ['0', 0, 0], 'The first choice is on in checkbox_zero_default'); $this->assertIdentical($results->checkbox_string_zero_default, ['0', 0, 0], 'The first choice is on in checkbox_string_zero_default'); - $edit = ['checkbox_off[0]' => '0']; - $results = json_decode($this->drupalPostForm('form-test/checkboxes-zero/1', $edit, 'Save')); + // Due to Mink driver differences, we cannot submit an empty checkbox value + // to drupalPostForm(), even if that empty value is the 'true' value for + // the checkbox. + $this->drupalGet('form-test/checkboxes-zero/1'); + $this->assertSession()->fieldExists('checkbox_off[0]')->check(); + $this->drupalPostForm(NULL, NULL, 'Save'); + $results = json_decode($this->getSession()->getPage()->getContent()); $this->assertIdentical($results->checkbox_off, ['0', 0, 0], 'The first choice is on in checkbox_off but the rest is not'); // Ensure that each checkbox is rendered correctly for a checkboxes group @@ -70,18 +76,22 @@ class CheckboxTest extends WebTestBase { $this->assertIdentical(count($checkboxes), 9, 'Correct number of checkboxes found.'); foreach ($checkboxes as $checkbox) { - $checked = isset($checkbox['checked']); - $name = (string) $checkbox['name']; + $checked = $checkbox->isChecked(); + $name = $checkbox->getAttribute('name'); $this->assertIdentical($checked, $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name])); } - $edit = ['checkbox_off[0]' => '0']; - $this->drupalPostForm('form-test/checkboxes-zero/0', $edit, 'Save'); + // Due to Mink driver differences, we cannot submit an empty checkbox value + // to drupalPostForm(), even if that empty value is the 'true' value for + // the checkbox. + $this->drupalGet('form-test/checkboxes-zero/0'); + $this->assertSession()->fieldExists('checkbox_off[0]')->check(); + $this->drupalPostForm(NULL, NULL, 'Save'); $checkboxes = $this->xpath('//input[@type="checkbox"]'); $this->assertIdentical(count($checkboxes), 9, 'Correct number of checkboxes found.'); foreach ($checkboxes as $checkbox) { - $checked = isset($checkbox['checked']); - $name = (string) $checkbox['name']; + $checked = $checkbox->isChecked(); + $name = (string) $checkbox->getAttribute('name'); $this->assertIdentical($checked, $name == 'checkbox_off[0]' || $name == 'checkbox_zero_default[0]' || $name == 'checkbox_string_zero_default[0]', format_string('Checkbox %name correctly checked', ['%name' => $name])); } }