diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php index 6abd8d9..b830b1a 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Form/SettingsForm.php @@ -104,6 +104,8 @@ public function getFormID() { */ protected function getConfigurableInstances() { if (!isset($this->configurableInstances)) { + $this->configurableInstances = array(); + $config = $this->configFactory->get('aggregator.settings'); // Parse fetchers and parsers and collect their PluginFormInterface @@ -243,7 +245,7 @@ public function getConfigNames() { $config_names = array('aggregator.settings'); foreach ($this->getConfigurableInstances() as $instance) { - $config_names[] = $instance->getConfigNames(); + $config_names += $instance->getConfigNames(); } return array_unique($config_names); diff --git a/core/modules/aggregator/tests/Drupal/aggregator/Tests/Form/SettingsFormTest.php b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Form/SettingsFormTest.php new file mode 100644 index 0000000..68c7d73 --- /dev/null +++ b/core/modules/aggregator/tests/Drupal/aggregator/Tests/Form/SettingsFormTest.php @@ -0,0 +1,122 @@ + 'Aggregator settings form tests', + 'description' => 'Unit tests for the aggregator settings form', + 'group' => 'Aggregator', + ); + } + + public function setUp() { + + } + + /** + * Tests getConfigNames(). + */ + public function testGetConfigNames() { + // Test with no aggregator plugins. + $configs = array('aggregator.settings' => array()); + $definitions = array(); + + list($settings_form) = $this->getSettingsForm($configs, $definitions); + + $expected = array('aggregator.settings'); + $this->assertSame($expected, $settings_form->getConfigNames()); + + // Test that aggregator plugins can add additional configuration names and + // that duplicated names are removed. + $configs = array('aggregator.settings' => array( + 'fetcher' => 'aggregator_test_fetcher', + 'parser' => 'aggregator_test_parser', + 'processors' => array('aggregator_test_processor') + )); + $definitions = array( + 'aggregator_test_fetcher' => array( + 'title' => 'Test fetcher', + 'description' => 'Test generic fetcher functionality.', + ), + 'aggregator_test_parser' => array( + 'title' => 'Test parser', + 'description' => 'Test generic parser functionality.', + ), + 'aggregator_test_processor' => array( + 'title' => 'Test processor', + 'description' => 'Test generic processor functionality.', + ), + ); + + list($settings_form, $plugin_manager) = $this->getSettingsForm($configs, $definitions); + + $plugin = $this->getMock('Drupal\Core\Plugin\PluginFormInterface'); + $plugin + ->expects($this->exactly(3)) + ->method('getConfigNames') + ->will($this->returnValue( + array('aggregator.settings', 'aggregator_test.settings') + )); + $plugin_manager + ->expects($this->exactly(3)) + ->method('createInstance') + ->will($this->returnValueMap(array( + array('aggregator_test_fetcher', array(), $plugin), + array('aggregator_test_parser', array(), $plugin), + array('aggregator_test_processor', array(), $plugin) + ))); + + $expected = array('aggregator.settings', 'aggregator_test.settings'); + + $this->assertSame($expected, $settings_form->getConfigNames()); + } + + /** + * Returns an aggregator settings form. + * + * @param array $configs + * An array of configuration values as expected by + * UnitTestCase::getConfigFactoryStub(). + * @param array $definitions + * An array of aggregator plugin definitions. + * + * @return array + * An array that contains the aggregator settings form and mocked aggregator + * plugin manager. + */ + protected function getSettingsForm(array $configs, array $definitions) { + $plugin_manager = $this->getMockBuilder('Drupal\aggregator\Plugin\AggregatorPluginManager') + ->disableOriginalConstructor() + ->getMock(); + $plugin_manager + ->expects($this->exactly(3)) + ->method('getDefinitions') + ->will($this->returnValue($definitions)); + return array(new SettingsForm( + $this->getConfigFactoryStub($configs), + $this->getMock('Drupal\Core\Config\Context\ContextInterface'), + $plugin_manager, + $plugin_manager, + $plugin_manager, + $this->getMock('Drupal\Core\StringTranslation\TranslationInterface') + ), $plugin_manager); + } + +}