You are here

public function EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName()
  2. 10 core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName()

Tests views data generated for relationship.

See also

entity_reference_field_views_data()

File

core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php, line 252

Class

EntityReferenceRelationshipTest
Tests entity reference relationship data.

Namespace

Drupal\Tests\field\Kernel\EntityReference\Views

Code

public function testDataTableRelationshipWithLongFieldName() {

  // Create some test entities which link each other.
  $referenced_entity = EntityTest::create();
  $referenced_entity
    ->save();
  $entity = EntityTestMulChanged::create();
  $entity->field_test_data_with_a_long_name->target_id = $referenced_entity
    ->id();
  $entity
    ->save();
  $this->entities[] = $entity;
  $entity = EntityTestMulChanged::create();
  $entity->field_test_data_with_a_long_name->target_id = $referenced_entity
    ->id();
  $entity
    ->save();
  $this->entities[] = $entity;
  Views::viewsData()
    ->clear();

  // Check an actual test view.
  $view = Views::getView('test_entity_reference_entity_test_view_long');
  $this
    ->executeView($view);

  /** @var \Drupal\views\ResultRow $row */
  foreach ($view->result as $index => $row) {

    // Check that the actual ID of the entity is the expected one.
    $this
      ->assertEqual($row->id, $this->entities[$index]
      ->id());

    // Also check that we have the correct result entity.
    $this
      ->assertEqual($row->_entity
      ->id(), $this->entities[$index]
      ->id());

    // Test the forward relationship.
    // $this->assertEqual($row->entity_test_entity_test_mul__field_data_test_id, 1);
    // Test that the correct relationship entity is on the row.
    $this
      ->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']
      ->id(), 1);
    $this
      ->assertEqual($row->_relationship_entities['field_test_data_with_a_long_name']
      ->bundle(), 'entity_test');
  }
}