You are here

protected function ContactPersonalTest::checkContactAccess in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/contact/src/Tests/ContactPersonalTest.php \Drupal\contact\Tests\ContactPersonalTest::checkContactAccess()

Creates a user and then checks contact form access.

Parameters

int $response: The expected response code.

bool $contact_value: (optional) The value the contact field should be set too.

1 call to ContactPersonalTest::checkContactAccess()
ContactPersonalTest::testAdminContact in core/modules/contact/src/Tests/ContactPersonalTest.php
Tests the personal contact form based access when an admin adds users.

File

core/modules/contact/src/Tests/ContactPersonalTest.php, line 279
Contains \Drupal\contact\Tests\ContactPersonalTest.

Class

ContactPersonalTest
Tests personal contact form functionality.

Namespace

Drupal\contact\Tests

Code

protected function checkContactAccess($response, $contact_value = NULL) {
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/people/create');
  if ($this
    ->config('contact.settings')
    ->get('user_default_enabled', TRUE)) {
    $this
      ->assertFieldChecked('edit-contact--2');
  }
  else {
    $this
      ->assertNoFieldChecked('edit-contact--2');
  }
  $name = $this
    ->randomMachineName();
  $edit = array(
    'name' => $name,
    'mail' => $this
      ->randomMachineName() . '@example.com',
    'pass[pass1]' => $pass = $this
      ->randomString(),
    'pass[pass2]' => $pass,
    'notify' => FALSE,
  );
  if (isset($contact_value)) {
    $edit['contact'] = $contact_value;
  }
  $this
    ->drupalPostForm('admin/people/create', $edit, t('Create new account'));
  $user = user_load_by_name($name);
  $this
    ->drupalLogout();
  $this
    ->drupalGet('user/' . $user
    ->id() . '/contact');
  $this
    ->assertResponse($response);
}