function EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName

Same name in other branches
  1. 9 core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName()
  2. 8.9.x core/modules/field/tests/src/Kernel/EntityReference/Views/EntityReferenceRelationshipTest.php \Drupal\Tests\field\Kernel\EntityReference\Views\EntityReferenceRelationshipTest::testDataTableRelationshipWithLongFieldName()
  3. 11.x 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 253

Class

EntityReferenceRelationshipTest
Tests entity reference relationship data.

Namespace

Drupal\Tests\field\Kernel\EntityReference\Views

Code

public function testDataTableRelationshipWithLongFieldName() : void {
    // 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->assertEquals($this->entities[$index]
            ->id(), $row->id);
        // Also check that we have the correct result entity.
        $this->assertEquals($this->entities[$index]
            ->id(), $row->_entity
            ->id());
        // Test the forward relationship.
        // $this->assertEquals(1, $row->entity_test_entity_test_mul__field_data_test_id);
        // Test that the correct relationship entity is on the row.
        $this->assertEquals(1, $row->_relationship_entities['field_test_data_with_a_long_name']
            ->id());
        $this->assertEquals('entity_test', $row->_relationship_entities['field_test_data_with_a_long_name']
            ->bundle());
    }
}

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