DeleteHomepageTest.php in Prevent homepage deletion 8
File
tests/src/Functional/DeleteHomepageTest.php
View source
<?php
namespace Drupal\Tests\prevent_homepage_deletion\Functional;
use Drupal\Tests\BrowserTestBase;
class DeleteHomepageTest extends BrowserTestBase {
public static $modules = [
'node',
'user',
'prevent_homepage_deletion',
];
protected $defaultTheme = 'stark';
protected $contentType;
protected $page_home;
protected $page_not_home;
protected function setUp() {
parent::setUp();
$this->contentType = $this
->createContentType([
'type' => 'page',
]);
$this->page_home = $this
->drupalCreateNode([
'type' => 'page',
]);
\Drupal::configFactory()
->getEditable('system.site')
->set('page.front', '/node/' . $this->page_home
->id())
->save(TRUE);
$this->page_not_home = $this
->drupalCreateNode([
'type' => 'page',
]);
}
public function testDeleteHomepage() {
$this
->drupalLogin($this
->createUser([
'delete any page content',
'delete_homepage_node',
]));
$this
->drupalGet('node/' . $this->page_home
->id() . '/delete');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalLogout();
$this
->drupalLogin($this
->createUser([
'delete any page content',
]));
$this
->drupalGet('node/' . $this->page_home
->id() . '/delete');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalGet('node/' . $this->page_not_home
->id() . '/delete');
$this
->assertSession()
->statusCodeEquals(200);
}
}