function ContactLinkTest::testContactLink

Same name in other branches
  1. 9 core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php \Drupal\Tests\contact\Functional\Views\ContactLinkTest::testContactLink()
  2. 8.9.x core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php \Drupal\Tests\contact\Functional\Views\ContactLinkTest::testContactLink()
  3. 10 core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php \Drupal\Tests\contact\Functional\Views\ContactLinkTest::testContactLink()

Tests contact link.

File

core/modules/contact/tests/src/Functional/Views/ContactLinkTest.php, line 55

Class

ContactLinkTest
Tests the contact link field.

Namespace

Drupal\Tests\contact\Functional\Views

Code

public function testContactLink() : void {
    $accounts = [];
    $accounts['root'] = User::load(1);
    // Create an account with access to all contact pages.
    $admin_account = $this->drupalCreateUser([
        'administer users',
    ]);
    $accounts['admin'] = $admin_account;
    // Create an account with no access to contact pages.
    $no_contact_account = $this->drupalCreateUser();
    $accounts['no_contact'] = $no_contact_account;
    // Create an account with access to contact pages.
    $contact_account = $this->drupalCreateUser([
        'access user contact forms',
    ]);
    $accounts['contact'] = $contact_account;
    $this->drupalLogin($admin_account);
    $this->drupalGet('test-contact-link');
    // The admin user has access to all contact links beside their own.
    $this->assertContactLinks($accounts, [
        'root',
        'no_contact',
        'contact',
    ]);
    $this->drupalLogin($no_contact_account);
    $this->drupalGet('test-contact-link');
    // Ensure that the user without the permission doesn't see any link.
    $this->assertContactLinks($accounts, []);
    $this->drupalLogin($contact_account);
    $this->drupalGet('test-contact-link');
    $this->assertContactLinks($accounts, [
        'root',
        'admin',
        'no_contact',
    ]);
    // Disable contact link for no_contact.
    $this->userData
        ->set('contact', $no_contact_account->id(), 'enabled', FALSE);
    // @todo Remove cache invalidation in https://www.drupal.org/node/2477903.
    Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
    $this->drupalGet('test-contact-link');
    $this->assertContactLinks($accounts, [
        'root',
        'admin',
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.