GroupBehaviorSettingsFormTest.php in Rabbit Hole 2.x
File
modules/rh_group/tests/src/Functional/GroupBehaviorSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\rh_group\Functional;
use Drupal\Core\Url;
use Drupal\Tests\rabbit_hole\Functional\RabbitHoleBehaviorSettingsFormTestBase;
class GroupBehaviorSettingsFormTest extends RabbitHoleBehaviorSettingsFormTestBase {
protected $bundle;
protected $entityType = 'group';
protected $bundleEntityTypeName = 'group_type';
public static $modules = [
'rh_group',
'group',
];
protected function createEntityBundle() {
$storage = \Drupal::entityTypeManager()
->getStorage('group_type');
$group_type = $storage
->create([
'id' => mb_strtolower($this
->randomMachineName()),
'label' => $this
->randomString(),
]);
$storage
->save($group_type);
$this->bundle = $group_type;
return $group_type
->id();
}
protected function createEntityBundleFormSubmit($action, $override) {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('/admin/group/types/add');
$this
->assertSession()
->statusCodeEquals(200);
$submit_button = 'Save group type';
$this
->assertSession()
->buttonExists($submit_button);
$this
->assertRabbitHoleSettings();
$edit = [
'label' => $this
->randomString(),
'id' => mb_strtolower($this
->randomMachineName()),
'rh_action' => $action,
'rh_override' => $override,
];
$this
->submitForm($edit, $submit_button);
$this->bundle = $this
->loadBundle($edit['id']);
return $edit['id'];
}
protected function createEntity($action = NULL) {
$values = [];
if (isset($action)) {
$values['rh_action'] = $action;
}
$storage = \Drupal::entityTypeManager()
->getStorage('group');
$group = $storage
->create($values + [
'type' => $this->bundle
->id(),
'label' => $this
->randomString(),
]);
$group
->enforceIsNew();
$storage
->save($group);
return $group
->id();
}
protected function getCreateEntityUrl() {
return Url::fromRoute('entity.group.add_form', [
'group_type' => $this->bundle
->id(),
]);
}
protected function getEditEntityUrl($id) {
return Url::fromRoute('entity.group.edit_form', [
'group' => $id,
]);
}
protected function getEditBundleUrl($bundle) {
return Url::fromRoute('entity.group_type.edit_form', [
'group_type' => $bundle,
]);
}
protected function getAdminPermissions() {
return [
'administer group',
'bypass group access',
'access group overview',
];
}
}