3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class CRM_Contribute_Form_Tasktest
31 class CRM_Contribute_Form_TaskTest
extends CiviUnitTestCase
{
33 protected $_individualId;
36 * Clean up after each test.
38 public function tearDown() {
39 $this->quickCleanUpFinancialEntities();
40 CRM_Utils_Hook
::singleton()->reset();
44 * CRM-19722 - Check CRM_Contribute_Form_Task::preProcessCommon()
45 * executes without any error after sorting the search result.
47 public function testPreProcessCommonAfterSorting() {
49 'source' => 'contribution_source',
50 'status' => 'contribution_status',
51 'financialTypes' => 'financial_type',
53 $financialTypes = ['Member Dues', 'Event Fee', 'Donation'];
54 $status = ['Completed', 'Partially paid', 'Pending'];
55 $source = ['test source text', 'check source text', 'source text'];
56 $this->_individualId
= $this->individualCreate();
58 for ($i = 0; $i < 3; $i++
) {
59 $contributionParams = [
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],
66 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
67 $contributionIds[] = $contribution['id'];
70 // Generate expected sorted array.
72 foreach ($fields as $key => $fld) {
73 $sortedFields = array_combine($
$key, $contributionIds);
75 $expectedValues[$fld] = $sortedFields;
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);
85 $contribIds = array_filter(array_map('intval', $form->get('contributionIds')));
86 $expectedValues = array_map('array_values', $expectedValues);
88 $this->assertEquals(array_values($contribIds), $expectedValues[$val], "Failed asserting values for {$val}");