function DefaultsSectionStorageTest::testExtractEntityFromRouteCreate

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testExtractEntityFromRouteCreate()
  2. 8.9.x core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testExtractEntityFromRouteCreate()
  3. 11.x 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 197

Class

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

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testExtractEntityFromRouteCreate() : void {
    $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');
    $result = $method->invoke($this->plugin, $value, []);
    $this->assertSame($expected, $result);
}

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