trait ContextTestTrait in Feeds extensible parsers 8
Trait for testing the context field on the mapping form.
Hierarchy
- trait \Drupal\Tests\feeds_ex\Functional\Feeds\Parser\ContextTestTrait
File
- tests/
src/ Functional/ Feeds/ Parser/ ContextTestTrait.php, line 8
Namespace
Drupal\Tests\feeds_ex\Functional\Feeds\ParserView source
trait ContextTestTrait {
/**
* Tests setting a context on the mapping form.
*
* @covers ::mappingFormAlter
* @covers ::mappingFormValidate
* @covers ::mappingFormSubmit
*
* @dataProvider dataProviderValidContext
*/
public function testSetContext($context, $expected_context = NULL) {
if (is_null($expected_context)) {
$expected_context = $context;
}
$edit = [
'context' => $context,
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $this->feedType
->id() . '/mapping', $edit, 'Save');
// Assert that the context was saved for the XML parser.
$feed_type = $this
->reloadEntity($this->feedType);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals($expected_context, $config['context']['value']);
}
/**
* Data provider for testSetContext().
*/
public abstract function dataProviderValidContext();
/**
* Tests setting an invalid context on the mapping form.
*
* @covers ::mappingFormAlter
* @covers ::mappingFormValidate
*
* @dataProvider dataProviderInvalidContext
*/
public function testSetInvalidContext($context, $expected_error, $expected_context = '') {
$edit = [
'context' => $context,
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $this->feedType
->id() . '/mapping', $edit, 'Save');
$this
->assertText($expected_error);
// Assert that the context was *not* saved for the parser.
$feed_type = $this
->reloadEntity($this->feedType);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals($expected_context, $config['context']['value']);
}
/**
* Data provider for testSetInvalidContext().
*/
public abstract function dataProviderInvalidContext();
/**
* Does a basic mapping test.
*/
public function testMapping() {
// First, set context.
$data = $this
->dataProviderValidContext();
$contexts = reset($data);
$context = reset($contexts);
$edit = [
'context' => $context,
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $this->feedType
->id() . '/mapping', $edit, 'Save');
// Now set mapping.
$this
->doMappingTest();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContextTestTrait:: |
abstract public | function | Data provider for testSetInvalidContext(). | 6 |
ContextTestTrait:: |
abstract public | function | Data provider for testSetContext(). | 6 |
ContextTestTrait:: |
public | function | Does a basic mapping test. | |
ContextTestTrait:: |
public | function | Tests setting a context on the mapping form. | |
ContextTestTrait:: |
public | function | Tests setting an invalid context on the mapping form. |