function DisplayApiTest::testFieldEmpty in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/field/src/Tests/DisplayApiTest.php \Drupal\field\Tests\DisplayApiTest::testFieldEmpty()
Tests that the prepareView() formatter method still fires for empty values.
File
- core/
modules/ field/ src/ Tests/ DisplayApiTest.php, line 282 - Contains \Drupal\field\Tests\DisplayApiTest.
Class
- DisplayApiTest
- Tests the field display API.
Namespace
Drupal\field\TestsCode
function testFieldEmpty() {
// Uses \Drupal\field_test\Plugin\Field\FieldFormatter\TestFieldEmptyFormatter.
$display = array(
'label' => 'hidden',
'type' => 'field_empty_test',
'settings' => array(
'test_empty_string' => '**EMPTY FIELD**' . $this
->randomMachineName(),
),
);
// $this->entity is set by the setUp() method and by default contains 4
// numeric values. We only want to test the display of this one field.
$build = $this->entity
->get($this->fieldName)
->view($display);
$this
->render($build);
// The test field by default contains values, so should not display the
// default "empty" text.
$this
->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->fieldName} = array();
$this->entity
->save();
$build = $this->entity
->get($this->fieldName)
->view($display);
$this
->render($build);
// This time, as the field values have been removed, we *should* show the
// default "empty" text.
$this
->assertText($display['settings']['test_empty_string']);
}