function DefaultLazyPluginCollectionTest::testAddInstanceId

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultLazyPluginCollectionTest::testAddInstanceId()
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultLazyPluginCollectionTest::testAddInstanceId()
  3. 10 core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php \Drupal\Tests\Core\Plugin\DefaultLazyPluginCollectionTest::testAddInstanceId()

@covers ::addInstanceId

File

core/tests/Drupal/Tests/Core/Plugin/DefaultLazyPluginCollectionTest.php, line 121

Class

DefaultLazyPluginCollectionTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Plugin%21DefaultLazyPluginCollection.php/class/DefaultLazyPluginCollection/11.x" title="Provides a default plugin collection for a plugin type." class="local">\Drupal\Core\Plugin\DefaultLazyPluginCollection</a> @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function testAddInstanceId() : void {
    $this->setupPluginCollection($this->exactly(4));
    $expected = [
        'banana' => 'banana',
        'cherry' => 'cherry',
        'apple' => 'apple',
    ];
    $this->defaultPluginCollection
        ->addInstanceId('apple');
    $result = $this->defaultPluginCollection
        ->getInstanceIds();
    $this->assertSame($expected, $result);
    $this->assertSame($expected, array_intersect_key($result, $this->defaultPluginCollection
        ->getConfiguration()));
    $expected = [
        'cherry' => 'cherry',
        'apple' => 'apple',
        'banana' => 'banana',
    ];
    $this->defaultPluginCollection
        ->removeInstanceId('banana');
    $this->defaultPluginCollection
        ->addInstanceId('banana', $this->config['banana']);
    $result = $this->defaultPluginCollection
        ->getInstanceIds();
    $this->assertSame($expected, $result);
    $this->assertSame($expected, array_intersect_key($result, $this->defaultPluginCollection
        ->getConfiguration()));
}

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