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