Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Utility / ColorTest.php
index cbb9d7e8eb91d3e7fd46d74cf2c208bcbf2c0870..02a4ed5f15b14d86f203afef9eb3979f87b60f8e 100644 (file)
@@ -26,7 +26,12 @@ class ColorTest extends TestCase {
    */
   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));
   }
@@ -56,7 +61,7 @@ class ColorTest extends TestCase {
     // 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];
     }
@@ -118,4 +123,42 @@ class ColorTest extends TestCase {
     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));
+  }
+
 }