function SectionDataTest::testSetArrayValue

@covers ::setValue

File

core/modules/layout_builder/tests/src/Kernel/SectionDataTest.php, line 27

Class

SectionDataTest
@coversDefaultClass \Drupal\layout_builder\Plugin\DataType\SectionData[[api-linebreak]]

Namespace

Drupal\Tests\layout_builder\Kernel

Code

public function testSetArrayValue() : void {
  $definition = DataDefinition::create('layout_section');
  $data = $this->container
    ->get(TypedDataManagerInterface::class)
    ->create($definition, name: 'test_section');
  // If an array is passed, it's converted to a Section object.
  $data->setValue([]);
  $this->assertInstanceOf(Section::class, $data->getValue());
  // Anything else should raise an exception.
  $this->expectExceptionMessage('Value assigned to "test_section" is not a valid section');
  $data->setValue('[]');
}

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