View source
<?php
namespace Drupal\Tests\feeds_tamper\Functional;
class UiCrudTest extends FeedsTamperBrowserTestBase {
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();
$edit = [
'tamper_id' => 'trim',
];
$this
->submitForm($edit, 'Submit');
$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'));
}
public function testEditTamperInstance() {
$uuid = $this->feedTypeTamperManager
->getTamperMeta($this->feedType)
->addTamper([
'plugin' => 'convert_case',
'operation' => 'strtoupper',
'label' => 'Str to Upper',
'source' => 'title',
'description' => 'Convert the case to uppercase.',
]);
$this->feedType
->save();
$this
->drupalGet($this->url);
$this
->getSession()
->getPage()
->find('css', '#edit-title ul.dropbutton li:nth-child(1) a')
->click();
$edit = [
'plugin_configuration[operation]' => 'ucfirst',
];
$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('convert_case', $tamper
->getPluginId());
$this
->assertEquals($uuid, $tamper
->getSetting('uuid'));
$this
->assertEquals('ucfirst', $tamper
->getSetting('operation'));
$this
->assertEquals('title', $tamper
->getSetting('source'));
}
public function testRemoveTamperInstance() {
$this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE)
->addTamper([
'plugin' => 'convert_case',
'operation' => 'strtoupper',
'label' => 'Str to Upper',
'source' => 'title',
'description' => 'Convert the case to uppercase.',
]);
$this->feedType
->save();
$this
->drupalGet($this->url);
$this
->getSession()
->getPage()
->find('css', '#edit-title ul.dropbutton li:nth-child(2) a')
->click();
$this
->submitForm([], 'Confirm');
$this->feedType = $this
->reloadEntity($this->feedType);
$plugin_collection = $this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE)
->getTampers();
$this
->assertCount(0, $plugin_collection);
}
public function testChangeTamperOrder() {
$tamper_meta = $this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE);
$uuid_content_1 = $tamper_meta
->addTamper([
'plugin' => 'explode',
'label' => 'Explode',
'separator' => '|',
'source' => 'content',
]);
$uuid_content_2 = $tamper_meta
->addTamper([
'plugin' => 'implode',
'label' => 'Implode',
'glue' => '-',
'source' => 'content',
]);
$uuid_content_3 = $tamper_meta
->addTamper([
'plugin' => 'trim',
'label' => 'Trim Content',
'side' => 'trim',
'source' => 'content',
]);
$uuid_title_1 = $tamper_meta
->addTamper([
'plugin' => 'trim',
'label' => 'Trim Title',
'side' => 'trim',
'source' => 'title',
]);
$uuid_title_2 = $tamper_meta
->addTamper([
'plugin' => 'required',
'label' => 'Required',
'invert' => FALSE,
'source' => 'title',
]);
$this->feedType
->save();
$this
->drupalGet($this->url);
$edit = [
"title[{$uuid_title_1}][weight]" => -9,
"title[{$uuid_title_2}][weight]" => -10,
"content[{$uuid_content_1}][weight]" => -10,
"content[{$uuid_content_2}][weight]" => -8,
"content[{$uuid_content_3}][weight]" => -9,
];
$this
->submitForm($edit, 'Save');
$this->feedType = $this
->reloadEntity($this->feedType);
$tamper_meta = $this->feedTypeTamperManager
->getTamperMeta($this->feedType, TRUE);
$this
->assertEquals(-9, $tamper_meta
->getTamper($uuid_title_1)
->getSetting('weight'));
$this
->assertEquals(-10, $tamper_meta
->getTamper($uuid_title_2)
->getSetting('weight'));
$this
->assertEquals(-10, $tamper_meta
->getTamper($uuid_content_1)
->getSetting('weight'));
$this
->assertEquals(-8, $tamper_meta
->getTamper($uuid_content_2)
->getSetting('weight'));
$this
->assertEquals(-9, $tamper_meta
->getTamper($uuid_content_3)
->getSetting('weight'));
}
}