3 namespace Drupal\Tests\aggregator\Unit\Plugin;
5 use Drupal\aggregator\Form\SettingsForm;
6 use Drupal\Core\Form\FormState;
7 use Drupal\Core\Messenger\MessengerInterface;
8 use Drupal\Tests\UnitTestCase;
11 * Tests settings configuration of individual aggregator plugins.
15 class AggregatorPluginSettingsBaseTest extends UnitTestCase {
18 * The aggregator settings form object under test.
20 * @var \Drupal\aggregator\Form\SettingsForm
22 protected $settingsForm;
25 * The stubbed config factory object.
27 * @var \PHPUnit_Framework_MockObject_MockBuilder
29 protected $configFactory;
32 * The stubbed aggregator plugin managers array.
41 protected function setUp() {
42 $this->configFactory = $this->getConfigFactoryStub(
44 'aggregator.settings' => [
45 'processors' => ['aggregator_test'],
47 'aggregator_test.settings' => [],
50 foreach (['fetcher', 'parser', 'processor'] as $type) {
51 $this->managers[$type] = $this->getMockBuilder('Drupal\aggregator\Plugin\AggregatorPluginManager')
52 ->disableOriginalConstructor()
54 $this->managers[$type]->expects($this->once())
55 ->method('getDefinitions')
56 ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']]));
59 /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockBuilder $messenger */
60 $messenger = $this->createMock(MessengerInterface::class);
61 $messenger->expects($this->any())->method('addMessage');
63 $this->settingsForm = new SettingsForm(
65 $this->managers['fetcher'],
66 $this->managers['parser'],
67 $this->managers['processor'],
68 $this->getStringTranslationStub()
70 $this->settingsForm->setMessenger($messenger);
74 * Test for AggregatorPluginSettingsBase.
76 * Ensure that the settings form calls build, validate and submit methods on
77 * plugins that extend AggregatorPluginSettingsBase.
79 public function testSettingsForm() {
80 // Emulate a form state of a submitted form.
81 $form_state = (new FormState())->setValues([
83 'aggregator_allowed_html_tags' => '',
86 $test_processor = $this->getMock(
87 'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor',
88 ['buildConfigurationForm', 'validateConfigurationForm', 'submitConfigurationForm'],
89 [[], 'aggregator_test', ['description' => ''], $this->configFactory]
91 $test_processor->expects($this->at(0))
92 ->method('buildConfigurationForm')
93 ->with($this->anything(), $form_state)
94 ->will($this->returnArgument(0));
95 $test_processor->expects($this->at(1))
96 ->method('validateConfigurationForm')
97 ->with($this->anything(), $form_state);
98 $test_processor->expects($this->at(2))
99 ->method('submitConfigurationForm')
100 ->with($this->anything(), $form_state);
102 $this->managers['processor']->expects($this->once())
103 ->method('createInstance')
104 ->with($this->equalTo('aggregator_test'))
105 ->will($this->returnValue($test_processor));
107 $form = $this->settingsForm->buildForm([], $form_state);
108 $this->settingsForm->validateForm($form, $form_state);
109 $this->settingsForm->submitForm($form, $form_state);