diff --git a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginBagTest.php b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginBagTest.php index 207beb8..892ca23 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginBagTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Plugin/PluginBagTest.php @@ -8,6 +8,7 @@ namespace Drupal\system\Tests\Plugin; use Drupal\plugin_test\Plugin\TestPluginBag; +use Drupal\plugin_test\Plugin\plugin_test\mock_block\MockTestPluginInterface; /** * Tests the generic plugin bag. @@ -36,19 +37,32 @@ protected function testPluginBag() { foreach ($definitions as $instance_id => $definition) { $this->assertTrue(isset($plugin_bag[$instance_id]), format_string('Plugin instance @instance_id exits on the bag', array('@instance_id' => $instance_id))); + $this->assertTrue($plugin_bag->has($instance_id), format_string('Plugin instance @instance_id exits on the bag', array('@instance_id' => $instance_id))); + $this->assertTrue($plugin_bag[$instance_id] instanceof $definition['class'], 'Getting the plugin from the bag worked.'); + $this->assertTrue($plugin_bag->get($instance_id) instanceof $definition['class'], 'Getting the plugin from the bag worked.'); } // A non existing instance_id shouldn't exist on the bag. $random_name = $this->randomName(); + $random_name_2 = $this->randomName(); $this->assertFalse(isset($plugin_bag[$random_name]), 'A random instance_id should not exist on the plugin bag.'); + $this->assertFalse($plugin_bag->has($random_name_2), 'A random instance_id should not exist on the plugin bag.'); // Set a new plugin instance to the bag, to test offsetSet. $plugin_bag[$random_name] = $this->mockBlockManager->createInstance($first_instance_id, array()); + $plugin_bag->set($random_name_2, $this->mockBlockManager->createInstance($first_instance_id, array())); $this->assertTrue(isset($plugin_bag[$random_name]), 'A random instance_id should exist after manual setting on the plugin bag.'); + $this->assertTrue(isset($plugin_bag[$random_name_2]), 'A random instance_id should exist after manual setting on the plugin bag.'); + $this->assertTrue($plugin_bag->has($random_name), 'A random instance_id should exist after manual setting on the plugin bag.'); + $this->assertTrue($plugin_bag->has($random_name_2), 'A random instance_id should exist after manual setting on the plugin bag.'); // Remove the previous added element and check whether it still exists. unset($plugin_bag[$random_name]); + $plugin_bag->remove($random_name_2); $this->assertFalse(isset($plugin_bag[$random_name]), 'A random instance_id should not exist on the plugin bag after removing.'); + $this->assertFalse(isset($plugin_bag[$random_name_2]), 'A random instance_id should not exist on the plugin bag after removing.'); + $this->assertFalse($plugin_bag->has($random_name), 'A random instance_id should not exist on the plugin bag after removing.'); + $this->assertFalse($plugin_bag->has($random_name_2), 'A random instance_id should not exist on the plugin bag after removing.'); // Test that iterating over the plugins work. $expected_instance_ids = array_keys($definitions);