class CheckboxWidgetTest in Facets 8
Unit test for widget.
@group facets
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase
- class \Drupal\Tests\facets\Unit\Plugin\widget\CheckboxWidgetTest
- class \Drupal\Tests\facets\Unit\Plugin\widget\WidgetTestBase
Expanded class hierarchy of CheckboxWidgetTest
File
- tests/
src/ Unit/ Plugin/ widget/ CheckboxWidgetTest.php, line 12
Namespace
Drupal\Tests\facets\Unit\Plugin\widgetView source
class CheckboxWidgetTest extends WidgetTestBase {
/**
* Creates a new processor object for use in the tests.
*/
protected function setUp() {
parent::setUp();
$this->widget = new CheckboxWidget([
'show_numbers' => TRUE,
], 'checkbox_widget', []);
}
/**
* Tests widget without filters.
*/
public function testNoFilterResults() {
$facet = $this->facet;
$facet
->setResults($this->originalResults);
$output = $this->widget
->build($facet);
$this
->assertSame('array', gettype($output));
$this
->assertCount(4, $output['#items']);
$this
->assertEquals([
'facet-inactive',
'js-facets-checkbox-links',
], $output['#attributes']['class']);
$expected_links = [
$this
->buildLinkAssertion('Llama', 'llama', $facet, 10),
$this
->buildLinkAssertion('Badger', 'badger', $facet, 20),
$this
->buildLinkAssertion('Duck', 'duck', $facet, 15),
$this
->buildLinkAssertion('Alpaca', 'alpaca', $facet, 9),
];
foreach ($expected_links as $index => $value) {
$this
->assertSame('array', gettype($output['#items'][$index]));
$this
->assertEquals($value, $output['#items'][$index]['#title']);
$this
->assertSame('array', gettype($output['#items'][$index]['#title']));
$this
->assertEquals('link', $output['#items'][$index]['#type']);
$this
->assertEquals([
'facet-item',
], $output['#items'][$index]['#wrapper_attributes']['class']);
}
}
/**
* {@inheritdoc}
*/
public function testDefaultConfiguration() {
$default_config = $this->widget
->defaultConfiguration();
$this
->assertArrayHasKey('show_numbers', $default_config);
$this
->assertArrayHasKey('soft_limit', $default_config);
$this
->assertArrayHasKey('show_reset_link', $default_config);
$this
->assertArrayHasKey('reset_text', $default_config);
$this
->assertArrayHasKey('soft_limit_settings', $default_config);
$this
->assertArrayHasKey('show_less_label', $default_config['soft_limit_settings']);
$this
->assertArrayHasKey('show_more_label', $default_config['soft_limit_settings']);
$this
->assertEquals(FALSE, $default_config['show_numbers']);
$this
->assertEquals(0, $default_config['soft_limit']);
$this
->assertEquals(FALSE, $default_config['show_reset_link']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CheckboxWidgetTest:: |
protected | function |
Creates a new processor object for use in the tests. Overrides WidgetTestBase:: |
|
CheckboxWidgetTest:: |
public | function |
Tests default configuration. Overrides WidgetTestBase:: |
|
CheckboxWidgetTest:: |
public | function | Tests widget without filters. | |
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. | |
WidgetTestBase:: |
protected | property | The facet used for the widget test. | |
WidgetTestBase:: |
protected | property | An array containing the results for the widget. | |
WidgetTestBase:: |
protected | property | An array of possible query types. | |
WidgetTestBase:: |
protected | property | The widget to be tested. | |
WidgetTestBase:: |
protected | function | Build a formattable markup object to use as assertion. | |
WidgetTestBase:: |
public | function | Tests get query type. | 1 |
WidgetTestBase:: |
public | function | Tests default for required properties. | 1 |