fixed merge conflicts
[civicrm-core.git] / tests / phpunit / WebTest / Contact / DeceasedContactsAdvancedSearchTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Contact_DeceasedContactsAdvancedSearchTest
31 */
32 class WebTest_Contact_DeceasedContactsAdvancedSearchTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 public function testDeceasedContactsAdvanceSearch() {
39 $this->webtestLogin();
40 $this->waitForPageToLoad($this->getTimeoutMsec());
41
42 // Create a group
43 $groupName = $this->WebtestAddGroup();
44
45 // Add contacts from the quick add block
46 $lastName = substr(sha1(rand()), 0, 7);
47 $names = array(
48 'firstName1' => FALSE,
49 'firstName2' => FALSE,
50 'firstName3' => FALSE,
51 'firstName4' => TRUE,
52 'firstName5' => TRUE,
53 );
54
55 foreach ($names as $key => $value) {
56 $$key = substr(sha1(rand()), 0, 7);
57 $this->_testAddContact($$key, $lastName, "{$$key}.{$lastName}@example.com", $groupName, $value);
58 }
59
60 // Advanced Search
61 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
62
63 // Select the group and check deceased contacts
64 $this->select('group', "label={$groupName}");
65 $this->click('demographics');
66 $this->waitForElementPresent('CIVICRM_QFID_1_is_deceased');
67 $this->click('CIVICRM_QFID_1_is_deceased');
68 $this->clickLink('_qf_Advanced_refresh');
69 $this->assertElementContainsText('search-status', '2 Contacts');
70 $this->click("toggleSelect");
71 $this->waitForTextPresent('2 Selected records only');
72
73 $this->select('task', 'label=Group - remove contacts');
74 $this->waitForPageToLoad($this->getTimeoutMsec());
75 $this->waitForElementPresent('_qf_RemoveFromGroup_back-bottom');
76 $this->assertElementContainsText('crm-container', 'Number of selected contacts: 2');
77 $this->select('group_id', "label={$groupName}");
78 $this->click('_qf_RemoveFromGroup_next-bottom');
79 $this->waitForPageToLoad($this->getTimeoutMsec());
80 $this->waitForText('crm-notification-container', "2 contacts removed from '{$groupName}'");
81
82 // Search for the contacts who are not deceased
83 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
84 $this->select('group', "label={$groupName}");
85 $this->click('_qf_Advanced_refresh');
86
87 // Check if non-deceased contacts are still present
88 $this->waitForElementPresent('search-status');
89 $this->assertElementContainsText('search-status', '3 Contacts');
90 }
91
92 /**
93 * @param string $firstName
94 * @param string $lastName
95 * @param $email
96 * @param string $groupName
97 * @param bool $deceased
98 */
99 public function _testAddContact($firstName, $lastName, $email, $groupName, $deceased = FALSE) {
100 $this->webtestAddContact($firstName, $lastName, $email);
101 if ($deceased) {
102 $this->click('link=Edit');
103 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
104
105 // Click on the Demographics tab
106 $this->click('demographics');
107 $this->waitForElementPresent('is_deceased');
108 $this->click('is_deceased');
109
110 // Click on Save
111 $this->click('_qf_Contact_upload_view-bottom');
112 $this->waitForPageToLoad($this->getTimeoutMsec());
113 }
114
115 // Add contact to group
116 $this->click('css=#tab_group a');
117 $this->waitForElementPresent('_qf_GroupContact_next');
118 $this->select('group_id', "{$groupName}");
119 $this->click('_qf_GroupContact_next');
120 }
121
122 }