function UiPageTest::testAddEvent

Tests that an event can be added.

File

tests/src/Functional/UiPageTest.php, line 124

Class

UiPageTest
Tests that the Reaction Rules list builder pages work.

Namespace

Drupal\Tests\rules\Functional

Code

public function testAddEvent() {
    // Setup an active rule.
    $this->testCreateReactionRule();
    // Go to "Add event" page.
    $this->clickLink('Add event');
    
    /** @var \Drupal\Tests\WebAssert $assert */
    $assert = $this->assertSession();
    $assert->pageTextContains('Add event to Test rule');
    $assert->pageTextContains('Event selection');
    $assert->pageTextContains('React on event');
    // Select an event.
    $this->findField('events[0][event_name]')
        ->selectOption('rules_entity_update:node');
    $this->pressButton('Add');
    // Click add again to ignore "Restrict by type".
    $this->pressButton('Add');
    $assert->pageTextContains('Added event After updating a content item entity to Test rule.');
    // Assert that the test rule has two events now.
    $expected = [
        'rules_entity_insert:node',
        'rules_entity_update:node',
    ];
    
    /** @var \Drupal\rules\Entity\ReactionRuleConfig $rule */
    $rule = $this->storage
        ->load('test_rule');
    $this->assertSame($expected, $rule->getEventNames());
}