3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 public 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->click("xpath=//ul[@id='actions']/li[2]/a");
56 $this->waitForPageToLoad($this->getTimeoutMsec());
57 $this->type("email_1_email", $emailString . $i . 'webtest');
58 $this->click("_qf_Contact_upload_view");
59 $this->waitForPageToLoad($this->getTimeoutMsec());
62 // goto advanced search
63 $this->openCiviPage("contact/search/advanced", "reset=1", "email");
65 $this->type("email", $emailString);
66 $this->click("_qf_Advanced_refresh");
67 $this->waitForPageToLoad($this->getTimeoutMsec());
69 // Verify exactly two contacts found
70 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString);
72 // Click "check all" box and act on "Add to group" action
73 $this->click('toggleSelect');
74 $this->waitForText("xpath=//input[@value='ts_sel']/following-sibling::label/span", '2');
75 $this->select("task", "label=Group - add contacts");
76 $this->waitForPageToLoad($this->getTimeoutMsec());
78 // Select the new group and click to add
79 $this->click("group_id");
80 $this->select("group_id", "label=" . $newGroupName);
81 $this->click("_qf_AddToGroup_next-bottom");
82 $this->waitForPageToLoad($this->getTimeoutMsec());
84 // Check status messages are as expected
85 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
86 $this->waitForText('crm-notification-container', "2 contacts added to group");
88 // Search by group membership in newly created group
89 $this->openCiviPage('contact/search/advanced', 'reset=1');
90 $this->select("group", "label=" . $newGroupName);
91 $this->click("_qf_Advanced_refresh");
92 $this->waitForPageToLoad($this->getTimeoutMsec());
94 // Verify those two contacts (and only those two) are in the group
95 if (!$this->isTextPresent("2 Contacts")) {
96 die("nothing found for group $newGroupName");
99 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName);
100 foreach ($cids as $cid) {
101 $this->assertTrue($this->isElementPresent('rowid' . $cid));
106 public function testMultiplePageContactSearchAddContactsToGroup() {
107 $this->webtestLogin();
108 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
109 $this->WebtestAddGroup($newGroupName);
111 $this->openCiviPage('contact/search', 'reset=1');
112 $this->clickLink("_qf_Basic_refresh");
113 $this->waitForElementPresent("xpath=//*[@id='CRM_Contact_Form_Search_Basic-rows-per-page-select']");
114 $this->type("xpath=//*[@id='CRM_Contact_Form_Search_Basic-rows-per-page-select']", '25');
115 $this->waitForElementPresent("toggleSelect");
116 $this->click("toggleSelect");
117 $this->waitForAjaxContent();
118 $this->waitForText("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a", "Next >");
119 $this->click("toggleSelect");
120 $this->waitForAjaxContent();
121 $this->waitForText("xpath=//input[@value='ts_sel']/following-sibling::label/span", '50');
122 $this->select("task", "label=Group - add contacts");
123 $this->waitForPageToLoad($this->getTimeoutMsec());
125 // Select the new group and click to add
126 $this->waitForElementPresent("group_id");
127 $this->click("group_id");
128 $this->select("group_id", "label=" . $newGroupName);
129 $this->click("_qf_AddToGroup_next-bottom");
131 // Check status messages are as expected
132 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
133 $this->waitForText('crm-notification-container', "50 contacts added to group");
135 $this->openCiviPage('contact/search/advanced', 'reset=1');
136 $this->select("group", "label=" . $newGroupName);
137 $this->click("_qf_Advanced_refresh");
138 $this->waitForPageToLoad($this->getTimeoutMsec());
140 $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName);