Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Contact_ContactReferenceFieldTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contact_ContactReferenceFieldTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testContactReferenceField() { | |
6a488035 TO |
39 | $this->webtestLogin(); |
40 | ||
6a488035 TO |
41 | /* add new group */ |
42 | ||
d8bd5fb9 | 43 | $this->openCiviPage('group/add', 'reset=1', '_qf_Edit_upload'); |
6a488035 TO |
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'); | |
6c5f7368 | 69 | $this->waitForText('crm-notification-container', "Added to Group"); |
6a488035 TO |
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 // | |
42daf119 | 82 | |
d8bd5fb9 | 83 | $this->openCiviPage('admin/custom/group', 'action=add&reset=1'); |
6a488035 TO |
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"); | |
74210507 | 95 | $this->waitForElementPresent("newCustomField"); |
6a488035 TO |
96 | |
97 | //Is custom group created? | |
6c5f7368 | 98 | $this->waitForText('crm-notification-container', "Your custom field set '{$customGroupTitle}' has been added. You can add custom fields now."); |
6a488035 | 99 | |
a471a3b6 | 100 | $customGroupId = $this->urlArg('gid'); |
6a488035 TO |
101 | |
102 | // Add contact reference fields | |
103 | $contactRefFieldLabel1 = 'contact_ref_' . substr(sha1(rand()), 0, 4); | |
74210507 | 104 | $this->waitForElementPresent("label"); |
6a488035 | 105 | $this->click("label"); |
74210507 | 106 | $this->waitForElementPresent("label"); |
6a488035 | 107 | $this->type("label", $contactRefFieldLabel1); |
74210507 | 108 | $this->waitForElementPresent("data_type[0]"); |
6a488035 TO |
109 | $this->select("data_type[0]", "label=Contact Reference"); |
110 | ||
111 | $this->waitForElementPresent("group_id"); | |
112 | $this->select("group_id", $groupName); | |
113 | ||
114 | //clicking save | |
74210507 | 115 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[2]/span[2]/"); |
6a488035 TO |
116 | |
117 | //Is custom field created? | |
b5e4fcd9 | 118 | $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel1' has been saved."); |
74210507 | 119 | $this->waitForElementPresent("xpath=//div[@class='ui-dialog-buttonset']/button[3]/span[2]/"); |
6a488035 TO |
120 | //add custom field - alphanumeric checkbox |
121 | $contactRefFieldLabel2 = 'contact_ref_' . substr(sha1(rand()), 0, 4); | |
74210507 | 122 | |
6a488035 | 123 | $this->click("label"); |
74210507 | 124 | $this->waitForElementPresent("label"); |
6a488035 | 125 | $this->type("label", $contactRefFieldLabel2); |
74210507 | 126 | $this->waitForElementPresent("data_type[0]"); |
6a488035 TO |
127 | $this->select("data_type[0]", "label=Contact Reference"); |
128 | ||
129 | $this->waitForElementPresent("group_id"); | |
130 | $this->click("xpath=//form[@id='Field']//a[text()='Advanced Filter']"); | |
131 | $this->waitForElementPresent("filter"); | |
132 | ||
c900afb1 | 133 | $this->type("filter", "action=get&contact_type=Organization"); |
6a488035 TO |
134 | |
135 | //clicking save | |
74210507 | 136 | $this->click("xpath=//div[@class='ui-dialog-buttonset']/button[1]/span[2]/"); |
6a488035 TO |
137 | |
138 | //Is custom field created? | |
b5e4fcd9 | 139 | $this->waitForText('crm-notification-container', "Custom field '$contactRefFieldLabel2' has been saved."); |
6a488035 | 140 | |
d8bd5fb9 | 141 | $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}"); |
6a488035 | 142 | |
b5e4fcd9 | 143 | $fieldid1 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[1]/td[8]/span[1]/a[text()='Edit Field']@href")); |
144 | $fieldid1 = $fieldid1[1]; | |
6a488035 | 145 | |
b5e4fcd9 | 146 | $contactRefFieldID1 = $fieldid1; |
6a488035 | 147 | |
d8bd5fb9 | 148 | $this->openCiviPage('admin/custom/group/field', "reset=1&action=browse&gid={$customGroupId}"); |
6a488035 | 149 | |
b5e4fcd9 | 150 | $fieldid2 = explode("&id=", $this->getAttribute("xpath=//div[@id='field_page']//table/tbody/tr[2]/td[8]/span[1]/a[text()='Edit Field']@href")); |
151 | $fieldid2 = $fieldid2[1]; | |
6a488035 | 152 | |
b5e4fcd9 | 153 | $contactRefFieldID2 = $fieldid2; |
6a488035 TO |
154 | |
155 | // Visit custom group preview page | |
d8bd5fb9 | 156 | $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}"); |
6a488035 | 157 | |
c900afb1 | 158 | $this->clickAt("//*[@id='custom_{$contactRefFieldID1}_-1']/../div/a"); |
159 | $this->keyDown("//*[@id='select2-drop']/div/input", " "); | |
160 | $this->type("//*[@id='select2-drop']/div/input", "Anderson"); | |
161 | $this->typeKeys("//*[@id='select2-drop']/div/input", "Anderson"); | |
162 | $this->waitForElementPresent("css=div.select2-result-label span"); | |
163 | $this->assertElementContainsText("css=div.select2-result-label", "{$contact1}@example.com"); | |
164 | $this->assertElementNotContainsText("css=div.select2-result-label", "{$contact2}@example.com"); | |
6a488035 | 165 | |
d8bd5fb9 | 166 | $this->openCiviPage('admin/custom/group', "action=preview&reset=1&id={$customGroupId}"); |
6a488035 | 167 | |
c900afb1 | 168 | $this->clickAt("//*[@id='custom_{$contactRefFieldID2}_-1']/../div/a"); |
169 | $this->keyDown("//*[@id='select2-drop']/div/input", " "); | |
170 | $this->type("//*[@id='select2-drop']/div/input", $org1); | |
171 | $this->typeKeys("//*[@id='select2-drop']/div/input", $org1); | |
172 | $this->waitForElementPresent("css=div.select2-result-label"); | |
173 | $this->assertElementContainsText("css=div.select2-result-label", "{$org1}@example.com"); | |
6a488035 TO |
174 | } |
175 | } | |
176 |