You are here

trait ProfileCreationTrait in Linkit 8.5

Provides methods to create profiles based on default settings.

This trait is meant to be used only by test classes.

Hierarchy

6 files declare their use of ProfileCreationTrait
LinkitControllerTest.php in tests/src/Functional/Controller/LinkitControllerTest.php
LinkitDialogTest.php in tests/src/FunctionalJavascript/LinkitDialogTest.php
LinkitEditorLinkDialogTest.php in tests/src/Kernel/LinkitEditorLinkDialogTest.php
MatcherAdminTest.php in tests/src/Functional/MatcherAdminTest.php
ProfileAdminTest.php in tests/src/Functional/ProfileAdminTest.php

... See full list

File

src/Tests/ProfileCreationTrait.php, line 12

Namespace

Drupal\linkit\Tests
View source
trait ProfileCreationTrait {

  /**
   * Creates a profile based on default settings.
   *
   * @param array $settings
   *   (optional) An associative array of settings for the profile, as used in
   *   entity_create(). Override the defaults by specifying the key and value
   *   in the array.
   *   The following defaults are provided:
   *   - id: Random string.
   *   - label: Random string.
   *
   * @return \Drupal\linkit\ProfileInterface
   *   The created profile entity.
   */
  protected function createProfile(array $settings = []) {

    // Populate defaults array.
    $settings += [
      'id' => mb_strtolower($this
        ->randomMachineName()),
      'label' => $this
        ->randomMachineName(),
    ];
    $profile = Profile::create($settings);
    $profile
      ->save();
    $profile = Profile::load($profile
      ->id());
    return $profile;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ProfileCreationTrait::createProfile protected function Creates a profile based on default settings.