class AggregatorPluginSettingsBaseTest
Same name in other branches
- 8.9.x core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php \Drupal\Tests\aggregator\Unit\Plugin\AggregatorPluginSettingsBaseTest
Tests settings configuration of individual aggregator plugins.
@group aggregator @group legacy
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait
- class \Drupal\Tests\aggregator\Unit\Plugin\AggregatorPluginSettingsBaseTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of AggregatorPluginSettingsBaseTest
File
-
core/
modules/ aggregator/ tests/ src/ Unit/ Plugin/ AggregatorPluginSettingsBaseTest.php, line 16
Namespace
Drupal\Tests\aggregator\Unit\PluginView source
class AggregatorPluginSettingsBaseTest extends UnitTestCase {
/**
* The aggregator settings form object under test.
*
* @var \Drupal\aggregator\Form\SettingsForm
*/
protected $settingsForm;
/**
* The stubbed config factory object.
*
* @var \PHPUnit\Framework\MockObject\MockBuilder
*/
protected $configFactory;
/**
* The stubbed aggregator plugin managers array.
*
* @var array
*/
protected $managers;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->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')
->willReturn([
'aggregator_test' => [
'title' => '',
'description' => '',
],
]);
}
/** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockBuilder $messenger */
$messenger = $this->createMock(MessengerInterface::class);
$messenger->expects($this->any())
->method('addMessage');
$this->settingsForm = new SettingsForm($this->configFactory, $this->managers['fetcher'], $this->managers['parser'], $this->managers['processor'], $this->getStringTranslationStub());
$this->settingsForm
->setMessenger($messenger);
}
/**
* Tests 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->getMockBuilder('Drupal\\aggregator_test\\Plugin\\aggregator\\processor\\TestProcessor')
->onlyMethods([
'buildConfigurationForm',
'validateConfigurationForm',
'submitConfigurationForm',
])
->setConstructorArgs([
[],
'aggregator_test',
[
'description' => '',
],
$this->configFactory,
])
->getMock();
$test_processor->expects($this->once())
->method('buildConfigurationForm')
->with($this->anything(), $form_state)
->will($this->returnArgument(0));
$test_processor->expects($this->once())
->method('validateConfigurationForm')
->with($this->anything(), $form_state);
$test_processor->expects($this->once())
->method('submitConfigurationForm')
->with($this->anything(), $form_state);
$this->managers['processor']
->expects($this->once())
->method('createInstance')
->with($this->equalTo('aggregator_test'))
->willReturn($test_processor);
$form = $this->settingsForm
->buildForm([], $form_state);
$this->settingsForm
->validateForm($form, $form_state);
$this->settingsForm
->submitForm($form, $form_state);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
AggregatorPluginSettingsBaseTest::$configFactory | protected | property | The stubbed config factory object. | |||
AggregatorPluginSettingsBaseTest::$managers | protected | property | The stubbed aggregator plugin managers array. | |||
AggregatorPluginSettingsBaseTest::$settingsForm | protected | property | The aggregator settings form object under test. | |||
AggregatorPluginSettingsBaseTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
AggregatorPluginSettingsBaseTest::testSettingsForm | public | function | Tests for AggregatorPluginSettingsBase. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
UnitTestCase::$randomGenerator | protected | property | The random generator. | |||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::assertArrayEquals | Deprecated | protected | function | Asserts if two arrays are equal by sorting them first. | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::randomMachineName | public | function | Generates a unique random string containing letters and numbers. | |||
UnitTestCase::setUpBeforeClass | public static | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.