Merge pull request #9560 from aydun/CRM-19754
[civicrm-core.git] / tests / phpunit / WebTest / Contact / TaskActionAddToGroupTest.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
81621fee 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
15a4309a 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 25 */
6a488035 26
6a488035 27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Contact_TaskActionAddToGroupTest
31 */
6a488035
TO
32class WebTest_Contact_TaskActionAddToGroupTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
00be9182 38 public function testAddContactsToGroup() {
6a488035 39
69369531 40 $this->webtestLogin();
6a488035
TO
41 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
42 $this->WebtestAddGroup($newGroupName);
43
44 // Create two new contacts with a common random string in email address
bf333c47 45 $emailString = substr(sha1(rand()), 0, 7) . '@example.com';
6a488035
TO
46 $cids = array();
47 for ($i = 0; $i < 2; $i++) {
48 // create new contact
49 $this->webtestAddContact();
50
51 // get cid of new contact
a471a3b6 52 $cids[] = $this->urlArg('cid');
6a488035
TO
53
54 // update email of new contact
03b0e225 55 $this->click("xpath=//ul[@id='actions']/li[2]/a");
6a488035
TO
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());
60 }
61
62 // goto advanced search
63 $this->openCiviPage("contact/search/advanced", "reset=1", "email");
64
65 $this->type("email", $emailString);
66 $this->click("_qf_Advanced_refresh");
67 $this->waitForPageToLoad($this->getTimeoutMsec());
68
69 // Verify exactly two contacts found
70 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString);
71
72 // Click "check all" box and act on "Add to group" action
4ea7e2aa 73 $this->waitForAjaxContent();
6a488035 74 $this->click('toggleSelect');
4ea7e2aa 75 $this->waitForAjaxContent();
bf333c47 76 $this->waitForText("xpath=//input[@value='ts_sel']/following-sibling::label/span", '2');
4ea7e2aa 77 $this->waitForAjaxContent();
7f82e636 78 $this->select("task", "label=Group - add contacts");
6a488035
TO
79 $this->waitForPageToLoad($this->getTimeoutMsec());
80
81 // Select the new group and click to add
82 $this->click("group_id");
83 $this->select("group_id", "label=" . $newGroupName);
84 $this->click("_qf_AddToGroup_next-bottom");
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86
87 // Check status messages are as expected
6c5f7368
CW
88 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
89 $this->waitForText('crm-notification-container', "2 contacts added to group");
6a488035
TO
90
91 // Search by group membership in newly created group
92 $this->openCiviPage('contact/search/advanced', 'reset=1');
c900afb1 93 $this->select("group", "label=" . $newGroupName);
6a488035
TO
94 $this->click("_qf_Advanced_refresh");
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96
97 // Verify those two contacts (and only those two) are in the group
98 if (!$this->isTextPresent("2 Contacts")) {
99 die("nothing found for group $newGroupName");
100 }
101
102 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName);
103 foreach ($cids as $cid) {
104 $this->assertTrue($this->isElementPresent('rowid' . $cid));
105 }
106
107 }
108
00be9182 109 public function testMultiplePageContactSearchAddContactsToGroup() {
69369531 110 $this->webtestLogin();
6a488035
TO
111 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
112 $this->WebtestAddGroup($newGroupName);
113
114 $this->openCiviPage('contact/search', 'reset=1');
beea38fc 115 $this->clickLink("_qf_Basic_refresh");
dd055b5e 116 $this->waitForElementPresent("xpath=//*[@id='CRM_Contact_Form_Search_Basic-rows-per-page-select']");
bf333c47 117 $this->type("xpath=//*[@id='CRM_Contact_Form_Search_Basic-rows-per-page-select']", '25');
c900afb1 118 $this->waitForElementPresent("toggleSelect");
6a488035 119 $this->click("toggleSelect");
dd055b5e 120 $this->waitForAjaxContent();
45d22844 121 $this->waitForText("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a", "Next >");
6a488035 122 $this->click("toggleSelect");
dd055b5e 123 $this->waitForAjaxContent();
bf333c47 124 $this->waitForText("xpath=//input[@value='ts_sel']/following-sibling::label/span", '50');
7f82e636 125 $this->select("task", "label=Group - add contacts");
6a488035
TO
126 $this->waitForPageToLoad($this->getTimeoutMsec());
127
6c6e6187 128 // Select the new group and click to add
dd055b5e 129 $this->waitForElementPresent("group_id");
6a488035
TO
130 $this->click("group_id");
131 $this->select("group_id", "label=" . $newGroupName);
132 $this->click("_qf_AddToGroup_next-bottom");
6a488035
TO
133
134 // Check status messages are as expected
6c5f7368
CW
135 $this->waitForText('crm-notification-container', "Added Contacts to {$newGroupName}");
136 $this->waitForText('crm-notification-container', "50 contacts added to group");
6a488035
TO
137
138 $this->openCiviPage('contact/search/advanced', 'reset=1');
c900afb1 139 $this->select("group", "label=" . $newGroupName);
6a488035
TO
140 $this->click("_qf_Advanced_refresh");
141 $this->waitForPageToLoad($this->getTimeoutMsec());
142
143 $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName);
144 }
96025800 145
6a488035 146}