Refactor ad-hoc url parsing to use the new urlArg() method
[civicrm-core.git] / tests / phpunit / WebTest / Profile / SearchTest.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_Profile_SearchTest extends CiviSeleniumTestCase {
29
30 protected function setUp() {
31 parent::setUp();
32 }
33
34 function testSearchProfile() {
6a488035
TO
35 $this->webtestLogin();
36
6a488035 37 // Add new profile.
305515fb 38 $this->openCiviPage('admin/uf/group', 'reset=1');
76e86fd8 39
6a488035
TO
40 $this->click('newCiviCRMProfile-bottom');
41
42 $this->waitForElementPresent('_qf_Group_next-bottom');
43
44 //Name of profile
45 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
46 $this->type('title', $profileTitle);
47
48 //click on save
49 $this->click('_qf_Group_next-bottom');
50 $this->waitForPageToLoad($this->getTimeoutMsec());
51
52 //check for profile create
6c5f7368 53 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
6a488035
TO
54
55 // Get profile id (gid) from URL
a471a3b6 56 $profileId = $this->urlArg('gid');
6a488035
TO
57
58 // Add Last Name field.
59 $this->click('field_name[0]');
60 $this->select('field_name[0]', 'value=Individual');
61 $this->click('field_name[1]');
62 $this->select('field_name[1]', 'value=last_name');
63 $this->click("//option[@value='Individual']");
64 $this->click('visibility');
65 $this->select('visibility', 'value=Public Pages');
66 $this->click('is_searchable');
67 $this->click('in_selector');
68 // click on save
69 $this->click('_qf_Field_next_new-bottom');
70 $this->waitForPageToLoad($this->getTimeoutMsec());
71 //check for field add
6c5f7368
CW
72 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Last Name' has been saved to '$profileTitle'.");
73 $this->waitForText('crm-notification-container', 'You can add another profile field.');
305515fb 74
6a488035
TO
75 // Add Email field.
76 $this->click('field_name[0]');
77 $this->select('field_name[0]', 'value=Contact');
78 $this->click('field_name[1]');
79 $this->select('field_name[1]', 'value=email');
80 $this->click("//option[@value='Contact']");
81 $this->click('visibility');
82 $this->select('visibility', 'value=Public Pages');
83 $this->click('is_searchable');
84 $this->click('in_selector');
85 // click on save
86 $this->click('_qf_Field_next_new-bottom');
87 $this->waitForPageToLoad($this->getTimeoutMsec());
88 //check for field add
6c5f7368
CW
89 $this->waitForText('crm-notification-container', "Your CiviCRM Profile Field 'Email' has been saved to '$profileTitle'.");
90 $this->waitForText('crm-notification-container', 'You can add another profile field.');
6a488035
TO
91
92 // Add Sample Custom Field.
93 $this->click('field_name[0]');
94 $this->select('field_name[0]', 'value=Individual');
95 $this->click('field_name[1]');
96 $this->select('field_name[1]', 'value=custom_1');
97 $this->click("//option[@value='Individual']");
98 $this->click('visibility');
99 $this->select('visibility', 'value=Public Pages');
100 $this->click('is_searchable');
101 $this->click('in_selector');
102 // click on save
225a8648 103 $this->clickLink('_qf_Field_next-bottom', "xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']");
6a488035
TO
104 $this->click("xpath=//div[@id='field_page']/div[1]/a[4]/span[text()='Use (create mode)']");
105
106 $this->waitForElementPresent('_qf_Edit_next');
107 $lastName = substr(sha1(rand()), 0, 7);
108
109 // Fill Last Name
110 $this->type('last_name', $lastName);
111 // Fill Email
112 $this->type('email-Primary', "jhon@$lastName.com");
113 // Select Custom option
114 $this->click('CIVICRM_QFID_Edu_2');
115 $this->click('_qf_Edit_next');
305515fb
PJ
116 $this->waitForPageToLoad($this->getTimeoutMsec());
117
118 $this->assertElementContainsText('css=span.msg-text', 'Your information has been saved.');
6a488035
TO
119
120 // Search Contact via profile.
121 $this->waitForElementPresent("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
122 $this->click("xpath=//div[@id='crm-container']//div/a[text()='» Back to Listings']");
123 $this->waitForElementPresent("xpath=//div[@class='crm-block crm-form-block']");
124 $this->click("xpath=//div[@class='crm-block crm-form-block']");
125 // Fill Last Name
126 $this->type('last_name', $lastName);
127 // Fill Email
128 $this->type('email-Primary', "jhon@$lastName.com");
129 // Select Custom option
130 $this->click('CIVICRM_QFID_Edu_2');
131 $this->click('_qf_Search_refresh');
305515fb 132 $this->waitForPageToLoad($this->getTimeoutMsec());
6a488035
TO
133
134 // Verify Data.
305515fb
PJ
135 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[2][text()='$lastName']"));
136 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[3][text()='$lastName']"));
137 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[4][text()='jhon@$lastName.com']"));
138 $this->assertTrue($this->isElementPresent("xpath=//table/tbody/tr[2]/td[5][text()='Education']"));
6a488035
TO
139
140 // Go back to Profile fields admin
305515fb 141 $this->openCiviPage('admin/uf/group/field', "reset=1&action=browse&gid=$profileId");
6a488035
TO
142
143 // Edit first profile field
144 $this->waitForElementPresent("xpath=//table/tbody/tr[1]/td[9]");
225a8648 145 $this->clickLink("xpath=//table/tbody/tr[1]/td[9]/span[1]/a[1]", '_qf_Field_next-bottom');
6a488035
TO
146
147 // sleep 5 to make sure jQuery is not hiding field after page load
efb29358
CW
148 // Because it tends to cause problems, all uses of sleep() must be justified in comments
149 // Sleep should never be used for wait for anything to load from the server
150 // Justification for this instance: FIXME
6a488035
TO
151 sleep(5);
152 $this->assertTrue($this->isElementPresent("visibility"), 'Visibility field not present when editing existing profile field.');
153 $this->click("xpath=//tr[@id='profile_visibility']/td[1]/a");
154 $this->waitForElementPresent("xpath=//div[@id='crm-notification-container']/div/div[2]/p[2]");
6c5f7368 155 $this->waitForText('crm-notification-container', 'Is this field hidden from other users');
6a488035
TO
156 $this->select('visibility', 'value=Public Pages and Listings');
157 }
42daf119 158}