Unverified Commit c0f3934c authored by larowlan's avatar larowlan

Issue #3041778 by mikelutz, claudiu.cristea, alexpott: Convert...

Issue #3041778 by mikelutz, claudiu.cristea, alexpott: Convert FilterEntityBundleTest into a kernel test
parent 81d8e2a7
...@@ -110,7 +110,7 @@ public function getValueOptions() { ...@@ -110,7 +110,7 @@ public function getValueOptions() {
$options[$type] = $info['label']; $options[$type] = $info['label'];
} }
asort($options); array_multisort($options, SORT_ASC, SORT_REGULAR, array_keys($options));
$this->valueOptions = $options; $this->valueOptions = $options;
} }
......
<?php <?php
namespace Drupal\Tests\views\Functional\Entity; namespace Drupal\Tests\views\Kernel\Entity;
use Drupal\node\Entity\Node; use Drupal\node\Entity\Node;
use Drupal\Tests\views\Functional\ViewTestBase; use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestData; use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views; use Drupal\views\Views;
/** /**
...@@ -12,49 +12,32 @@ ...@@ -12,49 +12,32 @@
* *
* @group views * @group views
*/ */
class FilterEntityBundleTest extends ViewTestBase { class FilterEntityBundleTest extends ViewsKernelTestBase {
/** /**
* Views used by this test. * {@inheritdoc}
*
* @var array
*/ */
public static $testViews = ['test_entity_type_filter']; public static $testViews = ['test_entity_type_filter'];
/** /**
* Modules to enable. * {@inheritdoc}
*
* @var array
*/ */
public static $modules = ['node']; public static $modules = ['node'];
/** /**
* Entity bundle data. * Tests the generic bundle filter.
*
* @var array
*/
protected $entityBundles;
/**
* An array of entities.
*
* @var array
*/ */
protected $entities = []; public function testFilterEntity() {
$this->installEntitySchema('user');
protected function setUp($import_test_views = TRUE) { $this->installEntitySchema('node');
parent::setUp(FALSE); NodeType::create(['type' => 'test_bundle'])->save();
NodeType::create(['type' => 'test_bundle_2'])->save();
$this->drupalCreateContentType(['type' => 'test_bundle']);
$this->drupalCreateContentType(['type' => 'test_bundle_2']);
ViewTestData::createTestViews(get_class($this), ['views_test_config']);
$this->entityBundles = $this->container->get('entity_type.bundle.info')->getBundleInfo('node'); $bundle_info = $this->container->get('entity_type.bundle.info')->getBundleInfo('node');
$this->entities['count'] = 0; $entities['count'] = 0;
foreach ($this->entityBundles as $key => $info) { foreach ($bundle_info as $key => $info) {
for ($i = 0; $i < 5; $i++) { for ($i = 0; $i < 5; $i++) {
$entity = Node::create([ $entity = Node::create([
'title' => $this->randomString(), 'title' => $this->randomString(),
...@@ -62,16 +45,10 @@ protected function setUp($import_test_views = TRUE) { ...@@ -62,16 +45,10 @@ protected function setUp($import_test_views = TRUE) {
'type' => $key, 'type' => $key,
]); ]);
$entity->save(); $entity->save();
$this->entities[$key][$entity->id()] = $entity; $entities[$key][$entity->id()] = $entity;
$this->entities['count']++; $entities['count']++;
} }
} }
}
/**
* Tests the generic bundle filter.
*/
public function testFilterEntity() {
$view = Views::getView('test_entity_type_filter'); $view = Views::getView('test_entity_type_filter');
// Tests \Drupal\views\Plugin\views\filter\Bundle::calculateDependencies(). // Tests \Drupal\views\Plugin\views\filter\Bundle::calculateDependencies().
...@@ -84,25 +61,24 @@ public function testFilterEntity() { ...@@ -84,25 +61,24 @@ public function testFilterEntity() {
'node', 'node',
], ],
]; ];
$this->assertIdentical($expected, $view->getDependencies()); $this->assertSame($expected, $view->getDependencies());
$this->executeView($view); $this->executeView($view);
// Test we have all the results, with all types selected. // Test we have all the results, with all types selected.
$this->assertEqual(count($view->result), $this->entities['count']); $this->assertCount($entities['count'], $view->result);
// Test the valueOptions of the filter handler. // Test the valueOptions of the filter handler.
$expected = []; $expected = [];
foreach ($bundle_info as $key => $info) {
foreach ($this->entityBundles as $key => $info) {
$expected[$key] = $info['label']; $expected[$key] = $info['label'];
} }
$this->assertIdentical($view->filter['type']->getValueOptions(), $expected); $this->assertSame($expected, $view->filter['type']->getValueOptions());
$view->destroy(); $view->destroy();
// Test each bundle type. // Test each bundle type.
foreach ($this->entityBundles as $key => $info) { foreach ($bundle_info as $key => $info) {
// Test each bundle type. // Test each bundle type.
$view->initDisplay(); $view->initDisplay();
$filters = $view->display_handler->getOption('filters'); $filters = $view->display_handler->getOption('filters');
...@@ -110,7 +86,7 @@ public function testFilterEntity() { ...@@ -110,7 +86,7 @@ public function testFilterEntity() {
$view->display_handler->setOption('filters', $filters); $view->display_handler->setOption('filters', $filters);
$this->executeView($view); $this->executeView($view);
$this->assertEqual(count($view->result), count($this->entities[$key])); $this->assertCount(count($entities[$key]), $view->result);
$view->destroy(); $view->destroy();
} }
...@@ -122,7 +98,7 @@ public function testFilterEntity() { ...@@ -122,7 +98,7 @@ public function testFilterEntity() {
$view->display_handler->setOption('filters', $filters); $view->display_handler->setOption('filters', $filters);
$this->executeView($view); $this->executeView($view);
$this->assertEqual(count($view->result), 0); $this->assertEmpty($view->result);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment