View source
<?php
namespace Drupal\Tests\feeds_tamper\FunctionalJavascript;
class UiCrudTest extends FeedsTamperJavascriptTestBase {
protected $feedType;
protected $url;
protected $feedTypeTamperManager;
protected function setUp() {
parent::setUp();
node_add_body_field($this->nodeType);
$this->feedType = $this
->createFeedType([
'mappings' => array_merge($this
->getDefaultMappings(), [
[
'target' => 'body',
'map' => [
'summary' => 'description',
'value' => 'content',
],
],
]),
]);
$this->url = $this->feedType
->toUrl('tamper');
$this->feedTypeTamperManager = \Drupal::service('feeds_tamper.feed_type_tamper_manager');
}
public function testAddTamperInstance() {
$this
->drupalGet($this->url);
$this
->getSession()
->getPage()
->find('css', '#edit-description-add-link')
->click();
$this
->getSession()
->getPage()
->selectFieldOption('tamper_id', 'trim');
$this
->assertSession()
->waitForElementVisible('css', '#plugin-config');
$edit = [
'plugin_configuration[label]' => 'Trim test',
'plugin_configuration[side]' => 'ltrim',
];
$this
->submitForm($edit, 'Submit');
$this->feedType = $this
->reloadEntity($this->feedType);
$plugin_collection = $this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE)
->getTampers();
$this
->assertCount(1, $plugin_collection);
$tamper = $plugin_collection
->getIterator()
->current();
$this
->assertEquals('trim', $tamper
->getPluginId());
$this
->assertEquals('Trim test', $tamper
->getSetting('label'));
$this
->assertEquals('ltrim', $tamper
->getSetting('side'));
$this
->assertEquals('description', $tamper
->getSetting('source'));
$this
->assertNoPhpErrorsInLog();
}
public function testLabelUpdateWhenChangingPlugin() {
$this
->drupalGet($this->url);
$this
->getSession()
->getPage()
->find('css', '#edit-description-add-link')
->click();
$page = $this
->getSession()
->getPage();
$page
->selectFieldOption('tamper_id', 'required');
$this
->assertSession()
->waitForElementVisible('css', '#plugin-config');
$field = $page
->findField('plugin_configuration[label]');
$this
->assertEquals('Required', $field
->getValue());
$page = $this
->getSession()
->getPage();
$page
->selectFieldOption('tamper_id', 'unique');
$this
->assertSession()
->waitForText('Makes the elements in a multivalued field unique.');
$field = $page
->findField('plugin_configuration[label]');
$this
->assertEquals('Unique', $field
->getValue());
$this
->submitForm([], 'Submit');
$this->feedType = $this
->reloadEntity($this->feedType);
$plugin_collection = $this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE)
->getTampers();
$this
->assertCount(1, $plugin_collection);
$tamper = $plugin_collection
->getIterator()
->current();
$this
->assertEquals('unique', $tamper
->getPluginId());
$this
->assertEquals('Unique', $tamper
->getSetting('label'));
$this
->assertEquals('description', $tamper
->getSetting('source'));
$this
->assertNoPhpErrorsInLog();
}
}