class JQueryColorpickerServiceTest in Jquery Colorpicker 8
Same name and namespace in other branches
- 8.2 tests/src/Unit/Service/jQueryColorpickerServiceTest.php \Drupal\Test\jquery_colorpicker\Service\JQueryColorpickerServiceTest
@coversDefaultClass \Drupal\jquery_colorpicker\Service\JQueryColorpickerService @group jquery_colorpicker
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait- class \Drupal\Test\jquery_colorpicker\Service\JQueryColorpickerServiceTest uses StringTranslationTrait
 
Expanded class hierarchy of JQueryColorpickerServiceTest
File
- tests/src/ Unit/ Service/ jQueryColorpickerServiceTest.php, line 14 
Namespace
Drupal\Test\jquery_colorpicker\ServiceView source
class JQueryColorpickerServiceTest extends UnitTestCase {
  use StringTranslationTrait;
  /**
   * The JQuery Colorpicker Service.
   *
   * @var \Drupal\jquery_colorpicker\Service\JQueryColorpickerService
   */
  protected $JQueryColorpickerService;
  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $container = new ContainerBuilder();
    $container
      ->set('string_translation', $this
      ->getStringTranslationStub());
    \Drupal::setContainer($container);
    $this->JQueryColorpickerService = new JQueryColorpickerService();
  }
  /**
   * @covers ::formatColor
   *
   * @dataProvider providerTestFormatColor
   */
  public function testFormatColor($expected, $color) {
    $this
      ->assertSame($expected, $this->JQueryColorpickerService
      ->formatColor($color));
  }
  /**
   * Provides data for the testFormatColor test.
   */
  public function providerTestFormatcolor() {
    $data = [];
    $data[] = [
      '',
      NULL,
    ];
    $data[] = [
      '',
      '',
    ];
    $data[] = [
      "1",
      TRUE,
    ];
    $data[] = [
      "",
      FALSE,
    ];
    $data[] = [
      "123",
      123,
    ];
    $data[] = [
      "1.23",
      1.23,
    ];
    $data[] = [
      "123456",
      "123456",
    ];
    $data[] = [
      "123456",
      "#123456",
    ];
    $data[] = [
      "",
      [],
    ];
    $test_class = new \stdClass();
    $data[] = [
      "",
      $test_class,
    ];
    return $data;
  }
  /**
   * @covers ::validateColor
   *
   * @dataProvider providerTestValidateColor
   */
  public function testValidateColor($expected, $color) {
    $this
      ->assertEquals($expected, $this->JQueryColorpickerService
      ->validateColor($color));
  }
  /**
   * Provides data for the testValidateColor test.
   */
  public function providerTestValidateColor() {
    $container = new ContainerBuilder();
    $container
      ->set('string_translation', $this
      ->getStringTranslationStub());
    \Drupal::setContainer($container);
    $type_error = $this
      ->t('Color must be a string or an integer');
    $length_error = $this
      ->t('Color values must be exactly six characters in length');
    $hex_error = $this
      ->t("You entered an invalid value for the color. Colors must be hexadecimal, and can only contain the characters '0-9', 'a-f' and/or 'A-F'.");
    $data = [];
    $data[] = [
      $type_error,
      TRUE,
    ];
    $data[] = [
      $type_error,
      FALSE,
    ];
    $data[] = [
      $type_error,
      [],
    ];
    $test = new \stdClass();
    $data[] = [
      $type_error,
      $test,
    ];
    $data[] = [
      $type_error,
      1.23,
    ];
    $data[] = [
      $length_error,
      12345,
    ];
    $data[] = [
      $length_error,
      "12345",
    ];
    $data[] = [
      $hex_error,
      "11111g",
    ];
    $data[] = [
      $hex_error,
      "11111G",
    ];
    $data[] = [
      $hex_error,
      "fffffg",
    ];
    $data[] = [
      $hex_error,
      "fffffG",
    ];
    $data[] = [
      $hex_error,
      "FFFFFg",
    ];
    $data[] = [
      $hex_error,
      "FFFFFG",
    ];
    // Valid submissions.
    $data[] = [
      FALSE,
      123456,
    ];
    $data[] = [
      FALSE,
      "123456",
    ];
    $data[] = [
      FALSE,
      "11111f",
    ];
    $data[] = [
      FALSE,
      "11111F",
    ];
    $data[] = [
      FALSE,
      "FFFFF1",
    ];
    $data[] = [
      FALSE,
      "fffff1",
    ];
    return $data;
  }
}Members
| Name   | Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| JQueryColorpickerServiceTest:: | protected | property | The JQuery Colorpicker Service. | |
| JQueryColorpickerServiceTest:: | public | function | Provides data for the testFormatColor test. | |
| JQueryColorpickerServiceTest:: | public | function | Provides data for the testValidateColor test. | |
| JQueryColorpickerServiceTest:: | public | function | Overrides UnitTestCase:: | |
| JQueryColorpickerServiceTest:: | public | function | @covers ::formatColor | |
| JQueryColorpickerServiceTest:: | public | function | @covers ::validateColor | |
| PhpunitCompatibilityTrait:: | public | function | Returns a mock object for the specified class using the available method. | |
| PhpunitCompatibilityTrait:: | public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
| StringTranslationTrait:: | protected | property | The string translation service. | 1 | 
| StringTranslationTrait:: | protected | function | Formats a string containing a count of items. | |
| StringTranslationTrait:: | protected | function | Returns the number of plurals supported by a given language. | |
| StringTranslationTrait:: | protected | function | Gets the string translation service. | |
| StringTranslationTrait:: | public | function | Sets the string translation service to use. | 2 | 
| StringTranslationTrait:: | protected | function | Translates a string to the current language or to a given language. | |
| UnitTestCase:: | protected | property | The random generator. | |
| UnitTestCase:: | protected | property | The app root. | 1 | 
| UnitTestCase:: | protected | function | Asserts if two arrays are equal by sorting them first. | |
| UnitTestCase:: | protected | function | Mocks a block with a block plugin. | 1 | 
| UnitTestCase:: | protected | function | Returns a stub class resolver. | |
| UnitTestCase:: | public | function | Returns a stub config factory that behaves according to the passed array. | |
| UnitTestCase:: | public | function | Returns a stub config storage that returns the supplied configuration. | |
| UnitTestCase:: | protected | function | Sets up a container with a cache tags invalidator. | |
| UnitTestCase:: | protected | function | Gets the random generator for the utility methods. | |
| UnitTestCase:: | public | function | Returns a stub translation manager that just returns the passed string. | |
| UnitTestCase:: | public | function | Generates a unique random string containing letters and numbers. | 
