JQueryColorpickerTest.php in Jquery Colorpicker 8.2
File
tests/src/Unit/Element/JQueryColorpickerTest.php
View source
<?php
namespace Drupal\Test\jquery_colorpicker\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\jquery_colorpicker\Element\JQueryColorpickerElement;
class JQueryColorpickerTest extends UnitTestCase {
public function testValueCallback($expected, $input) {
$element = [];
$form_state = $this
->prophesize(FormStateInterface::class)
->reveal();
$this
->assertSame($expected, JQueryColorpickerElement::valueCallback($element, $input, $form_state));
}
public function providerTestValueCallback() {
$data = [];
$data[] = [
NULL,
FALSE,
];
$data[] = [
NULL,
[
'test',
],
];
$test = new \stdClass();
$test->color = 'test';
$data[] = [
NULL,
$test,
];
$test->color = '123456';
$data[] = [
NULL,
$test,
];
$data[] = [
'#123456',
'#123456',
];
$data[] = [
NULL,
'1',
];
return $data;
}
public function testValidateElementEmpty() {
$element = [
'#value' => '',
];
$form_state = $this
->prophesize(FormStateInterface::class)
->reveal();
$this
->assertSame(NULL, JQueryColorpickerElement::validateElement($element, $form_state));
}
}