public function FilterEntityBundleTest::testFilterEntity in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/views/src/Tests/Entity/FilterEntityBundleTest.php \Drupal\views\Tests\Entity\FilterEntityBundleTest::testFilterEntity()
Tests the generic bundle filter.
File
- core/
modules/ views/ src/ Tests/ Entity/ FilterEntityBundleTest.php, line 74 - Contains \Drupal\views\Tests\Entity\FilterEntityBundleTest.
Class
- FilterEntityBundleTest
- Tests the generic entity bundle filter.
Namespace
Drupal\views\Tests\EntityCode
public function testFilterEntity() {
$view = Views::getView('test_entity_type_filter');
// Tests \Drupal\views\Plugin\views\filter\Bundle::calculateDependencies().
$expected = [
'config' => [
'node.type.test_bundle',
'node.type.test_bundle_2',
],
'module' => [
'node',
],
];
$this
->assertIdentical($expected, $view
->getDependencies());
$this
->executeView($view);
// Test we have all the results, with all types selected.
$this
->assertEqual(count($view->result), $this->entities['count']);
// Test the valueOptions of the filter handler.
$expected = array();
foreach ($this->entityBundles as $key => $info) {
$expected[$key] = $info['label'];
}
$this
->assertIdentical($view->filter['type']
->getValueOptions(), $expected);
$view
->destroy();
// Test each bundle type.
foreach ($this->entityBundles as $key => $info) {
// Test each bundle type.
$view
->initDisplay();
$filters = $view->display_handler
->getOption('filters');
$filters['type']['value'] = array(
$key => $key,
);
$view->display_handler
->setOption('filters', $filters);
$this
->executeView($view);
$this
->assertEqual(count($view->result), count($this->entities[$key]));
$view
->destroy();
}
// Test an invalid bundle type to make sure we have no results.
$view
->initDisplay();
$filters = $view->display_handler
->getOption('filters');
$filters['type']['value'] = array(
'type_3' => 'type_3',
);
$view->display_handler
->setOption('filters', $filters);
$this
->executeView($view);
$this
->assertEqual(count($view->result), 0);
}