Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
15a4309a | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 25 | */ |
6a488035 | 26 | |
6a488035 | 27 | require_once 'CiviTest/CiviSeleniumTestCase.php'; |
e9479dcf EM |
28 | |
29 | /** | |
30 | * Class WebTest_Campaign_MembershipTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Campaign_MembershipTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
00be9182 | 38 | public function testCreateCampaign() { |
42daf119 | 39 | $this->webtestLogin('admin'); |
6a488035 TO |
40 | |
41 | // Create new group | |
42 | $title = substr(sha1(rand()), 0, 7); | |
43 | $groupName = $this->WebtestAddGroup(); | |
44 | ||
45 | // Adding contact | |
46 | // We're using Quick Add block on the main page for this. | |
47 | $firstName1 = substr(sha1(rand()), 0, 7); | |
48 | $this->webtestAddContact($firstName1, "Smith", "$firstName1.smith@example.org"); | |
49 | ||
50 | // add contact to group | |
51 | // visit group tab | |
52 | $this->click("css=li#tab_group a"); | |
53 | $this->waitForElementPresent("group_id"); | |
54 | ||
55 | // add to group | |
94b3c290 | 56 | $this->waitForElementPresent("group_id"); |
6a488035 TO |
57 | $this->select("group_id", "label=$groupName"); |
58 | $this->click("_qf_GroupContact_next"); | |
2af8120a | 59 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
60 | |
61 | $firstName2 = substr(sha1(rand()), 0, 7); | |
62 | $this->webtestAddContact($firstName2, "John", "$firstName2.john@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"); | |
2af8120a | 72 | $this->waitForElementPresent('link=Remove'); |
6a488035 TO |
73 | |
74 | // Enable CiviCampaign module if necessary | |
8f737a72 | 75 | $this->enableComponents(array('CiviCampaign')); |
6a488035 TO |
76 | |
77 | // add the required Drupal permission | |
42daf119 | 78 | $this->changePermissions('edit-2-administer-civicampaign'); |
6a488035 | 79 | |
42daf119 CW |
80 | // Log in as normal user |
81 | $this->webtestLogin(); | |
8f737a72 | 82 | $this->openCiviPage('campaign/add', 'reset=1', '_qf_Campaign_upload-bottom'); |
6a488035 | 83 | |
6a488035 TO |
84 | $campaignTitle = "Campaign $title"; |
85 | $this->type("title", $campaignTitle); | |
86 | ||
87 | // select the campaign type | |
88 | $this->select("campaign_type_id", "value=2"); | |
89 | ||
90 | // fill in the description | |
91 | $this->type("description", "This is a test campaign"); | |
92 | ||
93 | // include groups for the campaign | |
ba6f320f | 94 | $this->multiselect2("includeGroups", array("$groupName", "Advisory Board")); |
6a488035 TO |
95 | |
96 | // fill the end date for campaign | |
97 | $this->webtestFillDate("end_date", "+1 year"); | |
98 | ||
99 | // select campaign status | |
100 | $this->select("status_id", "value=2"); | |
101 | ||
102 | // click save | |
103 | $this->click("_qf_Campaign_upload-bottom"); | |
104 | $this->waitForPageToLoad($this->getTimeoutMsec()); | |
105 | ||
6c5f7368 | 106 | $this->waitForText('crm-notification-container', "Campaign $title"); |
751132dd WA |
107 | $this->waitForElementPresent("//table[@class='campaigns dataTable no-footer']/tbody//tr//td/div[contains(text(),'{$campaignTitle}')]/../../td[1]"); |
108 | $id = (int) $this->getText("//table[@class='campaigns dataTable no-footer']/tbody//tr//td/div[contains(text(),'{$campaignTitle}')]/../../td[1]"); | |
6a488035 TO |
109 | $this->memberAddTest($campaignTitle, $id); |
110 | } | |
111 | ||
4cbe18b8 EM |
112 | /** |
113 | * @param $campaignTitle | |
100fef9d | 114 | * @param int $id |
4cbe18b8 | 115 | */ |
00be9182 | 116 | public function memberAddTest($campaignTitle, $id) { |
a416f5a2 | 117 | //Add new membershipType |
6a488035 | 118 | $memTypeParams = $this->webtestAddMembershipType(); |
76e86fd8 | 119 | |
6a488035 TO |
120 | // Adding Adding contact with randomized first name for test testContactContextActivityAdd |
121 | // We're using Quick Add block on the main page for this. | |
122 | $firstName = substr(sha1(rand()), 0, 7); | |
123 | $this->webtestAddContact($firstName, "John", $firstName . "john@gmail.com"); | |
124 | $this->assertTrue($this->isTextPresent("{$firstName} John has been created.")); | |
125 | ||
126 | // click through to the membership view screen | |
127 | $this->click("css=li#tab_member a"); | |
128 | ||
129 | $this->waitForElementPresent("link=Add Membership"); | |
130 | $this->click("link=Add Membership"); | |
131 | ||
132 | $this->waitForElementPresent("_qf_Membership_cancel-bottom"); | |
133 | ||
134 | // fill in Membership Organization and Type | |
135 | $this->select("membership_type_id_0", "label={$memTypeParams['member_of_contact']}"); | |
136 | ||
137 | // Wait for membership type select to reload | |
138 | $this->waitForTextPresent($memTypeParams['membership_type']); | |
139 | $this->select("membership_type_id[1]", "label={$memTypeParams['membership_type']}"); | |
140 | ||
141 | $sourceText = "Membership ContactAddTest Webtest"; | |
142 | // fill in Source | |
143 | $this->type("source", $sourceText); | |
144 | ||
145 | // select campaign | |
146 | $this->click("campaign_id"); | |
147 | $this->select("campaign_id", "value=$id"); | |
148 | ||
6a488035 TO |
149 | // Let Join Date stay default |
150 | // fill in Start Date | |
151 | $this->webtestFillDate('start_date'); | |
152 | ||
153 | // Clicking save. | |
154 | $this->click("_qf_Membership_upload"); | |
2af8120a | 155 | $this->waitForElementPresent('link=View'); |
6a488035 TO |
156 | |
157 | // page was loaded | |
158 | $this->waitForTextPresent($sourceText); | |
159 | ||
160 | // Is status message correct? | |
161 | $this->assertTrue($this->isTextPresent("membership for $firstName John has been added."), | |
162 | "Status message didn't show up after saving!" | |
163 | ); | |
164 | ||
165 | // click through to the membership view screen | |
94b3c290 | 166 | $this->click("xpath=//div[@id='memberships']//table//tbody/tr[1]/td[9]//span/a[text()='View']"); |
6a488035 TO |
167 | $this->waitForElementPresent("_qf_MembershipView_cancel-bottom"); |
168 | ||
169 | $this->webtestVerifyTabularData(array('Campaign' => $campaignTitle)); | |
170 | } | |
96025800 | 171 | |
6a488035 | 172 | } |