Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-07-14-13-42-39
[civicrm-core.git] / tests / phpunit / WebTest / Admin / CustomAddTestSameField.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 function testCustomSameFieldAdd() {
40 $this->open($this->sboxPath);
41 $this->webtestLogin();
42
43 $this->_testCustomAdd();
44 $this->_testCustomAdd();
45 }
46
47 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->click("//form[@id='Group']/div[2]/div[3]/span[1]/input");
62 $this->waitForPageToLoad($this->getTimeoutMsec());
63
64 //Is custom group created?
65 $this->assertTrue($this->isTextPresent("Your custom field set '$customGroupTitle' has been added. You can add custom fields now."));
66 //add custom field - alphanumeric text
67 $textFieldLabel = 'test_text_field';
68 $this->click("header");
69 $this->type("label", $textFieldLabel);
70 $this->click("_qf_Field_next_new-bottom");
71 $this->waitForPageToLoad($this->getTimeoutMsec());
72 $this->click("data_type[0]");
73 $this->select("data_type[0]", "value=0");
74 $this->click("//option[@value='0']");
75 $this->click("data_type[1]");
76 $this->select("data_type[1]", "label=CheckBox");
77 $this->click("//option[@value='CheckBox']");
78
79 $checkboxFieldLabel = 'test_checkbox';
80 $this->type("label", $checkboxFieldLabel);
81 $checkboxOptionLabel1 = 'check1';
82 $this->type("option_label_1", $checkboxOptionLabel1);
83 $this->type("option_value_1", "1");
84 $checkboxOptionLabel2 = 'check2';
85 $this->type("option_label_2", $checkboxOptionLabel2);
86 $this->type("option_value_2", "2");
87 $this->click("link=another choice");
88 $checkboxOptionLabel3 = 'check3';
89 $this->type("option_label_3", $checkboxOptionLabel3);
90 $this->type("option_value_3", "3");
91 $this->click("link=another choice");
92 $checkboxOptionLabel4 = 'check4';
93 $this->type("option_label_4", $checkboxOptionLabel4);
94 $this->type("option_value_4", "4");
95
96 //enter options per line
97 $this->type("options_per_line", "2");
98
99 //enter pre help message
100 $this->type("help_pre", "this is field pre help");
101
102 //enter post help message
103 $this->type("help_post", "this field post help");
104
105 //Is searchable?
106 $this->click("is_searchable");
107
108 //clicking save
109 $this->click("_qf_Field_next_new-bottom");
110 $this->waitForPageToLoad($this->getTimeoutMsec());
111
112 //Is custom field created?
113 $this->assertTrue($this->isTextPresent("Your custom field '$checkboxFieldLabel' has been saved."));
114
115 //add custom field - alphanumeric text
116 $textFieldLabel = 'test_text_field';
117 $this->click("header");
118 $this->type("label", $textFieldLabel);
119 $this->click("_qf_Field_next_new-bottom");
120
121 // Same group will not contain same custome fields so will show error for this field :
122 $this->waitForPageToLoad($this->getTimeoutMsec());
123 $this->click("data_type[0]");
124 $this->select("data_type[0]", "value=0");
125 $this->click("//option[@value='0']");
126 $this->click("data_type[1]");
127 $this->select("data_type[1]", "label=CheckBox");
128 $this->click("//option[@value='CheckBox']");
129 //Is custom field created
130 $this->assertTrue($this->isTextPresent("Custom field '$textFieldLabel' already exists in Database."));
131
132 //create another custom field - Number Radio
133 $this->click("data_type[0]");
134 $this->select("data_type[0]", "value=2");
135 $this->click("//option[@value='2']");
136 $this->click("data_type[1]");
137 $this->select("data_type[1]", "value=Radio");
138 $this->click("//option[@value='Radio']");
139
140 $radioFieldLabel = 'test_radio';
141 $this->type("label", $radioFieldLabel);
142 $radioOptionLabel1 = 'radio1';
143 $this->type("option_label_1", $radioOptionLabel1);
144 $this->type("option_value_1", "1");
145 $radioOptionLabel2 = 'radio2';
146 $this->type("option_label_2", $radioOptionLabel2);
147 $this->type("option_value_2", "2");
148
149 //select options per line
150 $this->type("options_per_line", "3");
151
152 //enter pre help msg
153 $this->type("help_pre", "this is field pre help");
154
155 //enter post help msg
156 $this->type("help_post", "this is field post help");
157
158 //Is searchable?
159 $this->click("is_searchable");
160
161 //clicking save
162 $this->click("_qf_Field_next-bottom");
163 $this->waitForPageToLoad($this->getTimeoutMsec());
164
165 //Is custom field created
166 $this->assertTrue($this->isTextPresent("Your custom field '$radioFieldLabel' has been saved."));
167
168 }
169 }
170