3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
28 class WebTest_Contact_ContactReferenceFieldTest
extends CiviSeleniumTestCase
{
30 protected function setUp() {
34 function testContactReferenceField() {
35 $this->webtestLogin();
39 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload');
41 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
42 $this->type("title", $groupName);
45 $this->type("description", "Adding new group.");
47 // check Access Control
48 $this->click("group_type[1]");
51 $this->click("_qf_Edit_upload");
52 $this->waitForPageToLoad($this->getTimeoutMsec());
57 $contact1 = substr(sha1(rand()), 0, 7);
58 $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com");
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");
69 $contact2 = substr(sha1(rand()), 0, 7);
70 $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com");
73 $org1 = 'org_' . substr(sha1(rand()), 0, 5);
74 $this->webtestAddOrganization($org1, "{$org1}@example.com");
76 /* create custom group and fields */
78 // Add Custom group //
80 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
82 //fill custom group title
83 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
84 $this->click("title");
85 $this->type("title", $customGroupTitle);
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");
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.");
97 $customGroupId = $this->urlArg('gid');
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");
105 $this->waitForElementPresent("group_id");
106 $this->select("group_id", $groupName);
109 $this->click("_qf_Field_next_new-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
112 //Is custom field created?
113 $this->waitForText('crm-notification-container', "Your custom field '$contactRefFieldLabel1' has been saved.");
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");
121 $this->waitForElementPresent("group_id");
122 $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']");
123 $this->waitForElementPresent("filter");
125 $this->type("filter", "action=lookup&contact_type=Organization");
128 $this->click("_qf_Field_next-bottom");
129 $this->waitForPageToLoad($this->getTimeoutMsec());
131 //Is custom field created?
132 $this->waitForText('crm-notification-container', "Your custom field '$contactRefFieldLabel2' has been saved.");
134 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
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());
139 $contactRefFieldID1 = $this->urlArg('id');
141 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
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());
146 $contactRefFieldID2 = $this->urlArg('id');
148 // Visit custom group preview page
149 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
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");
158 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
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");