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