You are here

protected function ContactPersonalTest::checkContactAccess in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\ContactPersonalTest::checkContactAccess()
  2. 10 core/modules/contact/tests/src/Functional/ContactPersonalTest.php \Drupal\Tests\contact\Functional\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/tests/src/Functional/ContactPersonalTest.php
Tests the personal contact form based access when an admin adds users.

File

core/modules/contact/tests/src/Functional/ContactPersonalTest.php, line 305

Class

ContactPersonalTest
Tests personal contact form functionality.

Namespace

Drupal\Tests\contact\Functional

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
      ->assertSession()
      ->checkboxChecked('edit-contact--2');
  }
  else {
    $this
      ->assertSession()
      ->checkboxNotChecked('edit-contact--2');
  }
  $name = $this
    ->randomMachineName();
  $edit = [
    '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
    ->drupalGet('admin/people/create');
  $this
    ->submitForm($edit, 'Create new account');
  $user = user_load_by_name($name);
  $this
    ->drupalLogout();
  $this
    ->drupalGet('user/' . $user
    ->id() . '/contact');
  $this
    ->assertSession()
    ->statusCodeEquals($response);
}