1 form.test | FormsTestCase::testColorValidation() |
Tests validation of #type 'color' elements.
File
- core/
modules/ simpletest/ tests/ form.test, line 344 - Unit tests for the Backdrop Form API.
Class
Code
function testColorValidation() {
// Keys are inputs, values are expected results.
$values = array(
'' => '#000000',
'#000' => '#000000',
'AAA' => '#aaaaaa',
'#af0DEE' => '#af0dee',
'#99ccBc' => '#99ccbc',
'#aabbcc' => '#aabbcc',
'123456' => '#123456',
);
// Tests that valid values are properly normalized.
foreach ($values as $input => $expected) {
$edit = array(
'color' => $input,
);
$result = json_decode($this->backdropPost('form-test/color', $edit, 'Submit'));
$this->assertEqual($result->color, $expected);
}
// Tests invalid values are rejected.
$values = array('#0008', '#1234', '#fffffg', '#abcdef22', '17', '#uaa');
foreach ($values as $input) {
$edit = array(
'color' => $input,
);
$this->backdropPost('form-test/color', $edit, 'Submit');
$this->assertRaw(t('%name must be a valid color.', array('%name' => 'Color')));
}
}