View source
<?php
namespace Drupal\Test\jquery_colorpicker\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Tests\UnitTestCase;
use Drupal\jquery_colorpicker\Element\JQueryColorpicker;
class JQueryColorpickerTest extends UnitTestCase {
public function testValueCallback($expected, $input) {
$element = [];
$form_state = $this
->prophesize(FormStateInterface::class)
->reveal();
$this
->assertSame($expected, JQueryColorpicker::valueCallback($element, $input, $form_state));
}
public function providerTestValueCallback() {
$data = [];
$data[] = [
NULL,
FALSE,
];
$data[] = [
NULL,
NULL,
];
$data[] = [
'',
[
'test',
],
];
$test = new \stdClass();
$test->value = 'test';
$data[] = [
'',
$test,
];
$data[] = [
"123",
123,
];
$data[] = [
"1.23",
1.23,
];
$data[] = [
"123",
"123",
];
$data[] = [
"1",
TRUE,
];
return $data;
}
public function testValidateElementEmpty() {
$element = [
'#value' => '',
];
$form_state = $this
->prophesize(FormStateInterface::class)
->reveal();
$this
->assertSame(NULL, JQueryColorpicker::validateElement($element, $form_state));
}
}