You are here

function ProfileAccessTest::setUp in Profile 2 8

Sets up a Drupal site for running functional and integration tests.

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Overrides WebTestBase::setUp

File

src/Tests/ProfileAccessTest.php, line 27
Contains \Drupal\profile\Tests\ProfileAccessTest.

Class

ProfileAccessTest
Tests profile access handling.

Namespace

Drupal\profile\Tests

Code

function setUp() {
  parent::setUp();
  $this->type = entity_create('profile_type', array(
    'id' => 'test',
    'label' => 'Test profile',
  ));
  $this->type
    ->save();
  $id = $this->type
    ->id();
  $this->field = array(
    'field_name' => 'profile_fullname',
    'entity_type' => 'profile',
    'type' => 'text',
    'cardinality' => 1,
    'translatable' => FALSE,
  );
  $this->field = FieldStorageConfig::create($this->field);
  $this->field
    ->save();
  $instance = array(
    'entity_type' => $this->field
      ->get('entity_type'),
    'field_name' => $this->field
      ->get('field_name'),
    'bundle' => $this->type
      ->id(),
    'label' => 'Full name',
    'widget' => array(
      'type' => 'text_textfield',
    ),
  );
  $instance = FieldConfig::create($instance);
  $instance
    ->save();
  $display = entity_get_display('profile', 'test', 'default')
    ->setComponent($this->field
    ->get('field_name'), array(
    'type' => 'text_default',
  ));
  $display
    ->save();
  entity_get_display('profile', 'test', 'default')
    ->setComponent($this->field
    ->get('field_name'), array(
    'type' => 'text_default',
  ))
    ->save();
  entity_get_form_display('profile', 'test', 'default')
    ->setComponent($this->field
    ->get('field_name'), array(
    'type' => 'string_textfield',
  ))
    ->save();
  $this
    ->checkPermissions(array(), TRUE);
  user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array(
    'access user profiles',
  ));
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer profile types',
    "view any {$id} profile",
    "add any {$id} profile",
    "edit any {$id} profile",
    "delete any {$id} profile",
  ));
}