Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-23-14-48-29
[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("_qf_Field_cancel-bottom");
96
97 //Is custom group created?
98 $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now.");
99
100 $customGroupId = $this->urlArg('gid');
101
102 // Add contact reference fields
103 $contactRefFieldLabel1 = 'contact_ref_' . substr(sha1(rand()), 0, 4);
104 $this->click("label");
105 $this->type("label", $contactRefFieldLabel1);
106 $this->select("data_type[0]", "label=Contact Reference");
107
108 $this->waitForElementPresent("group_id");
109 $this->select("group_id", $groupName);
110
111 //clicking save
112 $this->click("_qf_Field_next_new-bottom");
113 $this->waitForPageToLoad($this->getTimeoutMsec());
114
115 //Is custom field created?
116 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel1' has been saved.");
117
118 //add custom field - alphanumeric checkbox
119 $contactRefFieldLabel2 = 'contact_ref_' . substr(sha1(rand()), 0, 4);
120 $this->click("label");
121 $this->type("label", $contactRefFieldLabel2);
122 $this->select("data_type[0]", "label=Contact Reference");
123
124 $this->waitForElementPresent("group_id");
125 $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']");
126 $this->waitForElementPresent("filter");
127
128 $this->type("filter", "action=get&contact_type=Organization");
129
130 //clicking save
131 $this->click("_qf_Field_next-bottom");
132 $this->waitForPageToLoad($this->getTimeoutMsec());
133
134 //Is custom field created?
135 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel2' has been saved.");
136
137 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
138
139 $fieldid1 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[8]/span[1]/a[text()='Edit Field']@href"));
140 $fieldid1 = $fieldid1[1];
141
142 $contactRefFieldID1 = $fieldid1;
143
144 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
145
146 $fieldid2 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/span[1]/a[text()='Edit Field']@href"));
147 $fieldid2 = $fieldid2[1];
148
149 $contactRefFieldID2 = $fieldid2;
150
151 // Visit custom group preview page
152 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
153
154 $this->clickAt("//*[@id='custom_{$contactRefFieldID1}_-1']/../div/a");
155 $this->keyDown("//*[@id='select2-drop']/div/input", " ");
156 $this->type("//*[@id='select2-drop']/div/input", "Anderson");
157 $this->typeKeys("//*[@id='select2-drop']/div/input", "Anderson");
158 $this->waitForElementPresent("css=div.select2-result-label span");
159 $this->assertElementContainsText("css=div.select2-result-label", "{$contact1}@example.com");
160 $this->assertElementNotContainsText("css=div.select2-result-label", "{$contact2}@example.com");
161
162 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
163
164 $this->clickAt("//*[@id='custom_{$contactRefFieldID2}_-1']/../div/a");
165 $this->keyDown("//*[@id='select2-drop']/div/input", " ");
166 $this->type("//*[@id='select2-drop']/div/input", $org1);
167 $this->typeKeys("//*[@id='select2-drop']/div/input", $org1);
168 $this->waitForElementPresent("css=div.select2-result-label");
169 $this->assertElementContainsText("css=div.select2-result-label", "{$org1}@example.com");
170 }
171 }
172