function AreaEntityTest::testEntityAreaData

Same name in other branches
  1. 9 core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php \Drupal\Tests\views\Kernel\Handler\AreaEntityTest::testEntityAreaData()
  2. 8.9.x core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php \Drupal\Tests\views\Kernel\Handler\AreaEntityTest::testEntityAreaData()
  3. 10 core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php \Drupal\Tests\views\Kernel\Handler\AreaEntityTest::testEntityAreaData()

Tests views data for entity area handlers.

File

core/modules/views/tests/src/Kernel/Handler/AreaEntityTest.php, line 63

Class

AreaEntityTest
Tests the generic entity area handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testEntityAreaData() : void {
    $data = $this->container
        ->get('views.views_data')
        ->get('views');
    $entity_types = $this->container
        ->get('entity_type.manager')
        ->getDefinitions();
    $expected_entities = array_filter($entity_types, function (EntityTypeInterface $entity_type) {
        return $entity_type->hasViewBuilderClass();
    });
    // Test that all expected entity types have data.
    foreach (array_keys($expected_entities) as $entity) {
        $this->assertNotEmpty($data['entity_' . $entity], "Views entity '{$entity}' should have a data area.");
        // Test that entity_type is set correctly in the area data.
        $this->assertEquals($data['entity_' . $entity]['area']['entity_type'], $entity, "Correct entity_type set for {$entity}");
    }
    $expected_entities = array_filter($entity_types, function (EntityTypeInterface $type) {
        return !$type->hasViewBuilderClass();
    });
    // Test that no configuration entity types have data.
    foreach (array_keys($expected_entities) as $entity) {
        $this->assertArrayNotHasKey('entity_' . $entity, $data, "Views config entity '{$entity}' should not have a data area.");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.