diff --git a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php index 15c85d0..7e943df 100644 --- a/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php +++ b/core/lib/Drupal/Component/Plugin/DefaultPluginBag.php @@ -48,7 +48,7 @@ class DefaultPluginBag extends PluginBag { * * @var array */ - protected $originalOrder; + protected $originalOrder = array(); /** * Constructs a new DefaultPluginBag object. diff --git a/core/tests/Drupal/Tests/Component/Plugin/DefaultPluginBagTest.php b/core/tests/Drupal/Tests/Component/Plugin/DefaultPluginBagTest.php index e844dcc..01c652f 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/DefaultPluginBagTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/DefaultPluginBagTest.php @@ -47,9 +47,9 @@ class DefaultPluginBagTest extends UnitTestCase { * @var array */ protected $config = array( - 'apple' => array('id' => 'apple', 'key' => 'value'), 'banana' => array('id' => 'banana', 'key' => 'value'), 'cherry' => array('id' => 'cherry', 'key' => 'value'), + 'apple' => array('id' => 'apple', 'key' => 'value'), ); public static function getInfo() { @@ -94,7 +94,7 @@ protected function setUp() { public function testHas() { $definitions = $this->getPluginDefinitions(); - $this->assertFalse($this->defaultPluginBag->has($this->randomName()), 'Non existing plugin found.'); + $this->assertFalse($this->defaultPluginBag->has($this->randomName()), 'Nonexistent plugin found.'); foreach (array_keys($definitions) as $plugin_id) { $this->assertTrue($this->defaultPluginBag->has($plugin_id)); @@ -192,11 +192,27 @@ public function testSortHelper($plugin_id_1, $plugin_id_2, $expected) { } /** - * Tests the sort method. + * Tests the configuration getter method. * - * @see \Drupal\Component\Plugin\DefaultPluginBag::sort() + * @see \Drupal\Component\Plugin\DefaultPluginBag::getConfiguration() */ - public function testSort() { + public function testGetConfiguration() { + // The expected order matches $this->config. + $expected = array('banana', 'cherry', 'apple'); + + $config = $this->defaultPluginBag->getConfiguration(); + $this->assertSame($expected, array_keys($config), 'The order of the configuration is unchanged.'); + + $ids = $this->defaultPluginBag->getInstanceIDs(); + $this->assertSame($expected, array_keys($ids), 'The order of the instances is unchanged.'); + + $this->defaultPluginBag->sort(); + $config = $this->defaultPluginBag->getConfiguration(); + $this->assertSame($expected, array_keys($config), 'After sorting, the order of the configuration is unchanged.'); + + $ids = $this->defaultPluginBag->getInstanceIDs(); + sort($expected); + $this->assertSame($expected, array_keys($ids), 'After sorting, the order of the instances is also sorted.'); } }