More updates to stop using dev or alpha or beta versions.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Utility / ColorTest.php
index e2f1629198fcb54b9ca2010682e0b5b844ed2d9b..10664ffc66df81122dcc1d8cc0a08b0b16f235f3 100644 (file)
@@ -3,14 +3,14 @@
 namespace Drupal\Tests\Component\Utility;
 
 use Drupal\Component\Utility\Color;
-use Drupal\Tests\UnitTestCase;
+use PHPUnit\Framework\TestCase;
 
 /**
  * Tests Color utility class conversions.
  *
  * @group Utility
  */
-class ColorTest extends UnitTestCase {
+class ColorTest extends TestCase {
 
   /**
    * Tests Color::hexToRgb().
@@ -26,7 +26,12 @@ class ColorTest extends UnitTestCase {
    */
   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));
   }
@@ -118,4 +123,42 @@ class ColorTest extends UnitTestCase {
     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));
+  }
+
 }