function DataListItemAddTest::testActionExecutionItemPrepend

Tests the action execution - item prepend.

@covers ::execute

File

tests/src/Unit/Integration/RulesAction/DataListItemAddTest.php, line 92

Class

DataListItemAddTest
@coversDefaultClass \Drupal\rules\Plugin\RulesAction\DataListItemAdd @group RulesAction

Namespace

Drupal\Tests\rules\Unit\Integration\RulesAction

Code

public function testActionExecutionItemPrepend() {
    // Test adding a value at the start.
    $list = [
        'One',
        'Two',
        'Three',
    ];
    $this->action
        ->setContextValue('list', $list)
        ->setContextValue('item', 'Zero')
        ->setContextValue('position', 'start');
    $this->action
        ->execute();
    // The list should contain four items, with the new item added at the start.
    $this->assertEquals([
        'Zero',
        'One',
        'Two',
        'Three',
    ], $this->action
        ->getContextValue('list'));
}