function FieldBlockTest::testBuildWithFormException

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockTest::testBuildWithFormException()
  2. 10 core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockTest::testBuildWithFormException()
  3. 11.x core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php \Drupal\Tests\layout_builder\Kernel\FieldBlockTest::testBuildWithFormException()

Tests a field block that throws a form exception.

@todo Remove in https://www.drupal.org/project/drupal/issues/2367555.

File

core/modules/layout_builder/tests/src/Kernel/FieldBlockTest.php, line 307

Class

FieldBlockTest
@coversDefaultClass \Drupal\layout_builder\Plugin\Block\FieldBlock @group Field

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testBuildWithFormException() {
    $field = $this->prophesize(FieldItemListInterface::class);
    $field->view(Argument::type('array'))
        ->willThrow(new EnforcedResponseException(new Response()));
    $entity = $this->prophesize(FieldableEntityInterface::class);
    $entity->get('the_field_name')
        ->willReturn($field->reveal());
    $block = $this->getTestBlock($entity);
    $this->expectException(EnforcedResponseException::class);
    $block->build();
}

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