RabbitHoleBehaviorInvocationTestBase.php in Rabbit Hole 2.x
File
tests/src/Functional/RabbitHoleBehaviorInvocationTestBase.php
View source
<?php
namespace Drupal\Tests\rabbit_hole\Functional;
use Drupal\Tests\BrowserTestBase;
abstract class RabbitHoleBehaviorInvocationTestBase extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'rabbit_hole',
];
protected $behaviorSettingsManager;
protected function setUp() {
parent::setUp();
$this->behaviorSettingsManager = $this->container
->get('rabbit_hole.behavior_settings_manager');
$this
->drupalLogin($this
->drupalCreateUser($this
->getViewPermissions()));
}
public function testEntityDefaults() {
$this
->createEntityBundle();
$entity = $this
->createEntity();
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(200);
}
public function testDefaultToBundle() {
$this
->createEntityBundle('access_denied');
$entity = $this
->createEntity();
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(403);
$entity2 = $this
->createEntity('bundle_default');
$this
->drupalGet($entity2
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(403);
}
public function testPageNotFound() {
$this
->createEntityBundle();
$entity = $this
->createEntity('page_not_found');
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(404);
}
public function testAccessDenied() {
$this
->createEntityBundle();
$entity = $this
->createEntity('access_denied');
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(403);
}
public function testDisplayPage() {
$this
->createEntityBundle('access_denied');
$entity = $this
->createEntity('display_page');
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(200);
}
public function testPageRedirect() {
$this
->createEntityBundle();
$destination_path = $this
->createEntity('display_page')
->toUrl('canonical', [
'absolute' => TRUE,
])
->toString();
$entity = $this
->createEntity('page_redirect');
$entity
->set('rh_redirect', $destination_path);
$entity
->set('rh_redirect_response', 301);
$entity
->save();
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->addressEquals($destination_path);
}
public function testRabbitHoleBypassPermissions() {
$this
->drupalLogin($this
->createUser(array_merge($this
->getViewPermissions(), [
'rabbit hole bypass ' . $this->entityType,
])));
$this
->createEntityBundle();
$entity = $this
->createEntity('page_not_found');
$this
->drupalGet($entity
->toUrl()
->toString());
$this
->assertSession()
->statusCodeEquals(200);
}
protected abstract function createEntityBundle($action = NULL);
protected abstract function createEntity($action = NULL);
protected function getViewPermissions() {
return [];
}
}