X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Faggregator%2Ftests%2Fsrc%2FUnit%2FPlugin%2FAggregatorPluginSettingsBaseTest.php;fp=web%2Fcore%2Fmodules%2Faggregator%2Ftests%2Fsrc%2FUnit%2FPlugin%2FAggregatorPluginSettingsBaseTest.php;h=926723702df0d0799af3399b712f50fb31e5a1ad;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php b/web/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php new file mode 100644 index 000000000..926723702 --- /dev/null +++ b/web/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php @@ -0,0 +1,113 @@ +configFactory = $this->getConfigFactoryStub( + [ + 'aggregator.settings' => [ + 'processors' => ['aggregator_test'], + ], + 'aggregator_test.settings' => [], + ] + ); + foreach (['fetcher', 'parser', 'processor'] as $type) { + $this->managers[$type] = $this->getMockBuilder('Drupal\aggregator\Plugin\AggregatorPluginManager') + ->disableOriginalConstructor() + ->getMock(); + $this->managers[$type]->expects($this->once()) + ->method('getDefinitions') + ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']])); + } + + $this->settingsForm = new SettingsForm( + $this->configFactory, + $this->managers['fetcher'], + $this->managers['parser'], + $this->managers['processor'], + $this->getStringTranslationStub() + ); + } + + /** + * Test for AggregatorPluginSettingsBase. + * + * Ensure that the settings form calls build, validate and submit methods on + * plugins that extend AggregatorPluginSettingsBase. + */ + public function testSettingsForm() { + // Emulate a form state of a submitted form. + $form_state = (new FormState())->setValues([ + 'dummy_length' => '', + 'aggregator_allowed_html_tags' => '', + ]); + + $test_processor = $this->getMock( + 'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor', + ['buildConfigurationForm', 'validateConfigurationForm', 'submitConfigurationForm'], + [[], 'aggregator_test', ['description' => ''], $this->configFactory] + ); + $test_processor->expects($this->at(0)) + ->method('buildConfigurationForm') + ->with($this->anything(), $form_state) + ->will($this->returnArgument(0)); + $test_processor->expects($this->at(1)) + ->method('validateConfigurationForm') + ->with($this->anything(), $form_state); + $test_processor->expects($this->at(2)) + ->method('submitConfigurationForm') + ->with($this->anything(), $form_state); + + $this->managers['processor']->expects($this->once()) + ->method('createInstance') + ->with($this->equalTo('aggregator_test')) + ->will($this->returnValue($test_processor)); + + $form = $this->settingsForm->buildForm([], $form_state); + $this->settingsForm->validateForm($form, $form_state); + $this->settingsForm->submitForm($form, $form_state); + } + +} + +// @todo Delete after https://www.drupal.org/node/2278383 is in. +namespace Drupal\Core\Form; + +if (!function_exists('drupal_set_message')) { + function drupal_set_message() {} +}