Fix AddressParsingTest
[civicrm-core.git] / tests / phpunit / WebTest / Contact / TaskActionAddToGroupTest.php
CommitLineData
6a488035
TO
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
6a488035
TO
27require_once 'CiviTest/CiviSeleniumTestCase.php';
28class WebTest_Contact_TaskActionAddToGroupTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testAddContactsToGroup() {
35
69369531 36 $this->webtestLogin();
6a488035
TO
37 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
38 $this->WebtestAddGroup($newGroupName);
39
40 // Create two new contacts with a common random string in email address
41 $emailString = substr(sha1(rand()), 0, 7) . '@example.com_';
42 $cids = array();
43 for ($i = 0; $i < 2; $i++) {
44 // create new contact
45 $this->webtestAddContact();
46
47 // get cid of new contact
48 $queryParams = $this->parseURL();
49 $cids[] = $queryParams['queryString']['cid'];
50
51 // update email of new contact
52 $this->click("//ul[@id='actions']/li/a/span[text()='Edit']");
53 $this->waitForPageToLoad($this->getTimeoutMsec());
54 $this->type("email_1_email", $emailString . $i . 'webtest');
55 $this->click("_qf_Contact_upload_view");
56 $this->waitForPageToLoad($this->getTimeoutMsec());
57 }
58
59 // goto advanced search
60 $this->openCiviPage("contact/search/advanced", "reset=1", "email");
61
62 $this->type("email", $emailString);
63 $this->click("_qf_Advanced_refresh");
64 $this->waitForPageToLoad($this->getTimeoutMsec());
65
66 // Verify exactly two contacts found
67 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results with email like ' . $emailString);
68
69 // Click "check all" box and act on "Add to group" action
70 $this->click('toggleSelect');
71 $this->select("task", "label=Add Contacts to Group");
efb29358
CW
72 // Because it tends to cause problems, all uses of sleep() must be justified in comments
73 // Sleep should never be used for wait for anything to load from the server
74 // Justification for this instance: FIXME
6a488035
TO
75 sleep(1);
76 $this->click("Go");
77 $this->waitForPageToLoad($this->getTimeoutMsec());
78
79 // Select the new group and click to add
80 $this->click("group_id");
81 $this->select("group_id", "label=" . $newGroupName);
82 $this->click("_qf_AddToGroup_next-bottom");
83 $this->waitForPageToLoad($this->getTimeoutMsec());
84
85 // Check status messages are as expected
69369531
RN
86 $this->assertElementContainsText('crm-notification-container', "Added Contacts to {$newGroupName}");
87 $this->assertElementContainsText('crm-notification-container', "2 contacts added to group");
6a488035
TO
88
89 // Search by group membership in newly created group
90 $this->openCiviPage('contact/search/advanced', 'reset=1');
91 $this->select("crmasmSelect1", "label=" . $newGroupName);
92 $this->click("_qf_Advanced_refresh");
93 $this->waitForPageToLoad($this->getTimeoutMsec());
94
95 // Verify those two contacts (and only those two) are in the group
96 if (!$this->isTextPresent("2 Contacts")) {
97 die("nothing found for group $newGroupName");
98 }
99
100 $this->assertTrue($this->isTextPresent("2 Contacts"), 'Looking for 2 results belonging to group: ' . $newGroupName);
101 foreach ($cids as $cid) {
102 $this->assertTrue($this->isElementPresent('rowid' . $cid));
103 }
104
105 }
106
107 function testMultiplePageContactSearchAddContactsToGroup() {
69369531 108 $this->webtestLogin();
6a488035
TO
109 $newGroupName = 'Group_' . substr(sha1(rand()), 0, 7);
110 $this->WebtestAddGroup($newGroupName);
111
112 $this->openCiviPage('contact/search', 'reset=1');
113 $this->click("_qf_Basic_refresh");
114 $this->waitForPageToLoad($this->getTimeoutMsec());
115
116 $this->click("xpath=//div[@class='form-item float-right']/a[text()='25']");
117 $this->waitForPageToLoad($this->getTimeoutMsec());
118 $this->click("toggleSelect");
119 $this->click("xpath=//div[@class='crm-content-block']/div/div[2]/div/span[2]/a");
120 $this->waitForPageToLoad($this->getTimeoutMsec());
121 $this->click("toggleSelect");
122 $this->select("task", "label=Add Contacts to Group");
123 $this->click("Go");
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125
126 // Select the new group and click to add
127 $this->click("group_id");
128 $this->select("group_id", "label=" . $newGroupName);
129 $this->click("_qf_AddToGroup_next-bottom");
130 $this->waitForPageToLoad($this->getTimeoutMsec());
131
132 // Check status messages are as expected
69369531
RN
133 $this->assertElementContainsText('crm-notification-container', "Added Contacts to {$newGroupName}");
134 $this->assertElementContainsText('crm-notification-container', "50 contacts added to group");
6a488035
TO
135
136 $this->openCiviPage('contact/search/advanced', 'reset=1');
137 $this->select("crmasmSelect1", "label=" . $newGroupName);
138 $this->click("_qf_Advanced_refresh");
139 $this->waitForPageToLoad($this->getTimeoutMsec());
140
141 $this->assertTrue($this->isTextPresent("50 Contacts"), 'Looking for 50 results belonging to group: ' . $newGroupName);
142 }
143}
144