You are here

public function DefaultsSectionStorageTest::testExtractEntityFromRouteCreate in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testExtractEntityFromRouteCreate()

@covers ::extractEntityFromRoute

File

core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php, line 323

Class

DefaultsSectionStorageTest
@coversDefaultClass \Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testExtractEntityFromRouteCreate() {
  $expected = 'the_return_value';
  $value = 'foo.bar.baz';
  $expected_create_values = [
    'targetEntityType' => 'foo',
    'bundle' => 'bar',
    'mode' => 'baz',
    'status' => TRUE,
  ];
  $entity_storage = $this
    ->prophesize(EntityStorageInterface::class);
  $entity_storage
    ->load($value)
    ->willReturn(NULL);
  $entity_storage
    ->create($expected_create_values)
    ->willReturn($expected);
  $this->entityTypeManager
    ->getDefinition('entity_view_display')
    ->willReturn(new EntityType([
    'id' => 'entity_view_display',
  ]));
  $this->entityTypeManager
    ->getStorage('entity_view_display')
    ->willReturn($entity_storage
    ->reveal());
  $method = new \ReflectionMethod($this->plugin, 'extractEntityFromRoute');
  $method
    ->setAccessible(TRUE);
  $result = $method
    ->invoke($this->plugin, $value, []);
  $this
    ->assertSame($expected, $result);
}