View source
<?php
namespace Drupal\Tests\feeds\Functional\Form;
use Drupal\Tests\feeds\Functional\FeedsBrowserTestBase;
class MappingFormTest extends FeedsBrowserTestBase {
public static $modules = [
'feeds',
'node',
'user',
'feeds_test_plugin',
];
public function testCustomSourceUnique() {
$feed_type = $this
->createFeedTypeForCsv([
'guid' => 'guid',
'title' => 'title',
]);
$edit = [
'add_target' => 'status',
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping', $edit, 'Save');
$edit = [
'mappings[2][map][value][select]' => '__new',
'mappings[2][map][value][__new][value]' => 'title',
'mappings[2][map][value][__new][machine_name]' => 'title',
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertSession()
->pageTextContains('The machine-readable name is already in use. It must be unique.');
}
public function testPluginWithMappingForm() {
$feed_type = $this
->createFeedType([
'parser' => 'parser_with_mapping_form',
]);
$edit = [
'dummy' => 'dummyValue',
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping', $edit, 'Save');
$feed_type = $this
->reloadEntity($feed_type);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals('dummyValue', $config['dummy']);
}
public function testPluginWithMappingFormValidate() {
$feed_type = $this
->createFeedType([
'parser' => 'parser_with_mapping_form',
]);
$edit = [
'dummy' => 'invalid',
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping', $edit, 'Save');
$this
->assertText('Invalid value.');
$feed_type = $this
->reloadEntity($feed_type);
$config = $feed_type
->getParser()
->getConfiguration();
$this
->assertEquals('', $config['dummy']);
}
public function testMappingToEntityIdWarning() {
$feed_type = $this
->createFeedType();
$edit = [
'add_target' => 'nid',
];
$this
->drupalPostForm('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping', $edit, 'Save');
$edit = [
'mappings[2][unique][value]' => 0,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->assertSession()
->pageTextContains('When mapping to the entity ID (ID), it is recommended to set it as unique.');
$feed_type = $this
->reloadEntity($feed_type);
$mapping = $feed_type
->getMappings()[2];
$this
->assertTrue(empty($mapping['unique']['value']));
}
public function testMissingTargetWarning() {
$feed_type = $this
->createFeedType();
$feed_type
->addMapping([
'target' => 'non_existent',
'map' => [
'value' => 'title',
],
]);
$feed_type
->save();
$this
->drupalGet('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping');
$this
->assertSession()
->pageTextContains('The Feeds target "non_existent" does not exist.');
$this
->assertSession()
->pageTextContains('Error: target is missing (non_existent)');
$edit = [
'remove_mappings[2]' => 1,
];
$this
->drupalPostForm(NULL, $edit, 'Save');
$this
->drupalGet('/admin/structure/feeds/manage/' . $feed_type
->id() . '/mapping');
$this
->assertSession()
->pageTextNotContains('The Feeds target "non_existent" does not exist.');
$this
->assertSession()
->pageTextNotContains('Error: target is missing (non_existent)');
$feed_type = $this
->reloadEntity($feed_type);
$this
->assertEquals($this
->getDefaultMappings(), $feed_type
->getMappings());
}
}