NodeBehaviorSettingsFormTest.php in Rabbit Hole 8
File
modules/rh_node/tests/src/Functional/NodeBehaviorSettingsFormTest.php
View source
<?php
namespace Drupal\Tests\rh_node\Functional;
use Drupal\Core\Url;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\rabbit_hole\Functional\RabbitHoleBehaviorSettingsFormTestBase;
class NodeBehaviorSettingsFormTest extends RabbitHoleBehaviorSettingsFormTestBase {
use NodeCreationTrait;
use ContentTypeCreationTrait;
protected $bundle;
protected $entityType = 'node';
protected $bundleEntityTypeName = 'node_type';
public static $modules = [
'rh_node',
'node',
];
public function testBundleCreationWithFieldUi() {
\Drupal::service('module_installer')
->install([
'field_ui',
]);
$this
->testBundleCreation();
}
public function testBundleEditWithFieldUi() {
\Drupal::service('module_installer')
->install([
'field_ui',
]);
$this
->testBundleFormFirstSave();
}
protected function createEntityBundle() {
$this->bundle = $this
->drupalCreateContentType([
'type' => mb_strtolower($this
->randomMachineName()),
]);
return $this->bundle
->id();
}
protected function createEntityBundleFormSubmit($action, $override) {
$this
->drupalLogin($this->adminUser);
$edit = [
'name' => $this
->randomString(),
'type' => mb_strtolower($this
->randomMachineName()),
'rh_action' => $action,
'rh_override' => $override,
];
$this
->drupalGet(Url::fromRoute('node.type_add'));
$this
->assertRabbitHoleSettings();
$button_label = \Drupal::moduleHandler()
->moduleExists('field_ui') ? 'Save and manage fields' : 'Save content type';
$this
->submitForm($edit, $button_label);
$this->bundle = $this
->loadBundle($edit['type']);
return $edit['type'];
}
protected function createEntity($action = NULL) {
$values = [
'type' => $this->bundle
->id(),
'title' => $this
->randomString(),
];
if (isset($action)) {
$values['rh_action'] = $action;
}
return $this
->drupalCreateNode($values)
->id();
}
protected function getCreateEntityUrl() {
return Url::fromRoute('node.add_page');
}
protected function getEditEntityUrl($id) {
return Url::fromRoute('entity.node.edit_form', [
'node' => $id,
]);
}
protected function getEditBundleUrl($bundle) {
return Url::fromRoute('entity.node_type.edit_form', [
'node_type' => $bundle,
]);
}
protected function getAdminPermissions() {
return [
'bypass node access',
'administer content types',
];
}
}