$results =
json_decode($this->
getSession()->
getPage()->
getContent());
$this->
assertSame(['0', 0, 0
],
$results->checkbox_off, 'The first choice is on in checkbox_off but the rest is not'
);
// Ensure that each checkbox is rendered correctly for a checkboxes group
// that includes a 0-indexed array of options.
$this->
drupalGet('form-test/checkboxes-zero/0'
);
$this->
submitForm([], 'Save'
);
$checkboxes =
$this->
xpath('//input[@type="checkbox"]'
);
$this->
assertCount(9,
$checkboxes, 'Correct number of checkboxes found.'
);
foreach ($checkboxes as $checkbox) { $checked =
$checkbox->
isChecked();
$name =
$checkbox->
getAttribute('name'
);
$this->
assertSame($checked,
$name == 'checkbox_zero_default[0]' ||
$name == 'checkbox_string_zero_default[0]',
new FormattableMarkup('Checkbox %name correctly checked',
['%name' =>
$name]));
} // Due to Mink driver differences, we cannot submit an empty checkbox value
// to submitForm(), 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->
submitForm([], 'Save'
);
$checkboxes =
$this->
xpath('//input[@type="checkbox"]'
);