Merge pull request #159 from lcdservices/master
[civicrm-core.git] / tests / phpunit / WebTest / Contact / DeceasedContactsAdvancedSearchTest.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
27
28require_once 'CiviTest/CiviSeleniumTestCase.php';
29class WebTest_Contact_DeceasedContactsAdvancedSearchTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testDeceasedContactsAdvanceSearch() {
36 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
38 // class attributes.
39 $this->open($this->sboxPath);
40
41 // Logging in. Remember to wait for page to load. In most cases,
42 // you can rely on 30000 as the value that allows your test to pass, however,
43 // sometimes your test might fail because of this. In such cases, it's better to pick one element
44 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
45 // page contents loaded and you can continue your test execution.
46 $this->webtestLogin();
47 $this->waitForPageToLoad($this->getTimeoutMsec());
48
49 // Create a group
50 $groupName = $this->WebtestAddGroup();
51
52 // Add contacts from the quick add block
53 $lastName = substr(sha1(rand()), 0, 7);
54 $names = array(
55 'firstName1' => FALSE,
56 'firstName2' => FALSE,
57 'firstName3' => FALSE,
58 'firstName4' => TRUE,
59 'firstName5' => TRUE,
60 );
61
62 foreach ($names as $key => $value) {
63 $$key = substr(sha1(rand()), 0, 7);
64 $this->_testAddContact($$key, $lastName, "{$$key}.{$lastName}@example.com", $groupName, $value);
65 }
66
67 // Advanced Search
d8bd5fb9 68 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
6a488035
TO
69
70 // Select the group and check deceased contacts
71 $this->select('crmasmSelect1', "label={$groupName}");
72 $this->click('demographics');
73 $this->waitForElementPresent('CIVICRM_QFID_1_is_deceased');
74 $this->click('CIVICRM_QFID_1_is_deceased');
75 $this->click('_qf_Advanced_refresh');
76 $this->waitForPageToLoad($this->getTimeoutMsec());
77
78 // Remove contacts from group
79 $this->waitForElementPresent('Go');
d8bd5fb9 80 $this->assertElementContainsText('search-status', '2 Contacts');
6a488035
TO
81 $this->click("toggleSelect");
82 $this->waitForTextPresent('2 Selected records only');
83
84 $this->select('task', 'label=Remove Contacts from Group');
85 $this->click("xpath=//div[@id='search-status']/table/tbody/tr[3]/td/ul/input[2]");
86 $this->waitForElementPresent('_qf_RemoveFromGroup_back-bottom');
d8bd5fb9 87 $this->assertElementContainsText('crm-container', 'Number of selected contacts: 2');
6a488035
TO
88 $this->select('group_id', "label={$groupName}");
89 $this->click('_qf_RemoveFromGroup_next-bottom');
90 $this->waitForPageToLoad($this->getTimeoutMsec());
d8bd5fb9 91 $this->assertElementContainsText('crm-notification-container', "2 contacts removed from '{$groupName}'");
6a488035
TO
92
93 // Search for the contacts who are not deceased
d8bd5fb9 94 $this->openCiviPage('contact/search/advanced', 'reset=1', '_qf_Advanced_refresh');
6a488035
TO
95 $this->select('crmasmSelect1', "label={$groupName}");
96 $this->click('_qf_Advanced_refresh');
97
98 // Check if non-deceased contacts are still present
99 $this->waitForElementPresent('Go');
d8bd5fb9 100 $this->assertElementContainsText('search-status', '3 Contacts');
6a488035
TO
101 }
102
103 function _testAddContact($firstName, $lastName, $email, $groupName, $deceased = FALSE) {
104 $this->webtestAddContact($firstName, $lastName, $email);
105 if ($deceased) {
106 $this->click('link=Edit');
107 $this->waitForElementPresent('_qf_Contact_cancel-bottom');
108
109 // Click on the Demographics tab
110 $this->click('demographics');
111 $this->waitForElementPresent('is_deceased');
112 $this->click('is_deceased');
113
114 // Click on Save
115 $this->click('_qf_Contact_upload_view-bottom');
116 $this->waitForPageToLoad($this->getTimeoutMsec());
117 }
118
119 // Add contact to group
120 $this->click('css=#tab_group a');
121 $this->waitForElementPresent('_qf_GroupContact_next');
122 $this->select('group_id', "{$groupName}");
123 $this->click('_qf_GroupContact_next');
124 $this->waitForPageToLoad($this->getTimeoutMsec());
125 }
126}
127