Merge pull request #11453 from colemanw/php55
[civicrm-core.git] / tests / phpunit / WebTest / Admin / CustomAddTestSameField.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
28 require_once 'CiviTest/CiviSeleniumTestCase.php';
29
30 /**
31 * Class WebTest_Admin_CustomAddTestSameField
32 */
33 class WebTest_Admin_CustomAddTestSameField extends CiviSeleniumTestCase {
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
39 public function testCustomSameFieldAdd() {
40 $this->open($this->sboxPath);
41 $this->webtestLogin();
42
43 $this->_testCustomAdd();
44 $this->_testCustomAdd();
45 }
46
47 public function _testCustomAdd() {
48 //CRM-7564 : Different gropus can contain same custom fields
49 $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1");
50 $this->waitForPageToLoad($this->getTimeoutMsec());
51
52 //fill custom group title
53 $customGroupTitle = 'custom_group' . substr(sha1(rand()), 0, 3);
54 $this->click("title");
55 $this->type("title", $customGroupTitle);
56
57 //custom group extends
58 $this->click("extends[0]");
59 $this->select("extends[0]", "label=Contacts");
60 $this->click("//option[@value='Contact']");
61 $this->clickLink("//form[@id='Group']/div[2]/div[3]/span[1]/input");
62
63 //Is custom group created?
64 $this->waitForText('crm-notification-container', "Your custom field set '$customGroupTitle' has been added. You can add custom fields now.");
65
66 $gid = $this->urlArg('gid');
67
68 //add custom field - alphanumeric text
69 $this->openCiviPage('admin/custom/group/field/add', "reset=1&action=add&gid=$gid");
70 $textFieldLabel = 'test_text_field';
71 $this->click("header");
72 $this->waitForElementPresent('label');
73 $this->type("label", $textFieldLabel);
74 $this->click("_qf_Field_next_new-bottom");
75 $this->waitForPageToLoad($this->getTimeoutMsec());
76 $this->click("data_type[0]");
77 $this->select("data_type[0]", "value=0");
78 $this->click("//option[@value='0']");
79 $this->click("data_type[1]");
80 $this->select("data_type[1]", "label=CheckBox");
81 $this->click("//option[@value='CheckBox']");
82
83 $checkboxFieldLabel = 'test_checkbox';
84 $this->waitForElementPresent('label');
85 $this->type("label", $checkboxFieldLabel);
86 $checkboxOptionLabel1 = 'check1';
87 $this->type("option_label_1", $checkboxOptionLabel1);
88 $this->type("option_value_1", "1");
89 $checkboxOptionLabel2 = 'check2';
90 $this->type("option_label_2", $checkboxOptionLabel2);
91 $this->type("option_value_2", "2");
92 $this->click("link=another choice");
93 $checkboxOptionLabel3 = 'check3';
94 $this->type("option_label_3", $checkboxOptionLabel3);
95 $this->type("option_value_3", "3");
96 $this->click("link=another choice");
97 $checkboxOptionLabel4 = 'check4';
98 $this->type("option_label_4", $checkboxOptionLabel4);
99 $this->type("option_value_4", "4");
100
101 //enter options per line
102 $this->type("options_per_line", "2");
103
104 //enter pre help message
105 $this->type("help_pre", "this is field pre help");
106
107 //enter post help message
108 $this->type("help_post", "this field post help");
109
110 //Is searchable?
111 $this->click("is_searchable");
112
113 //clicking save
114 $this->clickLink("_qf_Field_next_new-bottom");
115
116 //Is custom field created?
117 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
118
119 //add custom field - alphanumeric text
120 $textFieldLabel = 'test_text_field';
121 $this->click("header");
122 $this->waitForElementPresent('label');
123 $this->type("label", $textFieldLabel);
124 $this->clickLink("_qf_Field_next_new-bottom");
125
126 // Same group will not contain same custome fields so will show error for this field :
127 $this->click("data_type[0]");
128 $this->select("data_type[0]", "value=0");
129 $this->click("//option[@value='0']");
130 $this->click("data_type[1]");
131 $this->select("data_type[1]", "label=CheckBox");
132 $this->click("//option[@value='CheckBox']");
133 //Is custom field created
134 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' already exists in Database.");
135
136 //create another custom field - Number Radio
137 $this->click("data_type[0]");
138 $this->select("data_type[0]", "value=2");
139 $this->click("//option[@value='2']");
140 $this->click("data_type[1]");
141 $this->select("data_type[1]", "value=Radio");
142 $this->click("//option[@value='Radio']");
143
144 $radioFieldLabel = 'test_radio';
145 $this->waitForElementPresent('label');
146 $this->type("label", $radioFieldLabel);
147 $radioOptionLabel1 = 'radio1';
148 $this->type("option_label_1", $radioOptionLabel1);
149 $this->type("option_value_1", "1");
150 $radioOptionLabel2 = 'radio2';
151 $this->type("option_label_2", $radioOptionLabel2);
152 $this->type("option_value_2", "2");
153
154 //select options per line
155 $this->type("options_per_line", "3");
156
157 //enter pre help msg
158 $this->type("help_pre", "this is field pre help");
159
160 //enter post help msg
161 $this->type("help_post", "this is field post help");
162
163 //Is searchable?
164 $this->click("is_searchable");
165
166 //clicking save
167 $this->clickLink("_qf_Field_done-bottom");
168
169 //Is custom field created
170 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
171
172 }
173
174 }