ContextTestTrait.php in Feeds extensible parsers 8
File
tests/src/Functional/Feeds/Parser/ContextTestTrait.php
View source
<?php
namespace Drupal\Tests\feeds_ex\Functional\Feeds\Parser;
trait ContextTestTrait {
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');
$feed_type = $this
->reloadEntity($this->feedType);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals($expected_context, $config['context']['value']);
}
public abstract function dataProviderValidContext();
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);
$feed_type = $this
->reloadEntity($this->feedType);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals($expected_context, $config['context']['value']);
}
public abstract function dataProviderInvalidContext();
public function testMapping() {
$data = $this
->dataProviderValidContext();
$contexts = reset($data);
$context = reset($contexts);
$edit = [
'context' => $context,
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $this->feedType
->id() . '/mapping', $edit, 'Save');
$this
->doMappingTest();
}
}