*/
public function testHexToRgb($value, $expected, $invalid = FALSE) {
if ($invalid) {
- $this->setExpectedException('InvalidArgumentException');
+ if (method_exists($this, 'expectException')) {
+ $this->expectException('InvalidArgumentException');
+ }
+ else {
+ $this->setExpectedException('InvalidArgumentException');
+ }
}
$this->assertSame($expected, Color::hexToRgb($value));
}
// Add invalid data types (hex value must be a string).
foreach ([
1, 12, 1234, 12345, 123456, 1234567, 12345678, 123456789, 123456789,
- -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, 0x0, 0x010
+ -1, PHP_INT_MAX, PHP_INT_MAX + 1, -PHP_INT_MAX, 0x0, 0x010,
] as $value) {
$invalid[] = [$value, '', TRUE];
}
return $tests;
}
+ /**
+ * Data provider for testNormalizeHexLength().
+ *
+ * @see testNormalizeHexLength()
+ *
+ * @return array
+ * An array of arrays containing:
+ * - The hex color value.
+ * - The 6 character length hex color value.
+ */
+ public function providerTestNormalizeHexLength() {
+ $data = [
+ ['#000', '#000000'],
+ ['#FFF', '#FFFFFF'],
+ ['#abc', '#aabbcc'],
+ ['cba', '#ccbbaa'],
+ ['#000000', '#000000'],
+ ['ffffff', '#ffffff'],
+ ['#010203', '#010203'],
+ ];
+
+ return $data;
+ }
+
+ /**
+ * Tests Color::normalizeHexLength().
+ *
+ * @param string $value
+ * The input hex color value.
+ * @param string $expected
+ * The expected normalized hex color value.
+ *
+ * @dataProvider providerTestNormalizeHexLength
+ */
+ public function testNormalizeHexLength($value, $expected) {
+ $this->assertSame($expected, Color::normalizeHexLength($value));
+ }
+
}