| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2016 | |
| 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_Member_ContactContextAddTest |
| 31 | */ |
| 32 | class WebTest_Member_ContactContextAddTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testContactMemberAdd() { |
| 39 | $this->webtestLogin(); |
| 40 | |
| 41 | // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership) |
| 42 | $memTypeParams = $this->webtestAddMembershipType(); |
| 43 | $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime'); |
| 44 | |
| 45 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 46 | |
| 47 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 48 | |
| 49 | //fill in first name |
| 50 | $this->type("first_name", $firstName); |
| 51 | |
| 52 | //fill in last name |
| 53 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7); |
| 54 | $this->type("last_name", $lastName); |
| 55 | |
| 56 | //fill in email |
| 57 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 58 | $this->type("email_1_email", $email); |
| 59 | |
| 60 | // Clicking save. |
| 61 | $this->click("_qf_Contact_upload_view"); |
| 62 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 63 | $this->waitForText('crm-notification-container', "$firstName $lastName"); |
| 64 | |
| 65 | // click through to the membership view screen |
| 66 | $this->click("css=li#tab_member a"); |
| 67 | |
| 68 | $this->waitForElementPresent("link=Add Membership"); |
| 69 | $this->click("link=Add Membership"); |
| 70 | |
| 71 | $this->waitForElementPresent("_qf_Membership_cancel-bottom"); |
| 72 | |
| 73 | // fill in Membership Organization and Type |
| 74 | $this->select("membership_type_id[0]", "label={$memTypeParams['member_of_contact']}"); |
| 75 | // Wait for membership type select to reload |
| 76 | $this->waitForTextPresent($memTypeParams['membership_type']); |
| 77 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 78 | // Sleep should never be used for wait for anything to load from the server |
| 79 | // Justification for this instance: FIXME |
| 80 | sleep(3); |
| 81 | $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}"); |
| 82 | |
| 83 | $sourceText = "Membership ContactAddTest Webtest"; |
| 84 | // fill in Source |
| 85 | $this->type("source", $sourceText); |
| 86 | |
| 87 | // Let Join Date stay default |
| 88 | |
| 89 | // fill in Start Date |
| 90 | $this->webtestFillDate('start_date'); |
| 91 | |
| 92 | // Clicking save. |
| 93 | $this->click("_qf_Membership_upload"); |
| 94 | |
| 95 | // page was loaded |
| 96 | $this->waitForTextPresent($sourceText); |
| 97 | |
| 98 | // Is status message correct? |
| 99 | $this->waitForText('crm-notification-container', "membership for $firstName $lastName has been added."); |
| 100 | |
| 101 | // click through to the membership view screen |
| 102 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 103 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 104 | |
| 105 | $verifyData = array( |
| 106 | 'Membership Type' => $memTypeParams['membership_type'], |
| 107 | 'Status' => 'New', |
| 108 | 'Source' => $sourceText, |
| 109 | ); |
| 110 | $this->webtestVerifyTabularData($verifyData); |
| 111 | |
| 112 | $this->click("_qf_MembershipView_cancel-bottom"); |
| 113 | // page was loaded |
| 114 | $this->waitForTextPresent($sourceText); |
| 115 | |
| 116 | $this->waitForElementPresent("css=li#tab_activity a"); |
| 117 | // click through to the activities screen |
| 118 | $this->click("css=li#tab_activity a"); |
| 119 | // page was loaded |
| 120 | $this->waitForTextPresent('Membership Signup'); |
| 121 | |
| 122 | // click through to the activiy view screen (which is the membership view |
| 123 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 124 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 125 | |
| 126 | $verifyData = array( |
| 127 | 'Membership Type' => $memTypeParams['membership_type'], |
| 128 | 'Status' => 'New', |
| 129 | 'Source' => $sourceText, |
| 130 | ); |
| 131 | $this->webtestVerifyTabularData($verifyData); |
| 132 | $this->clickLink("_qf_MembershipView_cancel-bottom", "xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[7]", FALSE); |
| 133 | $this->click("xpath=//div[@id='memberships']/div/table/tbody//tr/td[1][text()='{$memTypeParams['membership_type']}']/../td[9]/span/a[2][text()='Edit']"); |
| 134 | $this->waitForElementPresent("_qf_Membership_cancel-bottom"); |
| 135 | |
| 136 | // fill in Membership Organization and Type |
| 137 | $this->select("membership_type_id[0]", "label={$lifeTimeMemTypeParams['member_of_contact']}"); |
| 138 | // Wait for membership type select to reload |
| 139 | $this->waitForTextPresent($lifeTimeMemTypeParams['membership_type']); |
| 140 | $this->select("membership_type_id[1]", "label={$lifeTimeMemTypeParams['membership_type']}"); |
| 141 | |
| 142 | $this->waitForElementPresent("xpath=//form[@id='Membership']/div[2]/div[2]//table/tbody//tr[@class='crm-membership-form-block-end_date']/td[2]"); |
| 143 | $this->click("xpath=//form[@id='Membership']/div[2]/div[2]/table/tbody//tr[@class='crm-membership-form-block-end_date']/td[2]/a"); |
| 144 | |
| 145 | $this->click("_qf_Membership_upload-bottom"); |
| 146 | |
| 147 | $this->waitForElementPresent("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 148 | // page was loaded |
| 149 | $this->waitForTextPresent($sourceText); |
| 150 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 151 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 152 | |
| 153 | $verifyData = array( |
| 154 | 'Status' => 'New', |
| 155 | 'Source' => $sourceText, |
| 156 | 'End date' => '', |
| 157 | ); |
| 158 | $this->webtestVerifyTabularData($verifyData); |
| 159 | } |
| 160 | |
| 161 | public function testMemberAddWithLifeTimeMembershipType() { |
| 162 | $this->webtestLogin(); |
| 163 | |
| 164 | // Create a membership type to use for this test (defaults for this helper function are rolling 1 year membership) |
| 165 | $lifeTimeMemTypeParams = $this->webtestAddMembershipType('rolling', 1, 'lifetime'); |
| 166 | |
| 167 | $this->openCiviPage("contact/add", "reset=1&ct=Individual"); |
| 168 | |
| 169 | $firstName = "John_" . substr(sha1(rand()), 0, 7); |
| 170 | |
| 171 | //fill in first name |
| 172 | $this->type("first_name", $firstName); |
| 173 | |
| 174 | //fill in last name |
| 175 | $lastName = "Smith_" . substr(sha1(rand()), 0, 7);; |
| 176 | $this->type("last_name", $lastName); |
| 177 | |
| 178 | //fill in email |
| 179 | $email = substr(sha1(rand()), 0, 7) . "john@gmail.com"; |
| 180 | $this->type("email_1_email", $email); |
| 181 | |
| 182 | // Clicking save. |
| 183 | $this->click("_qf_Contact_upload_view"); |
| 184 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 185 | $this->waitForText('crm-notification-container', "$firstName $lastName has been created."); |
| 186 | |
| 187 | // click through to the membership view screen |
| 188 | $this->click("css=li#tab_member a"); |
| 189 | |
| 190 | $this->waitForElementPresent("link=Add Membership"); |
| 191 | $this->click("link=Add Membership"); |
| 192 | |
| 193 | $this->waitForElementPresent("_qf_Membership_cancel-bottom"); |
| 194 | |
| 195 | // fill in Membership Organization and Type |
| 196 | $this->select("membership_type_id[0]", "label={$lifeTimeMemTypeParams['member_of_contact']}"); |
| 197 | |
| 198 | // Wait for membership type select to reload |
| 199 | $this->waitForTextPresent($lifeTimeMemTypeParams['membership_type']); |
| 200 | // Because it tends to cause problems, all uses of sleep() must be justified in comments |
| 201 | // Sleep should never be used for wait for anything to load from the server |
| 202 | // Justification for this instance: FIXME |
| 203 | sleep(3); |
| 204 | $this->select("membership_type_id[1]", "label={$lifeTimeMemTypeParams['membership_type']}"); |
| 205 | |
| 206 | $sourceText = "Check Lifetime membership type webtest"; |
| 207 | // fill in Source |
| 208 | $this->type("source", $sourceText); |
| 209 | |
| 210 | // Let Join Date stay default |
| 211 | |
| 212 | // fill in Start Date |
| 213 | $this->webtestFillDate('start_date'); |
| 214 | |
| 215 | // Clicking save. |
| 216 | $this->click("_qf_Membership_upload"); |
| 217 | |
| 218 | // page was loaded |
| 219 | $this->waitForTextPresent($sourceText); |
| 220 | |
| 221 | // Is status message correct? |
| 222 | $this->waitForText('crm-notification-container', "membership for $firstName $lastName has been added."); |
| 223 | |
| 224 | // click through to the membership view screen |
| 225 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]/span/a[text()='View']"); |
| 226 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
| 227 | |
| 228 | $verifyData = array( |
| 229 | 'Status' => 'New', |
| 230 | 'Source' => $sourceText, |
| 231 | 'End date' => '', |
| 232 | ); |
| 233 | $this->webtestVerifyTabularData($verifyData); |
| 234 | $this->click("_qf_MembershipView_cancel-bottom"); |
| 235 | $this->waitForElementPresent("mainTabContainer"); |
| 236 | } |
| 237 | |
| 238 | } |