Commit | Line | Data |
---|---|---|
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 | ||
28 | require_once 'CiviTest/CiviSeleniumTestCase.php'; | |
29 | class WebTest_Contact_ContactReferenceFieldTest extends CiviSeleniumTestCase { | |
30 | ||
31 | protected function setUp() { | |
32 | parent::setUp(); | |
33 | } | |
34 | ||
35 | function testContactReferenceField() { | |
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 | ||
48 | ||
49 | /* add new group */ | |
50 | ||
d8bd5fb9 | 51 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload'); |
6a488035 TO |
52 | |
53 | $groupName = 'group_' . substr(sha1(rand()), 0, 7); | |
54 | $this->type("title", $groupName); | |
55 | ||
56 | // fill description | |
57 | $this->type("description", "Adding new group."); | |
58 | ||
59 | // check Access Control | |
60 | $this->click("group_type[1]"); | |
61 | ||
62 | // Clicking save. | |
63 | $this->click("_qf_Edit_upload"); | |
64 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
65 | ||
66 | /* add contacts */ | |
67 | ||
68 | // Individual 1 | |
69 | $contact1 = substr(sha1(rand()), 0, 7); | |
70 | $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com"); | |
71 | ||
72 | // Add Individual 1 to group | |
73 | $this->click('css=li#tab_group a'); | |
74 | $this->waitForElementPresent('_qf_GroupContact_next'); | |
75 | $this->select('group_id', "label={$groupName}"); | |
76 | $this->click('_qf_GroupContact_next'); | |
77 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
78 | $this->assertElementContainsText('crm-notification-container', "Added to Group"); | |
79 | ||
80 | // Individual 1 | |
81 | $contact2 = substr(sha1(rand()), 0, 7); | |
82 | $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com"); | |
83 | ||
84 | // Organization 1 | |
85 | $org1 = 'org_' . substr(sha1(rand()), 0, 5); | |
86 | $this->webtestAddOrganization($org1, "{$org1}@example.com"); | |
87 | ||
88 | /* create custom group and fields */ | |
89 | ||
90 | // Add Custom group // | |
91 | // Go directly to the URL of the screen that you will be testing (New Custom Group). | |
d8bd5fb9 | 92 | $this->openCiviPage('admin/custom/group', 'action=add&reset=1'); |
6a488035 TO |
93 | |
94 | //fill custom group title | |
95 | $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7); | |
96 | $this->click("title"); | |
97 | $this->type("title", $customGroupTitle); | |
98 | ||
99 | //custom group extends | |
100 | $this->click("extends[0]"); | |
101 | $this->select("extends[0]", "value=Contact"); | |
102 | $this->click("//option[@value='Contact']"); | |
103 | $this->click("_qf_Group_next-bottom"); | |
104 | $this->waitForElementPresent("_qf_Field_cancel-bottom"); | |
105 | ||
106 | //Is custom group created? | |
d8bd5fb9 | 107 | $this->assertElementContainsText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
6a488035 TO |
108 | |
109 | $matches = array(); | |
110 | preg_match('/gid=([0-9]+)/', $this->getLocation(), $matches); | |
111 | $customGroupId = $matches[1]; | |
112 | ||
113 | // Add contact reference fields | |
114 | $contactRefFieldLabel1 = 'contact_ref_' . substr(sha1(rand()), 0, 4); | |
115 | $this->click("label"); | |
116 | $this->type("label", $contactRefFieldLabel1); | |
117 | $this->select("data_type[0]", "label=Contact Reference"); | |
118 | ||
119 | $this->waitForElementPresent("group_id"); | |
120 | $this->select("group_id", $groupName); | |
121 | ||
122 | //clicking save | |
123 | $this->click("_qf_Field_next_new-bottom"); | |
124 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
125 | ||
126 | //Is custom field created? | |
d8bd5fb9 | 127 | $this->assertElementContainsText('crm-notification-container', "Your custom field '$contactRefFieldLabel1' has been saved."); |
6a488035 TO |
128 | |
129 | //add custom field - alphanumeric checkbox | |
130 | $contactRefFieldLabel2 = 'contact_ref_' . substr(sha1(rand()), 0, 4); | |
131 | $this->click("label"); | |
132 | $this->type("label", $contactRefFieldLabel2); | |
133 | $this->select("data_type[0]", "label=Contact Reference"); | |
134 | ||
135 | $this->waitForElementPresent("group_id"); | |
136 | $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']"); | |
137 | $this->waitForElementPresent("filter"); | |
138 | ||
139 | $this->type("filter", "action=lookup&contact_type=Organization"); | |
140 | ||
141 | //clicking save | |
142 | $this->click("_qf_Field_next-bottom"); | |
143 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
144 | ||
145 | //Is custom field created? | |
d8bd5fb9 | 146 | $this->assertElementContainsText('crm-notification-container', "Your custom field '$contactRefFieldLabel2' has been saved."); |
6a488035 | 147 | |
d8bd5fb9 | 148 | $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}"); |
6a488035 TO |
149 | |
150 | $this->click("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[8]/span[1]/a[text()='Edit Field']"); | |
151 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
152 | ||
153 | $matches = array(); | |
154 | preg_match('/&id=([0-9]+)/', $this->getLocation(), $matches); | |
155 | $contactRefFieldID1 = $matches[1]; | |
156 | ||
157 | ||
d8bd5fb9 | 158 | $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}"); |
6a488035 TO |
159 | |
160 | $this->click("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/span[1]/a[text()='Edit Field']"); | |
161 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
162 | ||
163 | $matches = array(); | |
164 | preg_match('/&id=([0-9]+)/', $this->getLocation(), $matches); | |
165 | $contactRefFieldID2 = $matches[1]; | |
166 | ||
167 | // Visit custom group preview page | |
d8bd5fb9 | 168 | $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}"); |
6a488035 TO |
169 | |
170 | $this->type("custom_{$contactRefFieldID1}_-1", "Anderson"); | |
171 | $this->fireEvent("custom_{$contactRefFieldID1}_-1", "focus"); | |
172 | $this->click("custom_{$contactRefFieldID1}_-1"); | |
173 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
d8bd5fb9 RN |
174 | $this->assertElementContainsText("css=div.ac_results-inner li", "{$contact1}@example.com"); |
175 | $this->assertElementNotContainsText("css=div.ac_results-inner ul li", "{$contact2}@example.com"); | |
6a488035 TO |
176 | |
177 | ||
d8bd5fb9 | 178 | $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}"); |
6a488035 TO |
179 | |
180 | $this->type("custom_{$contactRefFieldID2}_-1", $org1); | |
181 | $this->fireEvent("custom_{$contactRefFieldID2}_-1", "focus"); | |
182 | $this->click("custom_{$contactRefFieldID2}_-1"); | |
183 | $this->waitForElementPresent("css=div.ac_results-inner li"); | |
d8bd5fb9 | 184 | $this->assertElementContainsText("css=div.ac_results-inner li", "{$org1}@example.com"); |
6a488035 TO |
185 | } |
186 | } | |
187 |