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_Contribute_ContactContextAddTest | |
31 | */ | |
6a488035 TO |
32 | class WebTest_Contribute_ContactContextAddTest extends CiviSeleniumTestCase { |
33 | ||
34 | protected function setUp() { | |
35 | parent::setUp(); | |
36 | } | |
37 | ||
76e86fd8 CW |
38 | function testContactContextAdd() { |
39 | ||
6a488035 TO |
40 | // Log in using webtestLogin() method |
41 | $this->webtestLogin(); | |
76e86fd8 | 42 | |
6a488035 TO |
43 | // Create a contact to be used as soft creditor |
44 | $softCreditFname = substr(sha1(rand()), 0, 7); | |
45 | $softCreditLname = substr(sha1(rand()), 0, 7); | |
46 | $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); | |
76e86fd8 | 47 | |
6a488035 TO |
48 | // Adding contact with randomized first name (so we can then select that contact when creating contribution.) |
49 | // We're using Quick Add block on the main page for this. | |
50 | $firstName = substr(sha1(rand()), 0, 7); | |
51 | // Add new Financial Account | |
52 | $orgName = 'Alberta '.substr(sha1(rand()), 0, 7); | |
53 | $financialAccountTitle = 'Financial Account '.substr(sha1(rand()), 0, 4); | |
54 | $financialAccountDescription = "{$financialAccountTitle} Description"; | |
55 | $accountingCode = 1033; | |
56 | $financialAccountType = 'Asset'; | |
57 | $taxDeductible = FALSE; | |
58 | $isActive = FALSE; | |
59 | $isTax = TRUE; | |
60 | $taxRate = 9.99999999; | |
61 | $isDefault = FALSE; | |
76e86fd8 | 62 | |
6a488035 TO |
63 | //Add new organisation |
64 | if($orgName) { | |
65 | $this->webtestAddOrganization($orgName); | |
66 | } | |
67 | $this->_testAddFinancialAccount($financialAccountTitle, | |
68 | $financialAccountDescription, | |
69 | $accountingCode, | |
70 | $orgName, | |
71 | $financialAccountType, | |
72 | $taxDeductible, | |
73 | $isActive, | |
74 | $isTax, | |
75 | $taxRate, | |
76 | $isDefault | |
77 | ); | |
78 | ||
a471a3b6 | 79 | $this->webtestAddContact($firstName, "Anderson", true); |
76e86fd8 | 80 | |
6a488035 TO |
81 | // Get the contact id of the new contact |
82 | $contactUrl = $this->parseURL(); | |
83 | $cid = $contactUrl['queryString']['cid']; | |
84 | $this->assertType('numeric', $cid); | |
76e86fd8 | 85 | |
6a488035 TO |
86 | // go to contribution tab and add contribution. |
87 | $this->click("css=li#tab_contribute a"); | |
76e86fd8 | 88 | |
6a488035 TO |
89 | // wait for Record Contribution elenment. |
90 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); | |
91 | $this->click("link=Record Contribution (Check, Cash, EFT ...)"); | |
76e86fd8 | 92 | |
6a488035 TO |
93 | $this->waitForElementPresent("_qf_Contribution_cancel-bottom"); |
94 | // fill financial type. | |
95 | $this->select("financial_type_id", "Donation"); | |
76e86fd8 | 96 | |
6a488035 TO |
97 | // fill in Received Date |
98 | $this->webtestFillDate('receive_date'); | |
76e86fd8 | 99 | |
6a488035 TO |
100 | // source |
101 | $this->type("source", "Mailer 1"); | |
76e86fd8 | 102 | |
6a488035 TO |
103 | // total amount |
104 | $this->type("total_amount", "100"); | |
76e86fd8 | 105 | |
6a488035 TO |
106 | // select payment instrument type = Check and enter chk number |
107 | $this->select("payment_instrument_id", "value=4"); | |
108 | $this->waitForElementPresent("check_number"); | |
109 | $this->type("check_number", "check #1041"); | |
76e86fd8 | 110 | |
6a488035 | 111 | $this->type("trxn_id", "P20901X1" . rand(100, 10000)); |
76e86fd8 | 112 | |
6a488035 | 113 | // soft credit |
0ecb5006 | 114 | $this->webtestFillAutocomplete("{$softCreditLname}, {$softCreditFname}", 'soft_credit_contact_id_1'); |
115 | $this->type("soft_credit_amount_1", "100"); | |
6a488035 TO |
116 | |
117 | //Custom Data | |
118 | //$this->waitForElementPresent('CIVICRM_QFID_3_6'); | |
119 | //$this->click('CIVICRM_QFID_3_6'); | |
120 | ||
121 | //Additional Detail section | |
122 | $this->click("AdditionalDetail"); | |
123 | $this->waitForElementPresent("thankyou_date"); | |
76e86fd8 | 124 | |
6a488035 TO |
125 | $this->type("note", "Test note for {$firstName}."); |
126 | $this->type("fee_amount", "0"); | |
127 | $this->type("net_amount", "0"); | |
128 | $this->type("invoice_id", time()); | |
129 | $this->webtestFillDate('thankyou_date'); | |
130 | ||
6a488035 TO |
131 | |
132 | //Premium section | |
133 | $this->click("Premium"); | |
134 | $this->waitForElementPresent("fulfilled_date"); | |
135 | $this->select("product_name[0]", "label=Coffee Mug ( MUG-101 )"); | |
136 | $this->select("product_name[1]", "label=Black"); | |
137 | $this->webtestFillDate('fulfilled_date'); | |
138 | ||
139 | // Clicking save. | |
151d1477 | 140 | $this->clickLink("_qf_Contribution_upload-bottom", 'civicrm-footer', FALSE); |
6a488035 | 141 | // Is status message correct? |
6c5f7368 | 142 | $this->waitForText('crm-notification-container', "The contribution record has been saved"); |
76e86fd8 | 143 | |
0ecb5006 | 144 | $this->waitForElementPresent("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']"); |
151d1477 | 145 | $viewUrl = $this->parseURL($this->getAttribute("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']@href")); |
146 | $id = $viewUrl['queryString']['id']; | |
147 | $this->assertType('numeric', $id); | |
76e86fd8 | 148 | |
6a488035 | 149 | // click through to the Contribution view screen |
0ecb5006 | 150 | $this->click("xpath=//div[@class='view-content']/table[2]/tbody/tr/td[8]/span/a[text()='View']"); |
6a488035 TO |
151 | $this->waitForElementPresent('_qf_ContributionView_cancel-bottom'); |
152 | ||
153 | // verify Contribution created. Non-deductible amount derived from market value of selected 'sample' coffee mug premium (CRM-11956) | |
154 | $verifyData = array( | |
155 | 'From' => $firstName . " Anderson", | |
156 | 'Financial Type' => 'Donation', | |
157 | 'Contribution Status' => 'Completed', | |
158 | 'Paid By' => 'Check', | |
159 | 'Total Amount' => '$ 100.00', | |
160 | 'Non-deductible Amount' => '$ 12.50', | |
161 | 'Check Number' => 'check #1041', | |
162 | ); | |
163 | foreach ($verifyData as $label => $value) { | |
164 | $this->verifyText("xpath=//form[@id='ContributionView']//table/tbody/tr/td[text()='{$label}']/following-sibling::td", | |
165 | preg_quote($value) | |
166 | ); | |
167 | } | |
168 | ||
169 | // check values of contribution record in the DB | |
76e86fd8 | 170 | |
6a488035 TO |
171 | $searchParams = array('id' => $id); |
172 | $compareParams = array( | |
173 | 'contact_id' => $cid, | |
174 | 'total_amount' => '100.00', | |
175 | ); | |
176 | $this->assertDBCompareValues('CRM_Contribute_DAO_Contribution', $searchParams, $compareParams); | |
177 | ||
178 | // go to soft creditor contact view page | |
151d1477 | 179 | $this->clickLink("css=table.crm-soft-credit-listing tbody tr td a"); |
6a488035 TO |
180 | |
181 | // go to contribution tab | |
182 | $this->waitForElementPresent("css=li#tab_contribute a"); | |
183 | $this->click("css=li#tab_contribute a"); | |
184 | $this->waitForElementPresent("link=Record Contribution (Check, Cash, EFT ...)"); | |
185 | ||
186 | // verify soft credit details | |
187 | $expected = array( | |
0ecb5006 | 188 | 4 => 'Donation', |
6a488035 | 189 | 2 => '100.00', |
0ecb5006 | 190 | 6 => 'Completed', |
6a488035 TO |
191 | 1 => "{$firstName} Anderson", |
192 | ); | |
193 | foreach ($expected as $value => $label) { | |
151d1477 | 194 | $this->verifyText("xpath=id('Search')/div[2]/table[2]/tbody//tr/td[$value]", preg_quote($label)); |
6a488035 TO |
195 | } |
196 | } | |
197 | } | |
198 |