diff --git a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php index b7dd8c0..c2a1b78 100644 --- a/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php +++ b/core/modules/system/src/Tests/Entity/EntityReferenceSelection/EntityReferenceSelectionAccessTest.php @@ -316,12 +316,8 @@ public function testUserHandler() { ); $this->assertReferenceable($selection_options, $referenceable_tests, 'User handler (admin)'); - // Test the 'include_anonymous' option. This option is intentionally passed - // in the backward compatibility 'handler_settings' key to test also that - // plugin options passed in this way take precedence over the others, in the - // root. In this case the value of FALSE will override the initial value of - // 'include_anonymous' even that was declared in root of configuration. - $selection_options['handler_settings']['include_anonymous'] = FALSE; + // Test the 'include_anonymous' option. + $selection_options['include_anonymous'] = FALSE; $referenceable_tests = array( array( 'arguments' => array( diff --git a/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php new file mode 100644 index 0000000..9e14ff9 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/EntityReferenceSelection/EntityReferenceSelectionUnitTest.php @@ -0,0 +1,110 @@ + 'foo', + 'setting2' => ['bar', 'baz'], + ], + ], + [ + [ + 'handler_settings' => [ + 'setting1' => 'foo', + 'setting2' => ['bar', 'baz'], + ], + ], + ], + [ + [ + 'setting1' => 'foo', + 'handler_settings' => [ + 'setting2' => ['bar', 'baz'], + ] + ], + ], + [ + [ + 'setting1' => 'foo', + 'setting2' => 'this will be overwritten', + 'handler_settings' => [ + // Settings under 'handler_settings' take precedence. + 'setting2' => ['bar', 'baz'], + ] + ], + ], + ]; + } + + /** + * Tests selection handler plugin configuration set. + * + * @dataProvider providerTestSetConfiguration + * @covers ::setConfiguration + * + * @param array $options + * The configuration passed to the plugin. + */ + public function testSetConfiguration($options) { + $selection = new TestSelection($options, 'test_selector', []); + $selection->setConfiguration($options); + + $expected = [ + 'target_type' => NULL, + 'handler' => 'test_selector', + 'entity' => NULL, + 'setting1' => 'foo', + 'setting2' => [ + 'bar', + 'baz', + ], + 'handler_settings' => [ + 'setting1' => 'foo', + 'setting2' => [ + 'bar', + 'baz', + ], + ] + ]; + + $config = $selection->getConfiguration(); + // Sort by keys to get make comparision possible. + $this->assertSame(ksort($expected), ksort($config)); + } + +} + +/** + * Provides a testing plugin. + */ +class TestSelection extends SelectionPluginBase { + + public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { } + + public function validateReferenceableEntities(array $ids) { } + + public function countReferenceableEntities($match = NULL, $match_operator = 'CONTAINS') { } + +}