| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.7 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
| 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_Campaign_PledgeTest |
| 31 | */ |
| 32 | class WebTest_Campaign_PledgeTest extends CiviSeleniumTestCase { |
| 33 | |
| 34 | protected function setUp() { |
| 35 | parent::setUp(); |
| 36 | } |
| 37 | |
| 38 | public function testCreateCampaign() { |
| 39 | // Log in as admin first to verify permissions for CiviGrant |
| 40 | $this->webtestLogin('admin'); |
| 41 | |
| 42 | // Enable CiviCampaign module and CiviPledge module if necessary |
| 43 | $this->enableComponents(array("CiviCampaign", "CiviPledge")); |
| 44 | |
| 45 | // add the required Drupal permission |
| 46 | $permissions = array( |
| 47 | 'edit-2-access-civipledge', |
| 48 | 'edit-2-edit-pledges', |
| 49 | ); |
| 50 | $this->changePermissions($permissions); |
| 51 | |
| 52 | // Fixme: testing a theory that this test was failing due to permissions |
| 53 | //$this->webtestLogin(); |
| 54 | |
| 55 | // Create new group |
| 56 | $title = substr(sha1(rand()), 0, 7); |
| 57 | $groupName = $this->WebtestAddGroup(); |
| 58 | |
| 59 | // Adding contact |
| 60 | // We're using Quick Add block on the main page for this. |
| 61 | $firstName1 = substr(sha1(rand()), 0, 7); |
| 62 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); |
| 63 | |
| 64 | // add contact to group |
| 65 | // visit group tab |
| 66 | $this->click("css=li#tab_group a"); |
| 67 | $this->waitForElementPresent("group_id"); |
| 68 | |
| 69 | // add to group |
| 70 | $this->select("group_id", "label=$groupName"); |
| 71 | $this->click("_qf_GroupContact_next"); |
| 72 | $this->waitForElementPresent('link=Remove'); |
| 73 | |
| 74 | $firstName2 = substr(sha1(rand()), 0, 7); |
| 75 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org"); |
| 76 | |
| 77 | // add contact to group |
| 78 | // visit group tab |
| 79 | $this->click("css=li#tab_group a"); |
| 80 | $this->waitForElementPresent("group_id"); |
| 81 | |
| 82 | // add to group |
| 83 | $this->select("group_id", "label=$groupName"); |
| 84 | $this->click("_qf_GroupContact_next"); |
| 85 | $this->waitForElementPresent('link=Remove'); |
| 86 | |
| 87 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
| 88 | |
| 89 | $campaignTitle = "Campaign $title"; |
| 90 | $this->type("title", $campaignTitle); |
| 91 | |
| 92 | // select the campaign type |
| 93 | $this->select("campaign_type_id", "value=2"); |
| 94 | |
| 95 | // fill in the description |
| 96 | $this->type("description", "This is a test campaign"); |
| 97 | |
| 98 | // include groups for the campaign |
| 99 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
| 100 | |
| 101 | // fill the end date for campaign |
| 102 | $this->webtestFillDate("end_date", "+1 year"); |
| 103 | |
| 104 | // select campaign status |
| 105 | $this->select("status_id", "value=2"); |
| 106 | |
| 107 | // click save |
| 108 | $this->click("_qf_Campaign_upload-bottom"); |
| 109 | $this->waitForPageToLoad($this->getTimeoutMsec()); |
| 110 | |
| 111 | $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."), |
| 112 | "Status message didn't show up after saving campaign!" |
| 113 | ); |
| 114 | |
| 115 | $this->waitForElementPresent("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]"); |
| 116 | $id = (int) $this->getText("//div[@id='campaignList']/div/table/tbody/tr/td[3]/div[text()='{$campaignTitle}']/../../td[1]"); |
| 117 | $this->pledgeAddTest($campaignTitle, $id); |
| 118 | } |
| 119 | |
| 120 | /** |
| 121 | * @param $campaignTitle |
| 122 | * @param int $id |
| 123 | */ |
| 124 | public function pledgeAddTest($campaignTitle, $id) { |
| 125 | // create unique name |
| 126 | $name = substr(sha1(rand()), 0, 7); |
| 127 | $firstName = 'Adam' . $name; |
| 128 | $lastName = 'Jones' . $name; |
| 129 | |
| 130 | // create new contact |
| 131 | $this->webtestAddContact($firstName, $lastName, $firstName . "@example.com"); |
| 132 | |
| 133 | // wait for action element |
| 134 | $this->waitForElementPresent('crm-contact-actions-link'); |
| 135 | |
| 136 | // now add pledge from contact summary |
| 137 | $this->click("//a[@id='crm-contact-actions-link']/span/div"); |
| 138 | |
| 139 | // wait for add plegde link |
| 140 | $this->waitForElementPresent('link=Add Pledge'); |
| 141 | |
| 142 | $this->click('link=Add Pledge'); |
| 143 | |
| 144 | // wait for pledge form to load completely |
| 145 | $this->waitForElementPresent('_qf_Pledge_upload-bottom'); |
| 146 | |
| 147 | // check contact name on pledge form |
| 148 | $this->assertTrue($this->isTextPresent("$firstName $lastName")); |
| 149 | |
| 150 | $this->type("amount", "100"); |
| 151 | $this->type("installments", "10"); |
| 152 | $this->select("frequency_unit", "value=week"); |
| 153 | $this->type("frequency_day", "2"); |
| 154 | |
| 155 | $this->webtestFillDate('acknowledge_date', 'now'); |
| 156 | |
| 157 | // select campaign |
| 158 | $this->click("campaign_id"); |
| 159 | $this->select("campaign_id", "value=$id"); |
| 160 | |
| 161 | $this->select("contribution_page_id", "value=3"); |
| 162 | |
| 163 | //PaymentReminders |
| 164 | $this->click("PaymentReminders"); |
| 165 | $this->waitForElementPresent("additional_reminder_day"); |
| 166 | $this->type("initial_reminder_day", "4"); |
| 167 | $this->type("max_reminders", "2"); |
| 168 | $this->type("additional_reminder_day", "4"); |
| 169 | |
| 170 | $this->click("_qf_Pledge_upload-bottom"); |
| 171 | $this->waitForElementPresent('link=Add Pledge'); |
| 172 | |
| 173 | $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created."); |
| 174 | |
| 175 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']"); |
| 176 | //click through to the Pledge view screen |
| 177 | $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']"); |
| 178 | $this->waitForElementPresent("_qf_PledgeView_next-bottom"); |
| 179 | $pledgeDate = date('F jS, Y', strtotime('now')); |
| 180 | |
| 181 | // verify Activity created |
| 182 | $this->verifyText("xpath=//form[@id='PledgeView']//table/tbody/tr[8]/td[2]", preg_quote($campaignTitle)); |
| 183 | } |
| 184 | |
| 185 | } |