Merge pull request #11679 from jitendrapurohit/CRM-21776
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / Task / InvoiceTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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 and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test APIv3 civicrm_contribute_* functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Contribution
33 * @group headless
34 */
35 class CRM_Contribute_Form_Task_InvoiceTest extends CiviUnitTestCase {
36 /**
37 * Assume empty database with just civicrm_data.
38 */
39 protected $_individualId;
40
41 /**
42 * Clean up after each test.
43 */
44 public function tearDown() {
45 $this->quickCleanUpFinancialEntities();
46 CRM_Utils_Hook::singleton()->reset();
47 }
48
49 /**
50 * CRM-17815 - Test due date and payment advice block in generated
51 * invoice pdf for pending and completed contributions
52 */
53 public function testInvoiceForDueDate() {
54 $contactIds = array();
55 $params = array(
56 'output' => 'pdf_invoice',
57 'forPage' => 1,
58 );
59
60 $this->_individualId = $this->individualCreate();
61 $contributionParams = array(
62 'contact_id' => $this->_individualId,
63 'total_amount' => 100,
64 'financial_type_id' => 'Donation',
65 );
66 $result = $this->callAPISuccess('Contribution', 'create', $contributionParams);
67
68 $contributionParams['contribution_status_id'] = 2;
69 $contributionParams['is_pay_later'] = 1;
70 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
71
72 $contribution3 = $this->callAPISuccess('Contribution', 'create', $contributionParams);
73 $this->callAPISuccess('Payment', 'create', array('total_amount' => 8, 'contribution_id' => $contribution3['id']));
74
75 $this->callAPISuccess('Contribution', 'create', array('id' => $contribution3['id'], 'is_pay_later' => 0));
76
77 $contributionIDs = array(
78 array($result['id']),
79 array($contribution['id']),
80 array($contribution3['id']),
81 );
82
83 $contactIds[] = $this->_individualId;
84 foreach ($contributionIDs as $contributionID) {
85 $invoiceHTML[current($contributionID)] = CRM_Contribute_Form_Task_Invoice::printPDF($contributionID, $params, $contactIds);
86 }
87
88 $this->assertNotContains('Due Date', $invoiceHTML[$result['id']]);
89 $this->assertNotContains('PAYMENT ADVICE', $invoiceHTML[$result['id']]);
90
91 $this->assertContains('Due Date', $invoiceHTML[$contribution['id']]);
92 $this->assertContains('PAYMENT ADVICE', $invoiceHTML[$contribution['id']]);
93
94 $this->assertContains('AMOUNT DUE: </font></b></td>
95 <td style = "padding-left:34px;text-align:right;"><b><font size = "1">$ 92.00</font></b></td>', $invoiceHTML[$contribution3['id']]);
96
97 }
98
99 }