You are here

trait DomainConfigUITestTrait in Domain Access 8

Contains helper classes for tests to set up various configuration.

Hierarchy

5 files declare their use of DomainConfigUITestTrait
DomainConfigUIOptionsTest.php in domain_config_ui/tests/src/Functional/DomainConfigUIOptionsTest.php
DomainConfigUIOverrideTest.php in domain_config_ui/tests/src/FunctionalJavascript/DomainConfigUIOverrideTest.php
DomainConfigUIPermissionsTest.php in domain_config_ui/tests/src/Functional/DomainConfigUIPermissionsTest.php
DomainConfigUiSavedConfigTest.php in domain_config_ui/tests/src/FunctionalJavascript/DomainConfigUiSavedConfigTest.php
DomainConfigUISettingsTest.php in domain_config_ui/tests/src/FunctionalJavascript/DomainConfigUISettingsTest.php

File

domain_config_ui/tests/src/Traits/DomainConfigUITestTrait.php, line 8

Namespace

Drupal\Tests\domain_config_ui\Traits
View source
trait DomainConfigUITestTrait {

  /**
   * A user with full permissions to use the module.
   *
   * @var Drupal\Core\Session\AccountInterface
   */
  protected $adminUser;

  /**
   * A user with access administration but not this module.
   *
   * @var Drupal\Core\Session\AccountInterface
   */
  protected $editorUser;

  /**
   * A user with access to domains but not language.
   *
   * @var Drupal\Core\Session\AccountInterface
   */
  protected $limitedUser;

  /**
   * A user with permission to domains and language.
   *
   * @var Drupal\Core\Session\AccountInterface
   */
  protected $languageUser;

  /**
   * Create an admin user.
   */
  public function createAdminUser() {
    $this->adminUser = $this
      ->drupalCreateUser([
      'access administration pages',
      'access content',
      'administer domains',
      'administer domain config ui',
      'administer site configuration',
      'administer languages',
      'administer themes',
      'set default domain configuration',
      'translate domain configuration',
      'use domain config ui',
      'view domain information',
    ]);
  }

  /**
   * Create an editor user.
   */
  public function createEditorUser() {
    $this->editorUser = $this
      ->drupalCreateUser([
      'access administration pages',
      'access content',
      'administer site configuration',
      'administer languages',
    ]);
  }

  /**
   * Create a limited admin user.
   */
  public function createLimitedUser() {
    $this->limitedUser = $this
      ->drupalCreateUser([
      'access administration pages',
      'administer languages',
      'administer site configuration',
      'use domain config ui',
      'set default domain configuration',
    ]);
  }

  /**
   * Create a language administrator.
   */
  public function createLanguageUser() {
    $this->languageUser = $this
      ->drupalCreateUser([
      'access administration pages',
      'use domain config ui',
      'translate domain configuration',
      'administer site configuration',
    ]);
  }

  /**
   * Creates a second language for testing overrides.
   */
  public function createLanguage() {

    // Create and login user.
    $adminUser = $this
      ->drupalCreateUser([
      'administer languages',
      'access administration pages',
    ]);
    $this
      ->drupalLogin($adminUser);

    // Add language.
    $edit = [
      'predefined_langcode' => 'es',
    ];
    $this
      ->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

    // Enable URL language detection and selection.
    $edit = [
      'language_interface[enabled][language-url]' => '1',
    ];
    $this
      ->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
    $this
      ->drupalLogout();

    // In order to reflect the changes for a multilingual site in the container
    // we have to rebuild it.
    $this
      ->rebuildContainer();
    $es = \Drupal::entityTypeManager()
      ->getStorage('configurable_language')
      ->load('es');
    $this
      ->assertTrue(!empty($es), 'Created test language.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DomainConfigUITestTrait::$adminUser protected property A user with full permissions to use the module.
DomainConfigUITestTrait::$editorUser protected property A user with access administration but not this module.
DomainConfigUITestTrait::$languageUser protected property A user with permission to domains and language.
DomainConfigUITestTrait::$limitedUser protected property A user with access to domains but not language.
DomainConfigUITestTrait::createAdminUser public function Create an admin user.
DomainConfigUITestTrait::createEditorUser public function Create an editor user.
DomainConfigUITestTrait::createLanguage public function Creates a second language for testing overrides. 1
DomainConfigUITestTrait::createLanguageUser public function Create a language administrator.
DomainConfigUITestTrait::createLimitedUser public function Create a limited admin user.