3 namespace Drupal\Tests\aggregator\Unit\Plugin;
5 use Drupal\aggregator\Form\SettingsForm;
6 use Drupal\Core\Form\FormState;
7 use Drupal\Tests\UnitTestCase;
10 * Tests settings configuration of individual aggregator plugins.
14 class AggregatorPluginSettingsBaseTest extends UnitTestCase {
17 * The aggregator settings form object under test.
19 * @var \Drupal\aggregator\Form\SettingsForm
21 protected $settingsForm;
24 * The stubbed config factory object.
26 * @var \PHPUnit_Framework_MockObject_MockBuilder
28 protected $configFactory;
31 * The stubbed aggregator plugin managers array.
40 protected function setUp() {
41 $this->configFactory = $this->getConfigFactoryStub(
43 'aggregator.settings' => [
44 'processors' => ['aggregator_test'],
46 'aggregator_test.settings' => [],
49 foreach (['fetcher', 'parser', 'processor'] as $type) {
50 $this->managers[$type] = $this->getMockBuilder('Drupal\aggregator\Plugin\AggregatorPluginManager')
51 ->disableOriginalConstructor()
53 $this->managers[$type]->expects($this->once())
54 ->method('getDefinitions')
55 ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']]));
58 $this->settingsForm = new SettingsForm(
60 $this->managers['fetcher'],
61 $this->managers['parser'],
62 $this->managers['processor'],
63 $this->getStringTranslationStub()
68 * Test for AggregatorPluginSettingsBase.
70 * Ensure that the settings form calls build, validate and submit methods on
71 * plugins that extend AggregatorPluginSettingsBase.
73 public function testSettingsForm() {
74 // Emulate a form state of a submitted form.
75 $form_state = (new FormState())->setValues([
77 'aggregator_allowed_html_tags' => '',
80 $test_processor = $this->getMock(
81 'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor',
82 ['buildConfigurationForm', 'validateConfigurationForm', 'submitConfigurationForm'],
83 [[], 'aggregator_test', ['description' => ''], $this->configFactory]
85 $test_processor->expects($this->at(0))
86 ->method('buildConfigurationForm')
87 ->with($this->anything(), $form_state)
88 ->will($this->returnArgument(0));
89 $test_processor->expects($this->at(1))
90 ->method('validateConfigurationForm')
91 ->with($this->anything(), $form_state);
92 $test_processor->expects($this->at(2))
93 ->method('submitConfigurationForm')
94 ->with($this->anything(), $form_state);
96 $this->managers['processor']->expects($this->once())
97 ->method('createInstance')
98 ->with($this->equalTo('aggregator_test'))
99 ->will($this->returnValue($test_processor));
101 $form = $this->settingsForm->buildForm([], $form_state);
102 $this->settingsForm->validateForm($form, $form_state);
103 $this->settingsForm->submitForm($form, $form_state);
108 // @todo Delete after https://www.drupal.org/node/2278383 is in.
109 namespace Drupal\Core\Form;
111 if (!function_exists('drupal_set_message')) {
112 function drupal_set_message() {