Commit 1a53cd14 authored by alexpott's avatar alexpott

Issue #2030743 by yingtho, runeasgar, marcingy, YesCT, damiankloip, larowlan,...

Issue #2030743 by yingtho, runeasgar, marcingy, YesCT, damiankloip, larowlan, typhonius, dman, areke, Désiré: Improve tests for user form alters in contact module.
parent 50327552
......@@ -52,7 +52,7 @@ function setUp() {
$this->admin_user = $this->drupalCreateUser(array('administer contact forms', 'administer users', 'administer account settings', 'access site reports'));
// Create some normal users with their contact forms enabled by default.
\Drupal::config('contact.settings')->set('user_default_enabled', 1)->save();
\Drupal::config('contact.settings')->set('user_default_enabled', TRUE)->save();
$this->web_user = $this->drupalCreateUser(array('access user contact forms'));
$this->contact_user = $this->drupalCreateUser();
}
......@@ -216,6 +216,55 @@ function testPersonalContactFlood() {
$this->assertNoText('Try again later.', 'Admin user not denied access to flooded contact form.');
}
/**
* Tests the personal contact form based access when an admin adds users.
*/
function testAdminContact() {
user_role_grant_permissions(DRUPAL_ANONYMOUS_RID, array('access user contact forms'));
$this->checkContactAccess(200);
$this->checkContactAccess(403, FALSE);
$config = \Drupal::config('contact.settings');
$config->set('user_default_enabled', FALSE);
$config->save();
$this->checkContactAccess(403);
}
/**
* Creates a user and then checks contact form access.
*
* @param integer $response
* The expected response code.
* @param boolean $contact_value
* (optional) The value the contact field should be set too.
*/
protected function checkContactAccess($response, $contact_value = NULL) {
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/people/create');
if (\Drupal::config('contact.settings')->get('user_default_enabled', TRUE)) {
$this->assertFieldChecked('edit-contact--2');
}
else {
$this->assertNoFieldChecked('edit-contact--2');
}
$name = $this->randomName();
$edit = array(
'name' => $name,
'mail' => $this->randomName() . '@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);
}
/**
* Fills out a user's personal contact form and submits it.
*
......
......@@ -21,7 +21,7 @@ class UserCreateTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('image', 'contact');
public static $modules = array('image');
/**
* Create a user through the administration interface and ensure that it
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment