You are here

public function AreaEntityTest::testEntityAreaData in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Handler/AreaEntityTest.php \Drupal\views\Tests\Handler\AreaEntityTest::testEntityAreaData()

Tests views data for entity area handlers.

File

core/modules/views/src/Tests/Handler/AreaEntityTest.php, line 65
Contains \Drupal\views\Tests\Handler\AreaEntityTest.

Class

AreaEntityTest
Tests the generic entity area handler.

Namespace

Drupal\views\Tests\Handler

Code

public function testEntityAreaData() {
  $data = $this->container
    ->get('views.views_data')
    ->get('views');
  $entity_types = $this->container
    ->get('entity.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
      ->assertTrue(!empty($data['entity_' . $entity]), format_string('Views entity area data found for @entity', array(
      '@entity' => $entity,
    )));

    // Test that entity_type is set correctly in the area data.
    $this
      ->assertEqual($entity, $data['entity_' . $entity]['area']['entity_type'], format_string('Correct entity_type set for @entity', array(
      '@entity' => $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
      ->assertTrue(empty($data['entity_' . $entity]), format_string('Views config entity area data not found for @entity', array(
      '@entity' => $entity,
    )));
  }
}