function UiPageTest::testNoDeleteEventWhenRulesHasSingleEvent

Tests that events cannot be deleted when there is only one event.

File

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

Class

UiPageTest
Tests that the Reaction Rules list builder pages work.

Namespace

Drupal\Tests\rules\Functional

Code

public function testNoDeleteEventWhenRulesHasSingleEvent() {
  // Create a rule.
  $rule = $this->storage
    ->create([
    'id' => 'test_rule',
    'label' => 'Test rule',
    'events' => [
      [
        'event_name' => 'rules_entity_insert:node',
      ],
    ],
  ]);
  $rule->save();
  // Login and go to the rule edit page.
  $this->drupalLogin($this->adminUser);
  $this->drupalGet('admin/config/workflow/rules/reactions/edit/test_rule');
  // Assert that no link is displayed for deleting the only event that there
  // is.
  $this->assertNull($this->getSession()
    ->getPage()
    ->find('xpath', './/a[contains(@href, "event-delete/rules_entity_insert")]'));
  // Try to delete the event anyway and assert that access to that page is
  // denied.
  $this->drupalGet('admin/config/workflow/rules/reactions/edit/test_rule/event-delete/rules_entity_insert:node');
  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this->assertSession();
  $assert->statusCodeEquals(403);
}