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