public function ContactLinkTest::testContactLink in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/contact/src/Tests/Views/ContactLinkTest.php \Drupal\contact\Tests\Views\ContactLinkTest::testContactLink()
Tests contact link.
File
- core/
modules/ contact/ src/ Tests/ Views/ ContactLinkTest.php, line 58 - Contains \Drupal\contact\Tests\Views\ContactLinkTest.
Class
- ContactLinkTest
- Tests the contact link field.
Namespace
Drupal\contact\Tests\ViewsCode
public function testContactLink() {
$accounts = array();
$accounts['root'] = User::load(1);
// Create an account with access to all contact pages.
$admin_account = $this
->drupalCreateUser(array(
'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(array(
'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 his own.
$this
->assertContactLinks($accounts, array(
'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, array());
$this
->drupalLogin($contact_account);
$this
->drupalGet('test-contact-link');
$this
->assertContactLinks($accounts, array(
'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, array(
'root',
'admin',
));
}