Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-08-12-10-27-52
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileGroupSubscriptionTest.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 require_once 'CiviTest/CiviSeleniumTestCase.php';
28
29 /**
30 * Class WebTest_Profile_ProfileGroupSubscriptionTest
31 */
32 class WebTest_Profile_ProfileGroupSubscriptionTest extends CiviSeleniumTestCase {
33
34 protected function setUp() {
35 parent::setUp();
36 }
37
38 function testProfileGroupSubscription() {
39 $this->webtestLogin();
40
41 // Add new profile.
42 $this->openCiviPage('admin/uf/group', 'reset=1');
43
44 $this->click('newCiviCRMProfile-top');
45
46 $this->waitForElementPresent('_qf_Group_next-bottom');
47
48 //Name of profile
49 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
50 $this->type('title', $profileTitle);
51 $this->click('uf_group_type_Profile');
52
53 //Drupal user account registration option
54 $this->click('CIVICRM_QFID_0_8');
55
56 //What to do upon duplicate match
57 $this->click('CIVICRM_QFID_0_2');
58
59 //Proximity search options
60 $this->click('CIVICRM_QFID_0_14');
61
62 // enable mapping for contact
63 $this->click('is_map');
64
65 // include a link in the listings to Edit profile fields
66 $this->click('is_edit_link');
67
68 //to view contacts' Drupal user account information
69 $this->click('is_uf_link');
70
71 //click on save
72 $this->click('_qf_Group_next');
73 $this->waitForPageToLoad($this->getTimeoutMsec());
74
75 //check for profile create
76 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
77
78 //Add email field to profile
79 $this->click('field_name[0]');
80 $this->select('field_name[0]', 'value=Contact');
81 $this->click("//option[@value='Contact']");
82
83 $this->select('field_name[1]', 'value=email');
84 $this->click("//option[@value='email']");
85
86 //click on save
87 $this->click('_qf_Field_next_new-top');
88 $this->waitForPageToLoad($this->getTimeoutMsec());
89
90 //Add email field to profile
91 $this->click('field_name[0]');
92 $this->select('field_name[0]', 'value=Contact');
93 $this->click("//option[@value='Contact']");
94
95 $this->select('field_name[1]', 'value=group');
96 $this->click("//option[@value='group']");
97
98 //click on save
99 $this->click('_qf_Field_next');
100
101 $this->waitForPageToLoad($this->getTimeoutMsec());
102
103 //now use profile create mode for group subscription
104 $this->click("xpath=//div[@id='field_page']/div/a[4]/span");
105
106 $this->waitForElementPresent('email-Primary');
107
108 //check for group field
109 $this->assertElementContainsText('crm-profile-block', 'Group(s)', "Groups field was not found.");
110
111 //fill the subscription form
112 $randomEmail = substr(sha1(rand()), 0, 7) . "@example.com";
113
114 $this->type("email-Primary", $randomEmail);
115
116 // check advisory group ( may be we should create a separate group to test this)
117 $this->click("group_3");
118
119 $this->click('_qf_Edit_next');
120
121
122 // assert for subscription message
123
124 $this->isTextPresent("Your subscription request has been submitted for");
125 //check if profile is saved
126 $this->waitForText('crm-notification-container','Your information has been saved.');
127
128 // delete the profile
129 $this->openCiviPage('admin/uf/group', 'reset=1');
130 $this->_testdeleteProfile($profileTitle);
131 }
132
133 /**
134 * @param $profileTitle
135 */
136 function _testdeleteProfile($profileTitle) {
137 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
138 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td/span[text() = '$profileTitle']/../../td[7]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
139 $this->waitForElementPresent('_qf_Group_next-bottom');
140 $this->click('_qf_Group_next-bottom');
141 $this->waitForElementPresent('newCiviCRMProfile-bottom');
142 $this->waitForText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
143 }
144 }
145