function ColorTest::providerTestRbgToHex

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Utility/ColorTest.php \Drupal\Tests\Component\Utility\ColorTest::providerTestRbgToHex()
  2. 10 core/tests/Drupal/Tests/Component/Utility/ColorTest.php \Drupal\Tests\Component\Utility\ColorTest::providerTestRbgToHex()
  3. 11.x core/tests/Drupal/Tests/Component/Utility/ColorTest.php \Drupal\Tests\Component\Utility\ColorTest::providerTestRbgToHex()

Data provider for testRgbToHex().

Return value

array An array of arrays containing:

  • The rgb color array value.
  • The hex color value.

See also

testRgbToHex()

File

core/tests/Drupal/Tests/Component/Utility/ColorTest.php, line 156

Class

ColorTest
Tests Color utility class conversions.

Namespace

Drupal\Tests\Component\Utility

Code

public function providerTestRbgToHex() {
    // Input using named RGB array (e.g., as returned by Color::hexToRgb()).
    $tests = [
        [
            [
                'red' => 0,
                'green' => 0,
                'blue' => 0,
            ],
            '#000000',
        ],
        [
            [
                'red' => 255,
                'green' => 255,
                'blue' => 255,
            ],
            '#ffffff',
        ],
        [
            [
                'red' => 119,
                'green' => 119,
                'blue' => 119,
            ],
            '#777777',
        ],
        [
            [
                'red' => 1,
                'green' => 2,
                'blue' => 3,
            ],
            '#010203',
        ],
    ];
    // Input using indexed RGB array (e.g.: array(10, 10, 10)).
    foreach ($tests as $test) {
        $tests[] = [
            array_values($test[0]),
            $test[1],
        ];
    }
    // Input using CSS RGB string notation (e.g.: 10, 10, 10).
    foreach ($tests as $test) {
        $tests[] = [
            implode(', ', $test[0]),
            $test[1],
        ];
    }
    return $tests;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.