function DefaultsSectionStorageTest::testExtractEntityFromRouteCreate

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()
  2. 8.9.x core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testExtractEntityFromRouteCreate()
  3. 10 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 <a href="/api/drupal/core%21modules%21layout_builder%21src%21Plugin%21SectionStorage%21DefaultsSectionStorage.php/class/DefaultsSectionStorage/11.x" title="Defines the &#039;defaults&#039; section storage type." class="local">\Drupal\layout_builder\Plugin\SectionStorage\DefaultsSectionStorage</a>

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.