View source
<?php
namespace Drupal\Tests\aggregator\Unit\Plugin {
use Drupal\aggregator\Form\SettingsForm;
use Drupal\Core\Form\FormState;
use Drupal\Tests\UnitTestCase;
class AggregatorPluginSettingsBaseTest extends UnitTestCase {
protected $settingsForm;
protected $configFactory;
protected $managers;
protected function setUp() {
$this->configFactory = $this
->getConfigFactoryStub(array(
'aggregator.settings' => array(
'processors' => array(
'aggregator_test',
),
),
'aggregator_test.settings' => array(),
));
foreach (array(
'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(array(
'aggregator_test' => array(
'title' => '',
'description' => '',
),
)));
}
$this->settingsForm = new SettingsForm($this->configFactory, $this->managers['fetcher'], $this->managers['parser'], $this->managers['processor'], $this
->getStringTranslationStub());
}
public function testSettingsForm() {
$form_state = (new FormState())
->setValues([
'dummy_length' => '',
'aggregator_allowed_html_tags' => '',
]);
$test_processor = $this
->getMock('Drupal\\aggregator_test\\Plugin\\aggregator\\processor\\TestProcessor', array(
'buildConfigurationForm',
'validateConfigurationForm',
'submitConfigurationForm',
), array(
array(),
'aggregator_test',
array(
'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(array(), $form_state);
$this->settingsForm
->validateForm($form, $form_state);
$this->settingsForm
->submitForm($form, $form_state);
}
}
}
namespace {
if (!function_exists('drupal_set_message')) {
function drupal_set_message() {
}
}
}