function EntityReferenceSelectionUnitTest::testSetConfigurationBcLevel

Tests the selection handler plugin BC structure.

@covers ::setConfiguration
@covers ::resolveBackwardCompatibilityConfiguration
@covers ::ensureBackwardCompatibilityConfiguration

File

core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php, line 153

Class

EntityReferenceSelectionUnitTest
Provides unit testing for selection handlers.

Namespace

Drupal\Tests\Core\EntityReferenceSelection

Code

public function testSetConfigurationBcLevel() {
  $config = [
    'target_type' => 'some_entity_type_id',
    'handler' => 'test_selector',
    'setting1' => 'foo',
  ];
  $selection = new TestSelection($config, 'test_selector', []);
  $expected = [
    'target_type' => 'some_entity_type_id',
    'handler' => 'test_selector',
    'entity' => NULL,
    'setting1' => 'foo',
    'setting2' => [
      'qux' => 'qux value',
    ],
    'setting3' => 'foobar',
    'handler_settings' => [
      'setting1' => 'foo',
      'setting2' => [
        'qux' => 'qux value',
      ],
      'setting3' => 'foobar',
    ],
  ];
  $this->assertArrayEquals($expected, $selection->getConfiguration());
  // Read the stored values and override a setting.
  $config = $selection->getConfiguration();
  $config['setting1'] = 'bar';
  $selection->setConfiguration($config);
  $expected['setting1'] = 'bar';
  $expected['handler_settings']['setting1'] = 'bar';
  $this->assertArrayEquals($expected, $selection->getConfiguration());
}

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