7f20f38e |
1 | <?php |
2 | /* |
3 | +--------------------------------------------------------------------+ |
2fe49090 |
4 | | CiviCRM version 5 | |
7f20f38e |
5 | +--------------------------------------------------------------------+ |
6b83d5bd |
6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
7f20f38e |
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 | * Class CRM_Contribute_Form_Tasktest |
30 | */ |
6a7ec119 |
31 | class CRM_Contribute_Form_TaskTest extends CiviUnitTestCase { |
7f20f38e |
32 | /** |
33 | * Assume empty database with just civicrm_data. |
34 | */ |
35 | protected $_individualId; |
36 | |
37 | /** |
38 | * Clean up after each test. |
39 | */ |
40 | public function tearDown() { |
41 | $this->quickCleanUpFinancialEntities(); |
42 | CRM_Utils_Hook::singleton()->reset(); |
43 | } |
44 | |
45 | /** |
46 | * CRM-19722 - Check CRM_Contribute_Form_Task::preProcessCommon() |
47 | * executes without any error after sorting the search result. |
48 | */ |
49 | public function testPreProcessCommonAfterSorting() { |
50 | $fields = array( |
51 | 'source' => 'contribution_source', |
52 | 'status' => 'contribution_status', |
53 | 'financialTypes' => 'financial_type', |
54 | ); |
55 | $financialTypes = array('Member Dues', 'Event Fee', 'Donation'); |
56 | $status = array('Completed', 'Partially paid', 'Pending'); |
57 | $source = array('test source text', 'check source text', 'source text'); |
58 | $this->_individualId = $this->individualCreate(); |
59 | |
60 | for ($i = 0; $i < 3; $i++) { |
61 | $contributionParams = array( |
62 | 'contact_id' => $this->_individualId, |
63 | 'total_amount' => 100, |
64 | 'source' => $source[$i], |
65 | 'financial_type_id' => $financialTypes[$i], |
66 | 'contribution_status_id' => $status[$i], |
67 | ); |
68 | $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); |
69 | $contributionIds[] = $contribution['id']; |
70 | } |
71 | |
72 | // Generate expected sorted array. |
73 | $expectedValues = array(); |
74 | foreach ($fields as $key => $fld) { |
75 | $sortedFields = array_combine($$key, $contributionIds); |
76 | ksort($sortedFields); |
77 | $expectedValues[$fld] = $sortedFields; |
78 | } |
79 | |
80 | // Assert contribIds are returned in a sorted order. |
81 | $form = new CRM_Contribute_Form_Task(); |
82 | $form->controller = new CRM_Core_Controller(); |
83 | foreach ($fields as $val) { |
84 | $form->set(CRM_Utils_Sort::SORT_ORDER, "`{$val}` asc"); |
85 | CRM_Contribute_Form_Task::preProcessCommon($form); |
86 | |
87 | $contribIds = array_filter(array_map('intval', $form->get('contributionIds'))); |
88 | $expectedValues = array_map('array_values', $expectedValues); |
89 | |
90 | $this->assertEquals(array_values($contribIds), $expectedValues[$val], "Failed asserting values for {$val}"); |
91 | } |
92 | } |
93 | |
94 | } |