function UiPageTest::testDeleteEvent

Tests that an event can be deleted.

File

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

Class

UiPageTest
Tests that the Reaction Rules list builder pages work.

Namespace

Drupal\Tests\rules\Functional

Code

public function testDeleteEvent() {
    // Create a rule with two events.
    $rule = $this->storage
        ->create([
        'id' => 'test_rule',
        'label' => 'Test rule',
        'events' => [
            [
                'event_name' => 'rules_entity_insert:node',
            ],
            [
                'event_name' => 'rules_entity_update:node',
            ],
        ],
    ]);
    $rule->save();
    
    /** @var \Drupal\Tests\WebAssert $assert */
    $assert = $this->assertSession();
    // Login and go to the rule edit page.
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/config/workflow/rules/reactions/edit/test_rule');
    // Click delete button for second event.
    $this->clickLinkByHref('event-delete/rules_entity_update');
    // Assert we are on the delete page.
    $assert->pageTextContains('Are you sure you want to delete the event After updating a content item entity from Test rule?');
    // And confirm the delete.
    $this->pressButton('Delete');
    $assert->pageTextContains('Deleted event After updating a content item entity from Test rule.');
    // We need to reload the container because the container can get rebuilt
    // when saving a rule.
    $this->resetAll();
    $this->storage = $this->container
        ->get('entity_type.manager')
        ->getStorage('rules_reaction_rule');
    
    /** @var \Drupal\rules\Entity\ReactionRuleConfig $rule */
    $rule = $this->storage
        ->loadUnchanged('test_rule');
    // Assert that the event is really deleted.
    $this->assertSame([
        'rules_entity_insert:node',
    ], $rule->getEventNames());
}