Merge remote-tracking branch 'origin/4.4' into 4.4-4.5-2014-09-14-13-58-42
[civicrm-core.git] / tests / phpunit / WebTest / Contact / ContactReferenceFieldTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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
29 /**
30 * Class WebTest_Contact_ContactReferenceFieldTest
31 */
32 class WebTest_Contact_ContactReferenceFieldTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testContactReferenceField() {
39 $this->webtestLogin();
40
41 /* add new group */
42
43 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload');
44
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46 $this->type("title", $groupName);
47
48 // fill description
49 $this->type("description", "Adding new group.");
50
51 // check Access Control
52 $this->click("group_type[1]");
53
54 // Clicking save.
55 $this->click("_qf_Edit_upload");
56 $this->waitForPageToLoad($this->getTimeoutMsec());
57
58 /* add contacts */
59
60 // Individual 1
61 $contact1 = substr(sha1(rand()), 0, 7);
62 $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com");
63
64 // Add Individual 1 to group
65 $this->click('css=li#tab_group a');
66 $this->waitForElementPresent('_qf_GroupContact_next');
67 $this->select('group_id', "label={$groupName}");
68 $this->click('_qf_GroupContact_next');
69 $this->waitForText('crm-notification-container', "Added to Group");
70
71 // Individual 1
72 $contact2 = substr(sha1(rand()), 0, 7);
73 $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com");
74
75 // Organization 1
76 $org1 = 'org_' . substr(sha1(rand()), 0, 5);
77 $this->webtestAddOrganization($org1, "{$org1}@example.com");
78
79 /* create custom group and fields */
80
81 // Add Custom group //
82
83 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
84
85 //fill custom group title
86 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
87 $this->click("title");
88 $this->type("title", $customGroupTitle);
89
90 //custom group extends
91 $this->click("extends[0]");
92 $this->select("extends[0]", "value=Contact");
93 $this->click("//option[@value='Contact']");
94 $this->click("_qf_Group_next-bottom");
95 $this->waitForElementPresent("newCustomField");
96
97 //Is custom group created?
98 $this->click("newCustomField");
99 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
100
101 $customGroupId = $this->urlArg('gid');
102
103 // Add contact reference fields
104 $contactRefFieldLabel1 = 'contact_ref_' . substr(sha1(rand()), 0, 4);
105 $this->waitForElementPresent("label");
106 $this->click("label");
107 $this->waitForElementPresent("label");
108 $this->type("label", $contactRefFieldLabel1);
109 $this->waitForElementPresent("data_type[0]");
110 $this->select("data_type[0]", "label=Contact Reference");
111
112 $this->waitForElementPresent("group_id");
113 $this->select("group_id", $groupName);
114
115 //clicking save
116 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]/");
117
118 //Is custom field created?
119 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel1' has been saved.");
120 $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]/");
121 //add custom field - alphanumeric checkbox
122 $contactRefFieldLabel2 = 'contact_ref_' . substr(sha1(rand()), 0, 4);
123
124 $this->click("label");
125 $this->waitForElementPresent("label");
126 $this->type("label", $contactRefFieldLabel2);
127 $this->waitForElementPresent("data_type[0]");
128 $this->select("data_type[0]", "label=Contact Reference");
129
130 $this->waitForElementPresent("group_id");
131 $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']");
132 $this->waitForElementPresent("filter");
133
134 $this->type("filter", "action=get&contact_type=Organization");
135
136 //clicking save
137 $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]/");
138
139 //Is custom field created?
140 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel2' has been saved.");
141
142 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
143
144 $fieldid1 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[8]/span[1]/a[text()='Edit Field']@href"));
145 $fieldid1 = $fieldid1[1];
146
147 $contactRefFieldID1 = $fieldid1;
148
149 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
150
151 $fieldid2 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/span[1]/a[text()='Edit Field']@href"));
152 $fieldid2 = $fieldid2[1];
153
154 $contactRefFieldID2 = $fieldid2;
155
156 // Visit custom group preview page
157 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
158
159 $this->clickAt("//*[@id='custom_{$contactRefFieldID1}_-1']/../div/a");
160 $this->keyDown("//*[@id='select2-drop']/div/input", " ");
161 $this->type("//*[@id='select2-drop']/div/input", "Anderson");
162 $this->typeKeys("//*[@id='select2-drop']/div/input", "Anderson");
163 $this->waitForElementPresent("css=div.select2-result-label span");
164 $this->assertElementContainsText("css=div.select2-result-label", "{$contact1}@example.com");
165 $this->assertElementNotContainsText("css=div.select2-result-label", "{$contact2}@example.com");
166
167 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
168
169 $this->clickAt("//*[@id='custom_{$contactRefFieldID2}_-1']/../div/a");
170 $this->keyDown("//*[@id='select2-drop']/div/input", " ");
171 $this->type("//*[@id='select2-drop']/div/input", $org1);
172 $this->typeKeys("//*[@id='select2-drop']/div/input", $org1);
173 $this->waitForElementPresent("css=div.select2-result-label");
174 $this->assertElementContainsText("css=div.select2-result-label", "{$org1}@example.com");
175 }
176 }
177