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