3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Contact_TaskActionAddToGroupTest
32 class WebTest_Contact_TaskActionAddToGroupTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testAddContactsToGroup() {
40 $this->webtestLogin();
41 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
42 $this->WebtestAddGroup($newGroupName);
44 // Create two new contacts with a common random string in email address
45 $emailString = substr(sha1(rand()), 0, 7) . '@example.com_';
47 for ($i = 0; $i < 2; $i++
) {
49 $this->webtestAddContact();
51 // get cid of new contact
52 $cids[] = $this->urlArg('cid');
54 // update email of new contact
55 $this->waitForElementPresent("//ul[@id='actions']/li/a/span[text()='Edit']");
56 $this->click("//ul[@id='actions']/li/a/span[text()='Edit']");
57 $this->waitForPageToLoad($this->getTimeoutMsec());
58 $this->type("email_1_email", $emailString . $i . 'webtest');
59 $this->click("_qf_Contact_upload_view");
60 $this->waitForPageToLoad($this->getTimeoutMsec());
63 // goto advanced search
64 $this->openCiviPage("contact/search/advanced", "reset=1", "email");
66 $this->type("email", $emailString);
67 $this->click("_qf_Advanced_refresh");
68 $this->waitForPageToLoad($this->getTimeoutMsec());
70 // Verify exactly two contacts found
71 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString);
73 // Click "check all" box and act on "Add to group" action
74 $this->click('toggleSelect');
75 $this->select("task", "label=Add Contacts to Group");
76 // Because it tends to cause problems, all uses of sleep() must be justified in comments
77 // Sleep should never be used for wait for anything to load from the server
78 // Justification for this instance: FIXME
81 $this->waitForPageToLoad($this->getTimeoutMsec());
83 // Select the new group and click to add
84 $this->click("group_id");
85 $this->select("group_id", "label=" . $newGroupName);
86 $this->click("_qf_AddToGroup_next-bottom");
87 $this->waitForPageToLoad($this->getTimeoutMsec());
89 // Check status messages are as expected
90 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
91 $this->waitForText('crm-notification-container', "2 contacts added to group");
93 // Search by group membership in newly created group
94 $this->openCiviPage('contact/search/advanced', 'reset=1');
95 $this->select("group", "label=" . $newGroupName);
96 $this->click("_qf_Advanced_refresh");
97 $this->waitForPageToLoad($this->getTimeoutMsec());
99 // Verify those two contacts (and only those two) are in the group
100 if (!$this->isTextPresent("2 Contacts")) {
101 die("nothing found for group $newGroupName");
104 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName);
105 foreach ($cids as $cid) {
106 $this->assertTrue($this->isElementPresent('rowid' . $cid));
111 function testMultiplePageContactSearchAddContactsToGroup() {
112 $this->webtestLogin();
113 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
114 $this->WebtestAddGroup($newGroupName);
116 $this->openCiviPage('contact/search', 'reset=1');
117 $this->click("_qf_Basic_refresh");
118 $this->waitForPageToLoad($this->getTimeoutMsec());
120 $this->type("xpath=//*[@id='Basic-rows-per-page-select']", '25');
121 $this->waitForElementPresent("toggleSelect");
122 $this->click("toggleSelect");
123 $this->click("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a");
124 $this->waitForText("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a", "First");
125 $this->click("toggleSelect");
126 $this->select("task", "label=Add Contacts to Group");
128 $this->waitForPageToLoad($this->getTimeoutMsec());
130 // Select the new group and click to add
131 $this->click("group_id");
132 $this->select("group_id", "label=" . $newGroupName);
133 $this->click("_qf_AddToGroup_next-bottom");
134 $this->waitForPageToLoad($this->getTimeoutMsec());
136 // Check status messages are as expected
137 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
138 $this->waitForText('crm-notification-container', "50 contacts added to group");
140 $this->openCiviPage('contact/search/advanced', 'reset=1');
141 $this->select("group", "label=" . $newGroupName);
142 $this->click("_qf_Advanced_refresh");
143 $this->waitForPageToLoad($this->getTimeoutMsec());
145 $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName);