Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | ||
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Campaign_PledgeTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Campaign_PledgeTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
38 | function testCreateCampaign() { | |
6a488035 | 39 | // Log in as admin first to verify permissions for CiviGrant |
42daf119 | 40 | $this->webtestLogin('admin'); |
6a488035 TO |
41 | |
42 | // Enable CiviCampaign module and CiviPledge module if necessary | |
b9715b8a | 43 | $this->enableComponents(array("CiviCampaign", "CiviPledge")); |
6a488035 TO |
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 | ||
037454ae CW |
52 | // Fixme: testing a theory that this test was failing due to permissions |
53 | //$this->webtestLogin(); | |
6a488035 TO |
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"); | |
701f18c0 | 72 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
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"); | |
701f18c0 | 85 | $this->waitForElementPresent('link=Remove'); |
6a488035 | 86 | |
42daf119 | 87 | $this->openCiviPage("campaign/add", "reset=1", "_qf_Campaign_upload-bottom"); |
6a488035 | 88 | |
6a488035 TO |
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 | |
aeaa5f5d | 99 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
6a488035 TO |
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 | ||
aeaa5f5d JP |
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]"); | |
6a488035 TO |
117 | $this->pledgeAddTest($campaignTitle, $id); |
118 | } | |
119 | ||
4cbe18b8 EM |
120 | /** |
121 | * @param $campaignTitle | |
122 | * @param $id | |
123 | */ | |
6a488035 TO |
124 | function pledgeAddTest($campaignTitle, $id) { |
125 | // create unique name | |
42daf119 | 126 | $name = substr(sha1(rand()), 0, 7); |
6a488035 | 127 | $firstName = 'Adam' . $name; |
42daf119 | 128 | $lastName = 'Jones' . $name; |
6a488035 TO |
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 | ||
6a488035 TO |
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 | ||
6a488035 TO |
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"); | |
701f18c0 | 171 | $this->waitForElementPresent('link=Add Pledge'); |
6a488035 | 172 | |
701f18c0 | 173 | $this->waitForText('crm-notification-container', "Pledge has been recorded and the payment schedule has been created."); |
6a488035 | 174 | |
701f18c0 | 175 | $this->waitForElementPresent("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']"); |
6a488035 | 176 | //click through to the Pledge view screen |
701f18c0 | 177 | $this->click("xpath=//div[@class='view-content']//table//tbody/tr[1]/td[10]/span[1]/a[text()='View']"); |
6a488035 TO |
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 |