You are here

public function DeleteHomepageTest::testDeleteHomepage in Prevent homepage deletion 8

Test to check if the homepage can be deleted by various users.

File

tests/src/Functional/DeleteHomepageTest.php, line 60

Class

DeleteHomepageTest
Tests the functionality of this module.

Namespace

Drupal\Tests\prevent_homepage_deletion\Functional

Code

public function testDeleteHomepage() {

  // Step 1: Log in a user who can delete the homepage.
  $this
    ->drupalLogin($this
    ->createUser([
    'delete any page content',
    'delete_homepage_node',
  ]));

  // Step 2: Try to delete the homepage.
  $this
    ->drupalGet('node/' . $this->page_home
    ->id() . '/delete');
  $this
    ->assertSession()
    ->statusCodeEquals(200);

  // Step 3: Logout, and login as user without the permission.
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this
    ->createUser([
    'delete any page content',
  ]));

  // Step 4: Try to delete the homepage.
  $this
    ->drupalGet('node/' . $this->page_home
    ->id() . '/delete');
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Step 5: Try to delete the non-homepage.
  $this
    ->drupalGet('node/' . $this->page_not_home
    ->id() . '/delete');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}