View source
<?php
namespace Drupal\Tests\rules\Unit\Integration\RulesAction;
use Drupal\Tests\rules\Unit\Integration\RulesIntegrationTestBase;
class DataListItemAddTest extends RulesIntegrationTestBase {
protected $action;
protected function setUp() : void {
parent::setUp();
$this->action = $this->actionManager
->createInstance('rules_list_item_add');
}
public function testSummary() {
$this
->assertEquals('Add list item', $this->action
->summary());
}
public function testActionExecutionWithDefaults() {
$list = [
'One',
'Two',
'Three',
];
$this->action
->setContextValue('list', $list)
->setContextValue('item', 'Four');
$this->action
->execute();
$this
->assertEquals([
'One',
'Two',
'Three',
'Four',
], $this->action
->getContextValue('list'));
}
public function testActionExecutionItemAppend() {
$list = [
'One',
'Two',
'Three',
];
$this->action
->setContextValue('list', $list)
->setContextValue('item', 'Four')
->setContextValue('position', 'end');
$this->action
->execute();
$this
->assertEquals([
'One',
'Two',
'Three',
'Four',
], $this->action
->getContextValue('list'));
}
public function testActionExecutionItemPrepend() {
$list = [
'One',
'Two',
'Three',
];
$this->action
->setContextValue('list', $list)
->setContextValue('item', 'Zero')
->setContextValue('position', 'start');
$this->action
->execute();
$this
->assertEquals([
'Zero',
'One',
'Two',
'Three',
], $this->action
->getContextValue('list'));
}
public function testActionExecutionEnforceUnique() {
$list = [
'One',
'Two',
'Three',
'Four',
];
$this->action
->setContextValue('list', $list)
->setContextValue('item', 'Four')
->setContextValue('unique', TRUE);
$this->action
->execute();
$this
->assertEquals([
'One',
'Two',
'Three',
'Four',
], $this->action
->getContextValue('list'));
}
public function testActionExecutionNonUnique() {
$list = [
'One',
'Two',
'Three',
'Four',
];
$this->action
->setContextValue('list', $list)
->setContextValue('item', 'Four')
->setContextValue('unique', FALSE)
->setContextValue('position', 'end');
$this->action
->execute();
$this
->assertEquals([
'One',
'Two',
'Three',
'Four',
'Four',
], $this->action
->getContextValue('list'));
}
}