| 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 | |
| 28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
| 29 | class WebTest_Contact_SearchTest extends CiviSeleniumTestCase { |
| 30 | |
| 31 | protected function setUp() { |
| 32 | parent::setUp(); |
| 33 | } |
| 34 | |
| 35 | function testQuickSearch() { |
| 36 | $this->webtestLogin(); |
| 37 | |
| 38 | // Adding contact |
| 39 | // We're using Quick Add block on the main page for this. |
| 40 | $firstName = substr(sha1(rand()), 0, 7); |
| 41 | $this->webtestAddContact($firstName, "Anderson", "$firstName.anderson@example.org"); |
| 42 | |
| 43 | $sortName = "Anderson, $firstName"; |
| 44 | $displayName = "$firstName Anderson"; |
| 45 | |
| 46 | $this->open($this->sboxPath . "civicrm/dashboard?reset=1"); |
| 47 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 48 | |
| 49 | // type sortname in autocomplete |
| 50 | $this->click("css=input#sort_name_navigation"); |
| 51 | $this->type("css=input#sort_name_navigation", $sortName); |
| 52 | $this->typeKeys("css=input#sort_name_navigation", $sortName); |
| 53 | |
| 54 | // wait for result list |
| 55 | $this->waitForElementPresent("css=div.ac_results-inner li"); |
| 56 | |
| 57 | // visit contact summary page |
| 58 | $this->click("css=div.ac_results-inner li"); |
| 59 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 60 | |
| 61 | // Is contact present? |
| 62 | $this->assertTrue($this->isTextPresent("$displayName"), "Contact did not find!"); |
| 63 | } |
| 64 | |
| 65 | function testQuickSearchPartial() { |
| 66 | $this->webtestLogin(); |
| 67 | |
| 68 | // Adding contact |
| 69 | // We're using Quick Add block on the main page for this. |
| 70 | $firstName = substr(sha1(rand()), 0, 7); |
| 71 | $this->webtestAddContact($firstName, "Adams", "{$firstName}.adams@example.org"); |
| 72 | |
| 73 | $sortName = "Adams, {$firstName}"; |
| 74 | |
| 75 | $this->open($this->sboxPath . "civicrm/dashboard?reset=1"); |
| 76 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 77 | |
| 78 | // type partial sortname in autocomplete |
| 79 | $this->click("css=input#sort_name_navigation"); |
| 80 | $this->type("css=input#sort_name_navigation", 'ada'); |
| 81 | $this->typeKeys("css=input#sort_name_navigation", 'ada'); |
| 82 | |
| 83 | $this->click("_qf_Basic_refresh"); |
| 84 | |
| 85 | // wait for result list |
| 86 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 87 | // make sure we're on search results page |
| 88 | $this->waitForElementPresent("alpha-filter"); |
| 89 | // wait for bottom of page to load (access is in footer) |
| 90 | $this->waitForElementPresent("access"); |
| 91 | |
| 92 | // Is contact present in search result? |
| 93 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName); |
| 94 | } |
| 95 | |
| 96 | function testContactSearch() { |
| 97 | $this->webtestLogin(); |
| 98 | |
| 99 | // Create new tag. |
| 100 | $tagName = 'tag_' . substr(sha1(rand()), 0, 7); |
| 101 | self::addTag($tagName, $this); |
| 102 | |
| 103 | // Create new group |
| 104 | $groupName = 'group_' . substr(sha1(rand()), 0, 7); |
| 105 | $this->WebtestAddGroup($groupName); |
| 106 | |
| 107 | // Adding contact |
| 108 | // We're using Quick Add block on the main page for this. |
| 109 | $firstName = substr(sha1(rand()), 0, 7); |
| 110 | $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org"); |
| 111 | |
| 112 | $sortName = "Smith, $firstName"; |
| 113 | $displayName = "$firstName Smith"; |
| 114 | |
| 115 | // add contact to group |
| 116 | // visit group tab |
| 117 | $this->click("css=li#tab_group a"); |
| 118 | $this->waitForElementPresent("group_id"); |
| 119 | |
| 120 | // add to group |
| 121 | $this->select("group_id", "label=$groupName"); |
| 122 | $this->click("_qf_GroupContact_next"); |
| 123 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 124 | |
| 125 | // tag a contact |
| 126 | // visit tag tab |
| 127 | $this->click("css=li#tab_tag a"); |
| 128 | $this->waitForElementPresent("css=div#tagtree"); |
| 129 | |
| 130 | // select tag |
| 131 | $this->click("xpath=//ul/li/label[text()=\"$tagName\"]"); |
| 132 | $this->waitForElementPresent("css=.success"); |
| 133 | |
| 134 | // visit contact search page |
| 135 | $this->open($this->sboxPath . "civicrm/contact/search?reset=1"); |
| 136 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 137 | |
| 138 | // fill name as first_name |
| 139 | $this->type("css=.crm-basic-criteria-form-block input#sort_name", $firstName); |
| 140 | |
| 141 | // select contact type as Indiividual |
| 142 | $this->select("contact_type", "value=Individual"); |
| 143 | |
| 144 | // select group |
| 145 | $this->select("group", "label=$groupName"); |
| 146 | |
| 147 | // select tag |
| 148 | $this->select("tag", "label=$tagName"); |
| 149 | |
| 150 | // click to search |
| 151 | $this->click("_qf_Basic_refresh"); |
| 152 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 153 | |
| 154 | // Is contact present in search result? |
| 155 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * This code is reused with advanced search, hence the reference to $self |
| 160 | * |
| 161 | * @static |
| 162 | */ |
| 163 | static function addTag($tagName = 'New Tag', $self) { |
| 164 | $self->openCiviPage('admin/tag', array('reset' => 1, 'action' => 'add'), '_qf_Tag_next'); |
| 165 | |
| 166 | // fill tag name |
| 167 | $self->type("name", $tagName); |
| 168 | |
| 169 | // fill description |
| 170 | $self->type("description", "Adding new tag."); |
| 171 | |
| 172 | // select used for contact |
| 173 | $self->select("used_for", "value=civicrm_contact"); |
| 174 | |
| 175 | // check reserved |
| 176 | $self->click("is_reserved"); |
| 177 | |
| 178 | // Clicking save. |
| 179 | $self->click("_qf_Tag_next"); |
| 180 | $self->waitForPageToLoad($self->getTimeoutMsec()); |
| 181 | |
| 182 | // Is status message correct? |
| 183 | $self->assertTrue($self->isTextPresent("The tag '$tagName' has been saved.")); |
| 184 | } |
| 185 | |
| 186 | // CRM-6586 |
| 187 | function testContactSearchExport() { |
| 188 | $this->webtestLogin(); |
| 189 | |
| 190 | // Create new group |
| 191 | $parentGroupName = 'Parentgroup_' . substr(sha1(rand()), 0, 7); |
| 192 | $this->WebtestAddGroup($parentGroupName); |
| 193 | |
| 194 | // Create new group and select the previously selected group as parent group for this new group. |
| 195 | $childGroupName = 'Childgroup_' . substr(sha1(rand()), 0, 7); |
| 196 | $this->WebtestAddGroup($childGroupName, $parentGroupName); |
| 197 | |
| 198 | |
| 199 | // Adding Parent group contact |
| 200 | $firstName = substr(sha1(rand()), 0, 7); |
| 201 | $this->webtestAddContact($firstName, "Smith", "$firstName.smith@example.org"); |
| 202 | |
| 203 | $sortName = "Smith, $firstName"; |
| 204 | $displayName = "$firstName Smith"; |
| 205 | |
| 206 | // add contact to parent group |
| 207 | // visit group tab |
| 208 | $this->click("css=li#tab_group a"); |
| 209 | $this->waitForElementPresent("group_id"); |
| 210 | |
| 211 | // add to group |
| 212 | $this->select("group_id", "label=$parentGroupName"); |
| 213 | $this->click("_qf_GroupContact_next"); |
| 214 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 215 | |
| 216 | // Adding child group contact |
| 217 | // We're using Quick Add block on the main page for this. |
| 218 | $childName = substr(sha1(rand()), 0, 7); |
| 219 | $this->webtestAddContact($childName, "John", "$childName.john@example.org"); |
| 220 | |
| 221 | $childSortName = "John, $childName"; |
| 222 | $childDisplayName = "$childName John"; |
| 223 | |
| 224 | // add contact to child group |
| 225 | // visit group tab |
| 226 | $this->click("css=li#tab_group a"); |
| 227 | $this->waitForElementPresent("group_id"); |
| 228 | |
| 229 | // add to child group |
| 230 | $this->select("group_id", "*$childGroupName"); |
| 231 | $this->click("_qf_GroupContact_next"); |
| 232 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 233 | |
| 234 | |
| 235 | // visit contact search page |
| 236 | $this->open($this->sboxPath . "civicrm/contact/search?reset=1"); |
| 237 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 238 | |
| 239 | |
| 240 | // select contact type as Indiividual |
| 241 | $this->select("contact_type", "value=Individual"); |
| 242 | |
| 243 | // select group |
| 244 | $this->select("group", "label=$parentGroupName"); |
| 245 | |
| 246 | // click to search |
| 247 | $this->click("_qf_Basic_refresh"); |
| 248 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 249 | |
| 250 | // Is contact present in search result? |
| 251 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $sortName); |
| 252 | $this->assertElementContainsText('css=.crm-search-results > table.row-highlight', $childSortName); |
| 253 | |
| 254 | // select to export all the contasct from search result |
| 255 | $this->click("CIVICRM_QFID_ts_all_4"); |
| 256 | |
| 257 | // Select the task action to export |
| 258 | $this->click("task"); |
| 259 | $this->select("task", "label=Export Contacts"); |
| 260 | $this->click("Go"); |
| 261 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 262 | |
| 263 | $this->click("_qf_Select_next-bottom"); |
| 264 | } |
| 265 | } |