function UiPageTest::testAddEventWithRestrictByType

Tests that an event with type restriction can be added.

File

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

Class

UiPageTest
Tests that the Reaction Rules list builder pages work.

Namespace

Drupal\Tests\rules\Functional

Code

public function testAddEventWithRestrictByType() {
    // Add a content type called 'article'.
    $node_type = NodeType::create([
        'type' => 'article',
        'name' => 'Article',
    ]);
    $node_type->save();
    // 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');
    // Select bundle 'article'.
    $this->findField('bundle')
        ->selectOption('article');
    $this->pressButton('Add');
    $assert->pageTextContains('Added event After updating a content item entity of type Article to Test rule.');
    // Assert that the second event on the test rule has the bundle selection.
    $expected = [
        'rules_entity_insert:node',
        'rules_entity_update:node--article',
    ];
    
    /** @var \Drupal\rules\Entity\ReactionRuleConfig $rule */
    $rule = $this->storage
        ->load('test_rule');
    $this->assertSame($expected, $rule->getEventNames());
}