function DefaultsSectionStorageTest::testThirdPartySettings

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testThirdPartySettings()
  2. 8.9.x core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testThirdPartySettings()
  3. 11.x core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php \Drupal\Tests\layout_builder\Unit\DefaultsSectionStorageTest::testThirdPartySettings()

@covers ::getThirdPartySetting @covers ::setThirdPartySetting

File

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

Class

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

Namespace

Drupal\Tests\layout_builder\Unit

Code

public function testThirdPartySettings() : void {
    $this->entityTypeManager
        ->getDefinition('entity_view_display')
        ->willReturn(new EntityType([
        'id' => 'entity_view_display',
    ]));
    $container = new ContainerBuilder();
    $container->set('typed_data_manager', $this->prophesize(TypedDataManagerInterface::class)
        ->reveal());
    $container->set('entity_type.manager', $this->entityTypeManager
        ->reveal());
    \Drupal::setContainer($container);
    $this->plugin
        ->getPluginDefinition()
        ->addContextDefinition('display', EntityContextDefinition::fromEntityTypeId('entity_view_display'))
        ->addContextDefinition('view_mode', new ContextDefinition('string'));
    // Set an initial value on the section list.
    $section_list = $this->prophesize(LayoutEntityDisplayInterface::class);
    $context = $this->prophesize(ContextInterface::class);
    $context->getContextValue()
        ->willReturn($section_list->reveal());
    $this->plugin
        ->setContext('display', $context->reveal());
    $section_list->getThirdPartySetting('the_module', 'the_key', NULL)
        ->willReturn('value 1');
    // The plugin returns the initial value.
    $this->assertSame('value 1', $this->plugin
        ->getThirdPartySetting('the_module', 'the_key'));
    // When the section list is updated, also update the result returned.
    $section_list->setThirdPartySetting('the_module', 'the_key', 'value 2')
        ->shouldBeCalled()
        ->will(function (array $args) use ($section_list) {
        $section_list->getThirdPartySetting('the_module', 'the_key', NULL)
            ->willReturn($args[2]);
    });
    // Update the plugin value.
    $this->plugin
        ->setThirdPartySetting('the_module', 'the_key', 'value 2');
    // Assert that the returned value matches.
    $this->assertSame('value 2', $this->plugin
        ->getThirdPartySetting('the_module', 'the_key'));
}

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