class DevelClientSideFilterTableTest in Devel 8.2
Same name and namespace in other branches
- 8.3 tests/src/Unit/DevelClientSideFilterTableTest.php \Drupal\Tests\devel\Unit\DevelClientSideFilterTableTest
- 4.x tests/src/Unit/DevelClientSideFilterTableTest.php \Drupal\Tests\devel\Unit\DevelClientSideFilterTableTest
Tests ClientSideFilterTable element.
@coversDefaultClass \Drupal\devel\Element\ClientSideFilterTable @group devel
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\devel\Unit\DevelClientSideFilterTableTest
Expanded class hierarchy of DevelClientSideFilterTableTest
File
- tests/
src/ Unit/ DevelClientSideFilterTableTest.php, line 14
Namespace
Drupal\Tests\devel\UnitView source
class DevelClientSideFilterTableTest extends UnitTestCase {
/**
* @covers ::getInfo
*/
public function testGetInfo() {
$translation = $this
->getStringTranslationStub();
$expected_info = [
'#filter_label' => $translation
->translate('Search'),
'#filter_placeholder' => $translation
->translate('Search'),
'#filter_description' => $translation
->translate('Search'),
'#header' => [],
'#rows' => [],
'#empty' => '',
'#sticky' => FALSE,
'#responsive' => TRUE,
'#attributes' => [],
'#pre_render' => [
[
ClientSideFilterTable::class,
'preRenderTable',
],
],
];
$table = new ClientSideFilterTable([], 'test', 'test');
$table
->setStringTranslation($translation);
$this
->assertEquals($expected_info, $table
->getInfo());
}
/**
* @covers ::preRenderTable
* @dataProvider providerPreRenderTable
*/
public function testPreRenderTable($element, $expected) {
$result = ClientSideFilterTable::preRenderTable($element);
$this
->assertEquals($expected, $result);
}
/**
* Data provider for preRenderHtmlTag test.
*/
public function providerPreRenderTable() {
$data = [];
$t = $this
->getStringTranslationStub();
$actual = [
'#type' => 'devel_table_filter',
'#filter_label' => $t
->translate('Label 1'),
'#filter_placeholder' => $t
->translate('Placeholder 1'),
'#filter_description' => $t
->translate('Description 1'),
'#header' => [],
'#rows' => [],
'#empty' => $t
->translate('Empty 1'),
'#responsive' => TRUE,
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'devel-a-list',
],
],
];
$expected = [];
$expected['#attached']['library'][] = 'devel/devel-table-filter';
$expected['filters'] = [
'#type' => 'container',
'#weight' => -1,
'#attributes' => [
'class' => [
'table-filter',
'js-show',
],
],
'name' => [
'#type' => 'search',
'#size' => 30,
'#title' => $t
->translate('Label 1'),
'#placeholder' => $t
->translate('Placeholder 1'),
'#attributes' => [
'class' => [
'table-filter-text',
],
'data-table' => ".js-devel-table-filter",
'autocomplete' => 'off',
'title' => $t
->translate('Description 1'),
],
],
];
$expected['table'] = [
'#type' => 'table',
'#header' => [],
'#rows' => [],
'#empty' => $t
->translate('Empty 1'),
'#responsive' => TRUE,
'#sticky' => TRUE,
'#attributes' => [
'class' => [
'devel-a-list',
'js-devel-table-filter',
'devel-table-filter',
],
],
];
$data[] = [
$actual,
$expected,
];
$headers = [
'Test1',
'Test2',
'Test3',
'Test4',
'Test5',
];
$actual = [
'#type' => 'devel_table_filter',
'#filter_label' => $t
->translate('Label 2'),
'#filter_placeholder' => $t
->translate('Placeholder 2'),
'#filter_description' => $t
->translate('Description 2'),
'#header' => $headers,
'#rows' => [
[
[
'data' => 'test1',
'filter' => TRUE,
],
[
'data' => 'test2',
'filter' => TRUE,
'class' => [
'test2',
],
],
[
'data' => 'test3',
'class' => [
'test3',
],
],
[
'test4',
],
[
'data' => 'test5',
'filter' => TRUE,
'class' => [
'devel-event-name-header',
],
'colspan' => '3',
'header' => TRUE,
],
],
],
'#empty' => $t
->translate('Empty 2'),
'#responsive' => FALSE,
'#sticky' => FALSE,
'#attributes' => [
'class' => [
'devel-some-list',
],
],
];
$expected = [];
$expected['#attached']['library'][] = 'devel/devel-table-filter';
$expected['filters'] = [
'#type' => 'container',
'#weight' => -1,
'#attributes' => [
'class' => [
'table-filter',
'js-show',
],
],
'name' => [
'#type' => 'search',
'#size' => 30,
'#title' => $t
->translate('Label 2'),
'#placeholder' => $t
->translate('Placeholder 2'),
'#attributes' => [
'class' => [
'table-filter-text',
],
'data-table' => ".js-devel-table-filter--2",
'autocomplete' => 'off',
'title' => $t
->translate('Description 2'),
],
],
];
$expected['table'] = [
'#type' => 'table',
'#header' => $headers,
'#rows' => [
[
[
'data' => 'test1',
'filter' => TRUE,
'class' => [
'table-filter-text-source',
],
],
[
'data' => 'test2',
'filter' => TRUE,
'class' => [
'test2',
'table-filter-text-source',
],
],
[
'data' => 'test3',
'class' => [
'test3',
],
],
[
'test4',
],
[
'data' => 'test5',
'filter' => TRUE,
'class' => [
'devel-event-name-header',
'table-filter-text-source',
],
'colspan' => '3',
'header' => TRUE,
],
],
],
'#empty' => $t
->translate('Empty 2'),
'#responsive' => FALSE,
'#sticky' => FALSE,
'#attributes' => [
'class' => [
'devel-some-list',
'js-devel-table-filter--2',
'devel-table-filter',
],
],
];
$data[] = [
$actual,
$expected,
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DevelClientSideFilterTableTest:: |
public | function | Data provider for preRenderHtmlTag test. | |
DevelClientSideFilterTableTest:: |
public | function | @covers ::getInfo | |
DevelClientSideFilterTableTest:: |
public | function | @covers ::preRenderTable @dataProvider providerPreRenderTable | |
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. | |
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. | |
UnitTestCase:: |
protected | function | 340 |