3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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';
30 * Class WebTest_Contact_ContactReferenceFieldTest
32 class WebTest_Contact_ContactReferenceFieldTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 function testContactReferenceField() {
39 $this->webtestLogin();
43 $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload');
45 $groupName = 'group_' . substr(sha1(rand()), 0, 7);
46 $this->type("title", $groupName);
49 $this->type("description", "Adding new group.");
51 // check Access Control
52 $this->click("group_type[1]");
55 $this->click("_qf_Edit_upload");
56 $this->waitForPageToLoad($this->getTimeoutMsec());
61 $contact1 = substr(sha1(rand()), 0, 7);
62 $this->webtestAddContact($contact1, "Anderson", "{$contact1}@example.com");
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");
72 $contact2 = substr(sha1(rand()), 0, 7);
73 $this->webtestAddContact($contact2, "Anderson", "{$contact2}@example.com");
76 $org1 = 'org_' . substr(sha1(rand()), 0, 5);
77 $this->webtestAddOrganization($org1, "{$org1}@example.com");
79 /* create custom group and fields */
81 // Add Custom group //
83 $this->openCiviPage('admin/custom/group', 'action=add&reset=1');
85 //fill custom group title
86 $customGroupTitle = 'custom_' . substr(sha1(rand()), 0, 7);
87 $this->click("title");
88 $this->type("title", $customGroupTitle);
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");
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.");
100 $customGroupId = $this->urlArg('gid');
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");
108 $this->waitForElementPresent("group_id");
109 $this->select("group_id", $groupName);
112 $this->click("_qf_Field_next_new-bottom");
113 $this->waitForPageToLoad($this->getTimeoutMsec());
115 //Is custom field created?
116 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel1' has been saved.");
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");
124 $this->waitForElementPresent("group_id");
125 $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']");
126 $this->waitForElementPresent("filter");
128 $this->type("filter", "action=get&contact_type=Organization");
131 $this->click("_qf_Field_next-bottom");
132 $this->waitForPageToLoad($this->getTimeoutMsec());
134 //Is custom field created?
135 $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel2' has been saved.");
137 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
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];
142 $contactRefFieldID1 = $fieldid1;
144 $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}");
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];
149 $contactRefFieldID2 = $fieldid2;
151 // Visit custom group preview page
152 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
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");
162 $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}");
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");