3 namespace Drupal\diff\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Base class for Diff web tests.
10 abstract class DiffTestBase extends WebTestBase {
17 public static $modules = [
24 * Permissions for the admin user.
28 protected $adminPermissions = [
29 'administer site configuration',
31 'administer content types',
32 'create article content',
33 'edit any article content',
34 'view article revisions',
38 * A user with content administrative permissions.
40 * @var \Drupal\user\UserInterface
47 protected function setUp() {
50 // Create the Article content type.
51 $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
53 // Place the blocks that Diff module uses.
54 $this->drupalPlaceBlock('local_tasks_block');
55 $this->drupalPlaceBlock('local_actions_block');
57 // Make sure HTML Diff is disabled.
58 $config = \Drupal::configFactory()->getEditable('diff.settings');
59 $config->set('general_settings.layout_plugins.visual_inline.enabled', FALSE)->save();
63 * Creates an user with admin permissions and log in.
65 * @param array $additional_permissions
66 * Additional permissions that will be granted to admin user.
67 * @param bool $reset_permissions
68 * Flag to determine if default admin permissions will be replaced by
69 * $additional_permissions.
71 * @return \Drupal\user\Entity\User|false
72 * Newly created and logged in user object.
74 protected function loginAsAdmin(array $additional_permissions = [], $reset_permissions = FALSE) {
75 $permissions = $this->adminPermissions;
77 if ($reset_permissions) {
78 $permissions = $additional_permissions;
80 elseif (!empty($additional_permissions)) {
81 $permissions = array_merge($permissions, $additional_permissions);
84 $this->adminUser = $this->drupalCreateUser($permissions);
85 $this->drupalLogin($this->adminUser);
86 return $this->adminUser;