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 * Assume empty database with just civicrm_data.
35 protected $_individualId;
38 * Clean up after each test.
40 public function tearDown() {
41 $this->quickCleanUpFinancialEntities();
42 CRM_Utils_Hook
::singleton()->reset();
46 * CRM-19722 - Check CRM_Contribute_Form_Task::preProcessCommon()
47 * executes without any error after sorting the search result.
49 public function testPreProcessCommonAfterSorting() {
51 'source' => 'contribution_source',
52 'status' => 'contribution_status',
53 'financialTypes' => 'financial_type',
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();
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],
68 $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
69 $contributionIds[] = $contribution['id'];
72 // Generate expected sorted array.
73 $expectedValues = array();
74 foreach ($fields as $key => $fld) {
75 $sortedFields = array_combine($
$key, $contributionIds);
77 $expectedValues[$fld] = $sortedFields;
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);
87 $contribIds = array_filter(array_map('intval', $form->get('contributionIds')));
88 $expectedValues = array_map('array_values', $expectedValues);
90 $this->assertEquals(array_values($contribIds), $expectedValues[$val], "Failed asserting values for {$val}");