Merge pull request #92 from pratik-joshi/webtest-improvement
[civicrm-core.git] / tests / phpunit / WebTest / Profile / ProfileGroupSubscriptionTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 class WebTest_Profile_ProfileGroupSubscriptionTest extends CiviSeleniumTestCase {
30
31 protected function setUp() {
32 parent::setUp();
33 }
34
35 function testProfileGroupSubscription() {
36 // This is the path where our testing install resides.
37 // The rest of URL is defined in CiviSeleniumTestCase base class, in
38 // class attributes.
39 $this->open($this->sboxPath);
40
41 // Logging in. Remember to wait for page to load. In most cases,
42 // you can rely on 30000 as the value that allows your test to pass, however,
43 // sometimes your test might fail because of this. In such cases, it's better to pick one element
44 // somewhere at the end of page and use waitForElementPresent on it - this assures you, that whole
45 // page contents loaded and you can continue your test execution.
46 $this->webtestLogin();
47
48 // Go directly to the URL of the screen that you will be
49 // testing (Add new profile ).
50 $this->openCiviPage('admin/uf/group', 'reset=1');
51
52 $this->click('newCiviCRMProfile-top');
53
54 $this->waitForElementPresent('_qf_Group_next-bottom');
55
56 //Name of profile
57 $profileTitle = 'profile_' . substr(sha1(rand()), 0, 7);
58 $this->type('title', $profileTitle);
59
60 //Drupal user account registration option
61 $this->click('CIVICRM_QFID_0_8');
62
63 //What to do upon duplicate match
64 $this->click('CIVICRM_QFID_0_2');
65
66 //Proximity search options
67 $this->click('CIVICRM_QFID_0_14');
68
69 // enable maping for contact
70 $this->click('is_map');
71
72 // include a link in the listings to Edit profile fields
73 $this->click('is_edit_link');
74
75 //to view contacts' Drupal user account information
76 $this->click('is_uf_link');
77
78 //click on save
79 $this->click('_qf_Group_next');
80 $this->waitForPageToLoad($this->getTimeoutMsec());
81
82 //check for profile create
83 $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been added. You can add fields to this profile now.");
84
85 //Add email field to profile
86 $this->click('field_name[0]');
87 $this->select('field_name[0]', 'value=Contact');
88 $this->click("//option[@value='Contact']");
89
90 $this->select('field_name[1]', 'value=email');
91 $this->click("//option[@value='email']");
92
93 //click on save
94 $this->click('_qf_Field_next_new-top');
95 $this->waitForPageToLoad($this->getTimeoutMsec());
96
97 //Add email field to profile
98 $this->click('field_name[0]');
99 $this->select('field_name[0]', 'value=Contact');
100 $this->click("//option[@value='Contact']");
101
102 $this->select('field_name[1]', 'value=group');
103 $this->click("//option[@value='group']");
104
105 //click on save
106 $this->click('_qf_Field_next');
107
108 $this->waitForPageToLoad($this->getTimeoutMsec());
109
110 //now use profile create mode for group subscription
111 $this->click("xpath=//div[@id='field_page']/div/a[4]/span");
112
113 $this->waitForElementPresent('email-Primary');
114
115 //check for group field
116 $this->assertElementContainsText('crm-profile-block', 'Group(s)', "Groups field was not found.");
117
118 //fill the subscription form
119 $radomEmail = substr(sha1(rand()), 0, 7) . "@example.com";
120
121 $this->type("email-Primary", $radomEmail);
122
123 // check advisory group ( may be we should create a separate group to test this)
124 $this->click("group_3");
125
126 $this->click('_qf_Edit_next');
127
128 $this->waitForPageToLoad($this->getTimeoutMsec());
129
130 // assert for subscription message
131 $this->assertElementContainsText('messages', "Your subscription request has been submitted for group ", "Subscription message is not shown");
132
133 //check if profile is saved
134 $this->assertElementContainsText('css=span.msg-text', 'Your information has been saved.', 'Profile is not saved');
135
136 // delete the profile
137 $this->openCiviPage('admin/uf/group', 'reset=1');
138 $this->_testdeleteProfile($profileTitle);
139 }
140
141 function _testdeleteProfile($profileTitle) {
142 //$this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']");
143 $this->waitForElementPresent("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
144 $this->click("xpath=//div[@id='user-profiles']/div/div/table/tbody//tr/td[1]/span[text() = '$profileTitle']/../following-sibling::td[4]/span[2][text()='more']/ul/li[4]/a[text()='Delete']");
145 $this->waitForElementPresent('_qf_Group_next-bottom');
146 $this->click('_qf_Group_next-bottom');
147 $this->waitForElementPresent('newCiviCRMProfile-bottom');
148 $this->assertElementContainsText('crm-notification-container', "Your CiviCRM Profile '{$profileTitle}' has been deleted.");
149 }
150 }
151
152