(NFC) (dev/core#878) Simplify copyright header (tests/*)
[civicrm-core.git] / tests / phpunit / CRM / Contribute / Form / TaskTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | Use of this source code is governed by the AGPL license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Class CRM_Contribute_Form_Tasktest
14 */
15 class CRM_Contribute_Form_TaskTest extends CiviUnitTestCase {
16
17 protected $_individualId;
18
19 /**
20 * Clean up after each test.
21 */
22 public function tearDown() {
23 $this->quickCleanUpFinancialEntities();
24 CRM_Utils_Hook::singleton()->reset();
25 }
26
27 /**
28 * CRM-19722 - Check CRM_Contribute_Form_Task::preProcessCommon()
29 * executes without any error after sorting the search result.
30 */
31 public function testPreProcessCommonAfterSorting() {
32 $fields = [
33 'source' => 'contribution_source',
34 'status' => 'contribution_status',
35 'financialTypes' => 'financial_type',
36 ];
37 $financialTypes = ['Member Dues', 'Event Fee', 'Donation'];
38 $status = ['Completed', 'Partially paid', 'Pending'];
39 $source = ['test source text', 'check source text', 'source text'];
40 $this->_individualId = $this->individualCreate();
41
42 for ($i = 0; $i < 3; $i++) {
43 $contributionParams = [
44 'contact_id' => $this->_individualId,
45 'total_amount' => 100,
46 'source' => $source[$i],
47 'financial_type_id' => $financialTypes[$i],
48 'contribution_status_id' => $status[$i],
49 ];
50 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
51 $contributionIds[] = $contribution['id'];
52 }
53
54 // Generate expected sorted array.
55 $expectedValues = [];
56 foreach ($fields as $key => $fld) {
57 $sortedFields = array_combine($$key, $contributionIds);
58 ksort($sortedFields);
59 $expectedValues[$fld] = $sortedFields;
60 }
61
62 // Assert contribIds are returned in a sorted order.
63 $form = new CRM_Contribute_Form_Task();
64 $form->controller = new CRM_Core_Controller();
65 foreach ($fields as $val) {
66 $form->set(CRM_Utils_Sort::SORT_ORDER, "`{$val}` asc");
67 CRM_Contribute_Form_Task::preProcessCommon($form);
68
69 $contribIds = array_filter(array_map('intval', $form->get('contributionIds')));
70 $expectedValues = array_map('array_values', $expectedValues);
71
72 $this->assertEquals(array_values($contribIds), $expectedValues[$val], "Failed asserting values for {$val}");
73 }
74 }
75
76 }