3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviSeleniumTestCase.php';
30 * Class WebTest_Campaign_PledgeTest
32 class WebTest_Campaign_PledgeTest
extends CiviSeleniumTestCase
{
34 protected function setUp() {
38 public function testCreateCampaign() {
39 // Log in as admin first to verify permissions for CiviGrant
40 $this->webtestLogin('admin');
42 // Enable CiviCampaign module and CiviPledge module if necessary
43 $this->enableComponents(array("CiviCampaign", "CiviPledge"));
45 // add the required Drupal permission
47 'edit-2-access-civipledge',
48 'edit-2-edit-pledges',
50 $this->changePermissions($permissions);
52 // Fixme: testing a theory that this test was failing due to permissions
53 //$this->webtestLogin();
56 $title = substr(sha1(rand()), 0, 7);
57 $groupName = $this->WebtestAddGroup();
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");
64 // add contact to group
66 $this->click("css=li#tab_group a");
67 $this->waitForElementPresent("group_id");
70 $this->select("group_id", "label=$groupName");
71 $this->click("_qf_GroupContact_next");
72 $this->waitForElementPresent('link=Remove');
74 $firstName2 = substr(sha1(rand()), 0, 7);
75 $this->webtestAddContact($firstName2, "John", "$firstName2.john@example.org");
77 // add contact to group
79 $this->click("css=li#tab_group a");
80 $this->waitForElementPresent("group_id");
83 $this->select("group_id", "label=$groupName");
84 $this->click("_qf_GroupContact_next");
85 $this->waitForElementPresent('link=Remove');
87 $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom");
89 $campaignTitle = "Campaign $title";
90 $this->type("title", $campaignTitle);
92 // select the campaign type
93 $this->select("campaign_type_id", "value=2");
95 // fill in the description
96 $this->type("description", "This is a test campaign");
98 // include groups for the campaign
99 $this->multiselect2("includeGroups", array("$groupName", "Advisory Board"));
101 // fill the end date for campaign
102 $this->webtestFillDate("end_date", "+1 year");
104 // select campaign status
105 $this->select("status_id", "value=2");
108 $this->click("_qf_Campaign_upload-bottom");
109 $this->waitForPageToLoad($this->getTimeoutMsec());
111 $this->assertTrue($this->isTextPresent("Campaign Campaign $title has been saved."),
112 "Status message didn't show up after saving campaign!"
115 $this->waitForElementPresent("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
116 $id = (int) $this->getText("//div[@id='campaignList']/div[@class='dataTables_wrapper no-footer']/table/tbody/tr/td[text()='{$campaignTitle}']/../td[1]");
117 $this->pledgeAddTest($campaignTitle, $id);
121 * @param $campaignTitle
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;
130 // create new contact
131 $this->webtestAddContact($firstName, $lastName, $firstName . "@example.com");
133 // wait for action element
134 $this->waitForElementPresent('crm-contact-actions-link');
136 // now add pledge from contact summary
137 $this->click("//a[@id='crm-contact-actions-link']/span/div");
139 // wait for add plegde link
140 $this->waitForElementPresent('link=Add Pledge');
142 $this->click('link=Add Pledge');
144 // wait for pledge form to load completely
145 $this->waitForElementPresent('_qf_Pledge_upload-bottom');
147 // check contact name on pledge form
148 $this->assertTrue($this->isTextPresent("$firstName $lastName"));
150 $this->type("amount", "100");
151 $this->type("installments", "10");
152 $this->select("frequency_unit", "value=week");
153 $this->type("frequency_day", "2");
155 $this->webtestFillDate('acknowledge_date', 'now');
158 $this->click("campaign_id");
159 $this->select("campaign_id", "value=$id");
161 $this->select("contribution_page_id", "value=3");
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");
170 $this->click("_qf_Pledge_upload-bottom");
171 $this->waitForElementPresent('link=Add Pledge');
173 $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created.");
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'));
181 // verify Activity created
182 $this->verifyText("xpath=//form[@id='PledgeView']//table/tbody/tr[8]/td[2]", preg_quote($campaignTitle));