summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Pott2014-07-11 13:16:29 (GMT)
committerAlex Pott2014-07-11 13:16:29 (GMT)
commit1a53cd14ed261cdfd67633fc94f247a2168f2e44 (patch)
treefd71d1d9cc8b87b31f4d4e36b2d321c32bdf8d4f
parent50327552d58e976bf8af4759376058be0b3f3a77 (diff)
Issue #2030743 by yingtho, runeasgar, marcingy, YesCT, damiankloip, larowlan, typhonius, dman, areke, Désiré: Improve tests for user form alters in contact module.
-rw-r--r--core/modules/contact/src/Tests/ContactPersonalTest.php51
-rw-r--r--core/modules/user/src/Tests/UserCreateTest.php2
2 files changed, 51 insertions, 2 deletions
diff --git a/core/modules/contact/src/Tests/ContactPersonalTest.php b/core/modules/contact/src/Tests/ContactPersonalTest.php
index 4be01ac..6f3e2f1 100644
--- a/core/modules/contact/src/Tests/ContactPersonalTest.php
+++ b/core/modules/contact/src/Tests/ContactPersonalTest.php
@@ -52,7 +52,7 @@ class ContactPersonalTest extends WebTestBase {
$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();
}
@@ -217,6 +217,55 @@ class ContactPersonalTest extends WebTestBase {
}
/**
+ * 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.
*
* @param $account
diff --git a/core/modules/user/src/Tests/UserCreateTest.php b/core/modules/user/src/Tests/UserCreateTest.php
index 6531d40..b049560 100644
--- a/core/modules/user/src/Tests/UserCreateTest.php
+++ b/core/modules/user/src/Tests/UserCreateTest.php
@@ -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