function FieldFieldTest::testMissingBundleFieldRender

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

Tests that a field not available for every bundle is rendered as empty.

File

core/modules/views/tests/src/Kernel/Handler/FieldFieldTest.php, line 580

Class

FieldFieldTest
Provides some integration tests for the Field handler.

Namespace

Drupal\Tests\views\Kernel\Handler

Code

public function testMissingBundleFieldRender() : void {
    // Create a new bundle not having the test field attached.
    $bundle = $this->randomMachineName();
    entity_test_create_bundle($bundle);
    $entity = EntityTest::create([
        'type' => $bundle,
        'name' => $this->randomString(),
        'user_id' => $this->testUsers[0]
            ->id(),
    ]);
    $entity->save();
    $executable = Views::getView('test_field_field_test');
    $executable->execute();
    $this->assertEquals('', $executable->getStyle()
        ->getField(6, 'field_test'));
}

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