Fix some uses of sleep, comment the rest
[civicrm-core.git] / tests / phpunit / WebTest / Contact / TaskActionAddToGroupTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25 */
26
27
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29 class WebTest_Contact_TaskActionAddToGroupTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testAddContactsToGroup() {
36
37 $this->webtestLogin();
38 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
39 $this->WebtestAddGroup($newGroupName);
40
41 // Create two new contacts with a common random string in email address
42 $emailString = substr(sha1(rand()), 0, 7) . '@example.com_';
43 $cids = array();
44 for ($i = 0; $i < 2; $i++) {
45 // create new contact
46 $this->webtestAddContact();
47
48 // get cid of new contact
49 $queryParams = $this->parseURL();
50 $cids[] = $queryParams['queryString']['cid'];
51
52 // update email of new contact
53 $this->click("//ul[@id='actions']/li/a/span[text()='Edit']");
54 $this->waitForPageToLoad($this->getTimeoutMsec());
55 $this->type("email_1_email", $emailString . $i . 'webtest');
56 $this->click("_qf_Contact_upload_view");
57 $this->waitForPageToLoad($this->getTimeoutMsec());
58 }
59
60 // goto advanced search
61 $this->openCiviPage("contact/search/advanced", "reset=1", "email");
62
63 $this->type("email", $emailString);
64 $this->click("_qf_Advanced_refresh");
65 $this->waitForPageToLoad($this->getTimeoutMsec());
66
67 // Verify exactly two contacts found
68 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString);
69
70 // Click "check all" box and act on "Add to group" action
71 $this->click('toggleSelect');
72 $this->select("task", "label=Add Contacts to Group");
73 // Because it tends to cause problems, all uses of sleep() must be justified in comments
74 // Sleep should never be used for wait for anything to load from the server
75 // Justification for this instance: FIXME
76 sleep(1);
77 $this->click("Go");
78 $this->waitForPageToLoad($this->getTimeoutMsec());
79
80 // Select the new group and click to add
81 $this->click("group_id");
82 $this->select("group_id", "label=" . $newGroupName);
83 $this->click("_qf_AddToGroup_next-bottom");
84 $this->waitForPageToLoad($this->getTimeoutMsec());
85
86 // Check status messages are as expected
87 $this->assertElementContainsText('crm-notification-container', "Added Contacts to {$newGroupName}");
88 $this->assertElementContainsText('crm-notification-container', "2 contacts added to group");
89
90 // Search by group membership in newly created group
91 $this->openCiviPage('contact/search/advanced', 'reset=1');
92 $this->select("crmasmSelect1", "label=" . $newGroupName);
93 $this->click("_qf_Advanced_refresh");
94 $this->waitForPageToLoad($this->getTimeoutMsec());
95
96 // Verify those two contacts (and only those two) are in the group
97 if (!$this->isTextPresent("2 Contacts")) {
98 die("nothing found for group $newGroupName");
99 }
100
101 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName);
102 foreach ($cids as $cid) {
103 $this->assertTrue($this->isElementPresent('rowid' . $cid));
104 }
105
106 }
107
108 function testMultiplePageContactSearchAddContactsToGroup() {
109 $this->webtestLogin();
110 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
111 $this->WebtestAddGroup($newGroupName);
112
113 $this->openCiviPage('contact/search', 'reset=1');
114 $this->click("_qf_Basic_refresh");
115 $this->waitForPageToLoad($this->getTimeoutMsec());
116
117 $this->click("xpath=//div[@class='form-item float-right']/a[text()='25']");
118 $this->waitForPageToLoad($this->getTimeoutMsec());
119 $this->click("toggleSelect");
120 $this->click("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a");
121 $this->waitForPageToLoad($this->getTimeoutMsec());
122 $this->click("toggleSelect");
123 $this->select("task", "label=Add Contacts to Group");
124 $this->click("Go");
125 $this->waitForPageToLoad($this->getTimeoutMsec());
126
127 // Select the new group and click to add
128 $this->click("group_id");
129 $this->select("group_id", "label=" . $newGroupName);
130 $this->click("_qf_AddToGroup_next-bottom");
131 $this->waitForPageToLoad($this->getTimeoutMsec());
132
133 // Check status messages are as expected
134 $this->assertElementContainsText('crm-notification-container', "Added Contacts to {$newGroupName}");
135 $this->assertElementContainsText('crm-notification-container', "50 contacts added to group");
136
137 $this->openCiviPage('contact/search/advanced', 'reset=1');
138 $this->select("crmasmSelect1", "label=" . $newGroupName);
139 $this->click("_qf_Advanced_refresh");
140 $this->waitForPageToLoad($this->getTimeoutMsec());
141
142 $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName);
143 }
144 }
145
146