Merge pull request #11407 from cividesk/CRM-21553
[civicrm-core.git] / tests / phpunit / WebTest / Admin / CustomAddTestSameField.php
CommitLineData
e1069955 1<?php
2/*
3 +--------------------------------------------------------------------+
2fe49090 4 | CiviCRM version 5 |
e1069955 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
e1069955 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 +--------------------------------------------------------------------+
d25dd0ee 25 */
e1069955 26
27
28require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
29
30/**
31 * Class WebTest_Admin_CustomAddTestSameField
32 */
e1069955 33class WebTest_Admin_CustomAddTestSameField extends CiviSeleniumTestCase {
34
35 protected function setUp() {
36 parent::setUp();
37 }
38
00be9182 39 public function testCustomSameFieldAdd() {
e1069955 40 $this->open($this->sboxPath);
41 $this->webtestLogin();
b6708aeb 42
e1069955 43 $this->_testCustomAdd();
44 $this->_testCustomAdd();
45 }
b6708aeb 46
00be9182 47 public function _testCustomAdd() {
e1069955 48 //CRM-7564 : Different gropus can contain same custom fields
b6708aeb 49 $this->open($this->sboxPath . "civicrm/admin/custom/group?action=add&reset=1");
e1069955 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);
b6708aeb 56
e1069955 57 //custom group extends
58 $this->click("extends[0]");
59 $this->select("extends[0]", "label=Contacts");
60 $this->click("//option[@value='Contact']");
39a2888d 61 $this->clickLink("//form[@id='Group']/div[2]/div[3]/span[1]/input");
b6708aeb 62
e1069955 63 //Is custom group created?
39a2888d 64 $this->waitForText('crm-notification-container', "Your custom field set '$customGroupTitle' has been added. You can add custom fields now.");
48b420d7 65
39a2888d 66 $gid = $this->urlArg('gid');
48b420d7 67
e1069955 68 //add custom field - alphanumeric text
39a2888d 69 $this->openCiviPage('admin/custom/group/field/add', "reset=1&action=add&gid=$gid");
e1069955 70 $textFieldLabel = 'test_text_field';
71 $this->click("header");
fb93fc39 72 $this->waitForElementPresent('label');
e1069955 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']");
b6708aeb 82
e1069955 83 $checkboxFieldLabel = 'test_checkbox';
fb93fc39 84 $this->waitForElementPresent('label');
e1069955 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");
b6708aeb 100
e1069955 101 //enter options per line
102 $this->type("options_per_line", "2");
b6708aeb 103
e1069955 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");
b6708aeb 109
e1069955 110 //Is searchable?
111 $this->click("is_searchable");
b6708aeb 112
e1069955 113 //clicking save
39a2888d 114 $this->clickLink("_qf_Field_next_new-bottom");
b6708aeb 115
e1069955 116 //Is custom field created?
39a2888d 117 $this->waitForText('crm-notification-container', "Custom field '$checkboxFieldLabel' has been saved.");
b6708aeb 118
e1069955 119 //add custom field - alphanumeric text
120 $textFieldLabel = 'test_text_field';
121 $this->click("header");
fb93fc39 122 $this->waitForElementPresent('label');
e1069955 123 $this->type("label", $textFieldLabel);
39a2888d 124 $this->clickLink("_qf_Field_next_new-bottom");
b6708aeb 125
e1069955 126 // Same group will not contain same custome fields so will show error for this field :
e1069955 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
39a2888d 134 $this->waitForText('crm-notification-container', "Custom field '$textFieldLabel' already exists in Database.");
b6708aeb 135
e1069955 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']");
b6708aeb 143
e1069955 144 $radioFieldLabel = 'test_radio';
fb93fc39 145 $this->waitForElementPresent('label');
e1069955 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");
b6708aeb 153
e1069955 154 //select options per line
155 $this->type("options_per_line", "3");
b6708aeb 156
e1069955 157 //enter pre help msg
158 $this->type("help_pre", "this is field pre help");
b6708aeb 159
e1069955 160 //enter post help msg
161 $this->type("help_post", "this is field post help");
b6708aeb 162
e1069955 163 //Is searchable?
164 $this->click("is_searchable");
b6708aeb 165
e1069955 166 //clicking save
39a2888d 167 $this->clickLink("_qf_Field_done-bottom");
b6708aeb 168
e1069955 169 //Is custom field created
39a2888d 170 $this->waitForText('crm-notification-container', "Custom field '$radioFieldLabel' has been saved.");
b6708aeb 171
172 }
96025800 173
e1069955 174}