public function LinksWidgetTest::testHideNumbers in Facets 8
Tests widget, make sure hiding and showing numbers works.
File
- tests/
src/ Unit/ Plugin/ widget/ LinksWidgetTest.php, line 99
Class
- LinksWidgetTest
- Unit test for widget.
Namespace
Drupal\Tests\facets\Unit\Plugin\widgetCode
public function testHideNumbers() {
$original_results = $this->originalResults;
$original_results[1]
->setActiveState(TRUE);
$facet = $this->facet;
$facet
->setResults($original_results);
$this->widget
->setConfiguration([
'show_numbers' => FALSE,
]);
$output = $this->widget
->build($facet);
$this
->assertSame('array', gettype($output));
$this
->assertCount(4, $output['#items']);
$expected_links = [
$this
->buildLinkAssertion('Llama', 'llama', $facet, 10, FALSE, FALSE),
$this
->buildLinkAssertion('Badger', 'badger', $facet, 20, TRUE, FALSE),
$this
->buildLinkAssertion('Duck', 'duck', $facet, 15, FALSE, FALSE),
$this
->buildLinkAssertion('Alpaca', 'alpaca', $facet, 9, FALSE, FALSE),
];
foreach ($expected_links as $index => $value) {
$this
->assertSame('array', gettype($output['#items'][$index]));
$this
->assertEquals($value, $output['#items'][$index]['#title']);
$this
->assertEquals('link', $output['#items'][$index]['#type']);
if ($index === 1) {
$this
->assertEquals([
'is-active',
], $output['#items'][$index]['#attributes']['class']);
}
$this
->assertEquals([
'facet-item',
], $output['#items'][$index]['#wrapper_attributes']['class']);
}
// Enable the 'show_numbers' setting again to make sure that the switch
// between those settings works.
$this->widget
->setConfiguration([
'show_numbers' => TRUE,
]);
$output = $this->widget
->build($facet);
$this
->assertSame('array', gettype($output));
$this
->assertCount(4, $output['#items']);
$expected_links = [
$this
->buildLinkAssertion('Llama', 'llama', $facet, 10),
$this
->buildLinkAssertion('Badger', 'badger', $facet, 20, TRUE),
$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
->assertEquals('link', $output['#items'][$index]['#type']);
if ($index === 1) {
$this
->assertEquals([
'is-active',
], $output['#items'][$index]['#attributes']['class']);
}
$this
->assertEquals([
'facet-item',
], $output['#items'][$index]['#wrapper_attributes']['class']);
}
}