function EntityFieldBlockTest::testBodyField

Same name in other branches
  1. 8.x-3.x modules/ctools_block/tests/src/Functional/EntityFieldBlockTest.php \Drupal\Tests\ctools_block\Functional\EntityFieldBlockTest::testBodyField()

Tests using the node body field in a block.

File

modules/ctools_block/tests/src/Functional/EntityFieldBlockTest.php, line 27

Class

EntityFieldBlockTest
Tests the entity field block.

Namespace

Drupal\Tests\ctools_block\Functional

Code

public function testBodyField() {
    $block = $this->drupalPlaceBlock('entity_field:node:body', [
        'formatter' => [
            'type' => 'text_default',
        ],
        'context_mapping' => [
            'entity' => '@node.node_route_context:node',
        ],
    ]);
    $node = $this->drupalCreateNode([
        'type' => 'ctools_block_field_test',
    ]);
    $this->drupalGet('node/' . $node->id());
    $assert = $this->assertSession();
    $assert->pageTextContains($block->label());
    $assert->pageTextContains($node->body->value);
    $node->set('body', NULL)
        ->save();
    $this->getSession()
        ->reload();
    // The block should not appear if there is no value in the field.
    $assert->pageTextNotContains($block->label());
}