Webtest fixes for profile/custom-field/price-set
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileCountryState.php
CommitLineData
69932a56
N
1<?php
2/*
3 +--------------------------------------------------------------------+
06a1bc01 4 | CiviCRM version 4.5 |
69932a56 5 +--------------------------------------------------------------------+
06a1bc01 6 | Copyright CiviCRM LLC (c) 2004-2014 |
69932a56
N
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
27require_once 'CiviTest/CiviSeleniumTestCase.php';
e9479dcf
EM
28
29/**
30 * Class WebTest_Profile_ProfileCountryState
31 */
69932a56
N
32class WebTest_Profile_ProfileCountryState extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testStateCountry() {
e9479dcf 39 $this->webtestLogin();
69932a56 40 $config = CRM_Core_Config::singleton();
a55077dc
N
41 // Add new profile.
42 $this->openCiviPage('admin/uf/group', 'reset=1');
43 $this->click('newCiviCRMProfile-top');
44 $this->waitForElementPresent('_qf_Group_next-bottom');
45
46 //Name of profile
47 $profileTitle = 'Country state province web test temp';
48 $this->type('title', $profileTitle);
49
39a2888d
CW
50 // Standalone form or directory
51 $this->click('uf_group_type_Profile');
52
a55077dc
N
53 //click on save
54 $this->click('_qf_Group_next');
55 $this->waitForPageToLoad($this->getTimeoutMsec());
e9479dcf 56
a55077dc
N
57
58 //check for profile create
59 $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
60 $gid = $this->urlArg('gid');
39a2888d 61
a55077dc 62 //Add Country field to profile
39a2888d 63 $this->openCiviPage('admin/uf/group/field/add', array('action' => 'add', 'reset' => 1, 'gid' => $gid), 'field_name[0]');
a55077dc
N
64 $this->click('field_name[0]');
65 $this->select('field_name[0]', 'value=Contact');
66 $this->click("//option[@value='Contact']");
67 $this->click('field_name[1]');
68 $this->select('field_name[1]', 'value=country');
69 $this->click("//option[@value='country']");
70 $this->click('is_required');
71
72 $this->click('_qf_Field_next_new');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74
75 //Add State field to profile
76 $this->click('field_name[0]');
77 $this->select('field_name[0]', 'value=Contact');
78 $this->click("//option[@value='Contact']");
79 $this->click('field_name[1]');
80 $this->select('field_name[1]', 'value=state_province');
81 $this->click("xpath=//select[@id='field_name_1']/option[@value='state_province']");
82 $this->click('is_required');
83 //click on save
84 $this->click('_qf_Field_next');
85 $this->waitForPageToLoad($this->getTimeoutMsec());
86
87 if($gid) {
88 $this->openCiviPage('admin/setting/localization', 'reset=1', '_qf_Localization_next-bottom');
69932a56
N
89 $country = array(1001 => 'Afghanistan', 1013 => 'Australia', 1039 => 'Canada', 1101 => 'India');
90 $enabledCountries = $this->getSelectOptions("countryLimit-t");
91 $enabledStates = $this->getSelectOptions("provinceLimit-t");
a55077dc 92 $newCountry = array();
69932a56
N
93 foreach($country as $countryID => $countryName) {
94 if(!in_array($countryName, $enabledCountries)) {
a55077dc 95 $newCountry[$countryID] = $countryName;
69932a56
N
96 $this->addSelection("countryLimit-f", "label=$countryName");
97 $this->click("xpath=//select[@id='countryLimit-f']/option[@value='$countryID']");
98 $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
99 }
100 if(!in_array($countryName, $enabledStates)) {
101 $this->addSelection("provinceLimit-f", "label=$countryName");
102 $this->click("//option[@value='$countryID']");
103 $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='add']");
104 }
105 $added = true;
106 }
107 if ($added) {
108 $this->click("_qf_Localization_next-bottom");
109 $this->waitForPageToLoad($this->getTimeoutMsec());
110 $this->waitForText('crm-notification-container', "Saved");
e9479dcf 111 }
a55077dc 112 $this->openCiviPage("profile/create", "gid=$gid&reset=1", NULL);
69932a56 113
69932a56 114 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
69932a56
N
115 $this->click("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select");
116 $countryID = array_rand($country);
117 $states = CRM_Core_PseudoConstant::stateProvinceForCountry($countryID, 'id');
118 $stateID = array_rand($states);
119 $this->select("xpath=//form[@id='Edit']/div[2]/div/div/div[2]/select", "value=$countryID");
39a2888d 120 $this->waitForElementPresent("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select/option[@value=$stateID]");
69932a56
N
121 $this->click("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select");
122 $this->select("xpath=//form[@id='Edit']/div[2]/div/div[2]/div[2]/select", "value=$stateID");
123 $this->clickLink('_qf_Edit_next', NULL);
a55077dc 124
39a2888d
CW
125 // Delete profile
126 $this->openCiviPage('admin/uf/group', 'action=delete&id=' . $gid, '_qf_Group_next-bottom');
127 $this->clickLink('_qf_Group_next-bottom', 'newCiviCRMProfile-bottom');
a55077dc
N
128 $this->waitForText('crm-notification-container', "Profile '{$profileTitle}' has been deleted.");
129
130 $this->openCiviPage("admin/setting/localization", "reset=1", "_qf_Localization_next-bottom");
131 $enabledCountries = $this->getSelectOptions("countryLimit-t");
132 $enabledStates = $this->getSelectOptions("provinceLimit-t");
133 $removed = false;
134 foreach($newCountry as $countryID => $countryName) {
135 $this->addSelection("countryLimit-t", "label=$countryName");
136 $this->click("xpath=//select[@id='countryLimit-t']/option[@value='$countryID']");
137 $this->click("xpath=//tr[@class='crm-localization-form-block-countryLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
138
139 $this->addSelection("provinceLimit-t", "label=$countryName");
140 $this->click("//option[@value='$countryID']");
141 $this->click("xpath=//tr[@class='crm-localization-form-block-provinceLimit']/td[2]/table//tbody/tr/td[2]/input[@name='remove']");
142 $removed = true;
143 }
144 if ($removed) {
145 $this->click("_qf_Localization_next-bottom");
146 $this->waitForPageToLoad($this->getTimeoutMsec());
147 $this->waitForText('crm-notification-container', "Saved");
148 }
69932a56
N
149 }
150 }
e9479dcf 151}