From f78dbf0b4efa9b5155dace9699783a447665cb73 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 16 Jul 2019 19:16:27 +1200 Subject: [PATCH] Reformat arrays in tests --- .../CRM/Event/BAO/AdditionalPaymentTest.php | 19 +-- .../CRM/Event/BAO/ChangeFeeSelectionTest.php | 119 ++++++++++-------- .../phpunit/CRM/Event/BAO/ParticipantTest.php | 77 ++++++------ .../CRM/Event/Form/ParticipantTest.php | 78 ++++++------ tests/phpunit/CRM/Price/Form/OptionTest.php | 60 ++++----- tests/phpunit/api/v3/GroupTest.php | 83 ++++++------ tests/phpunit/api/v3/ImTest.php | 30 +++-- tests/phpunit/api/v3/LocBlockTest.php | 45 +++---- tests/phpunit/api/v3/MailSettingsTest.php | 42 ++++--- tests/phpunit/api/v3/OptionGroupTest.php | 71 +++++------ 10 files changed, 340 insertions(+), 284 deletions(-) diff --git a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php index 9e70d946bf..4471184896 100644 --- a/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php +++ b/tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php @@ -27,6 +27,7 @@ /** * Class CRM_Event_BAO_AdditionalPaymentTest + * * @group headless */ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { @@ -77,7 +78,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $participantParams ); $participant = $this->callAPISuccess('participant', 'create', $participantParams); - $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); + $this->callAPISuccessGetSingle('participant', ['id' => $participant['id']]); // create participant contribution with partial payment $contributionParams = array_merge( [ @@ -99,16 +100,16 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $contributionId = $contribution['id']; - $participant = $this->callAPISuccessGetSingle('participant', array('id' => $participant['id'])); + $participant = $this->callAPISuccessGetSingle('participant', ['id' => $participant['id']]); // add participant payment entry - $this->callAPISuccess('participant_payment', 'create', array( + $this->callAPISuccess('participant_payment', 'create', [ 'participant_id' => $participant['id'], 'contribution_id' => $contributionId, - )); + ]); // -- processing priceSet using the BAO - $lineItem = array(); + $lineItem = []; $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE); $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet); $feeBlock = CRM_Utils_Array::value('fields', $priceSet); @@ -121,14 +122,14 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { $lineItemVal[$priceSetId] = $lineItem; CRM_Price_BAO_LineItem::processPriceSet($participant['id'], $lineItemVal, $this->getContributionObject($contributionId), 'civicrm_participant'); - return array( + return [ 'participant' => $participant, 'contribution' => $contribution['values'][$contribution['id']], 'lineItem' => $templineItems, 'params' => $tempParams, 'feeBlock' => $feeBlock, 'priceSetId' => $priceSetId, - ); + ]; } /** @@ -162,7 +163,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { // make additional payment via 'Record Payment' form $form = new CRM_Contribute_Form_AdditionalPayment(); - $submitParams = array( + $submitParams = [ 'contact_id' => $result['contribution']['contact_id'], 'contribution_id' => $contributionID, 'total_amount' => 100, @@ -171,7 +172,7 @@ class CRM_Event_BAO_AdditionalPaymentTest extends CiviUnitTestCase { 'payment_processor_id' => 0, 'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'), 'check_number' => '#123', - ); + ]; $form->cid = $result['contribution']['contact_id']; $form->testSubmit($submitParams); diff --git a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php index 95a5ec198f..5a7322b745 100644 --- a/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php +++ b/tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php @@ -1,18 +1,28 @@ _contactId = $this->individualCreate(); - $event = $this->eventCreate(array('is_monetary' => 1)); + $event = $this->eventCreate(['is_monetary' => 1]); $this->_eventId = $event['id']; $this->_priceSetID = $this->priceSetCreate(); CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $this->_priceSetID); @@ -73,10 +83,10 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { /** * Create an event with a price set. * - * @todo resolve this with parent function. * @param string $type * * @return int + * @todo resolve this with parent function. */ protected function priceSetCreate($type = 'Radio') { $feeTotal = 55; @@ -89,44 +99,44 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $priceSet = CRM_Price_BAO_PriceSet::create($paramsSet); if ($type == 'Text') { - $paramsField = array( + $paramsField = [ 'label' => 'Text Price Field', 'name' => CRM_Utils_String::titleToVar('text_price_field'), 'html_type' => 'Text', - 'option_label' => array('1' => 'Text Price Field'), - 'option_name' => array('1' => CRM_Utils_String::titleToVar('text_price_field')), - 'option_weight' => array('1' => 1), - 'option_amount' => array('1' => 10), - 'option_count' => array(1 => 1), + 'option_label' => ['1' => 'Text Price Field'], + 'option_name' => ['1' => CRM_Utils_String::titleToVar('text_price_field')], + 'option_weight' => ['1' => 1], + 'option_amount' => ['1' => 10], + 'option_count' => [1 => 1], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1), + 'is_active' => ['1' => 1], 'price_set_id' => $priceSet->id, 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), - ); + ]; } else { - $paramsField = array( + $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Two Options'), 'html_type' => 'Radio', //'price' => $feeTotal, - 'option_label' => array('1' => 'Expensive Room', '2' => "Cheap Room", '3' => 'Very Expensive', '4' => 'No Fee'), - 'option_value' => array('1' => 'E', '2' => 'C', '3' => 'V', '4' => 'N'), - 'option_name' => array('1' => 'Expensive', '2' => "Cheap", "3" => "Very Expensive", '3' => 'No Fee'), - 'option_weight' => array('1' => 1, '2' => 2, '3' => 3, '4' => 4), - 'option_amount' => array('1' => $this->_expensiveFee, '2' => $this->_cheapFee, '3' => $this->_veryExpensive, '4' => $this->_noFee), - 'option_count' => array(1 => 1, 2 => 1, 3 => 1, 4 => 1), + 'option_label' => ['1' => 'Expensive Room', '2' => "Cheap Room", '3' => 'Very Expensive', '4' => 'No Fee'], + 'option_value' => ['1' => 'E', '2' => 'C', '3' => 'V', '4' => 'N'], + 'option_name' => ['1' => 'Expensive', '2' => "Cheap", "3" => "Very Expensive", '3' => 'No Fee'], + 'option_weight' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4], + 'option_amount' => ['1' => $this->_expensiveFee, '2' => $this->_cheapFee, '3' => $this->_veryExpensive, '4' => $this->_noFee], + 'option_count' => [1 => 1, 2 => 1, 3 => 1, 4 => 1], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1), + 'is_active' => ['1' => 1], 'price_set_id' => $priceSet->id, 'is_enter_qty' => 1, 'financial_type_id' => $this->getFinancialTypeId('Event Fee'), - ); + ]; } $field = CRM_Price_BAO_PriceField::create($paramsField); $values = $this->callAPISuccess('PriceFieldValue', 'get', [ @@ -162,6 +172,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { * Get the total for the invoice. * * @param int $contributionId + * * @return mixed */ private function contributionInvoice($contributionId) { @@ -209,7 +220,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { * Prepare records for editing. */ public function registerParticipantAndPay($actualPaidAmt = NULL) { - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -220,13 +231,13 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, //'fee_level' => CRM_Core_DAO::VALUE_SEPARATOR.'Expensive Room'.CRM_Core_DAO::VALUE_SEPARATOR, - ); + ]; $participant = $this->callAPISuccess('Participant', 'create', $params); $this->_participantId = $participant['id']; $actualPaidAmt = $actualPaidAmt ? $actualPaidAmt : $this->_expensiveFee; - $contributionParams = array( + $contributionParams = [ 'total_amount' => $actualPaidAmt, 'source' => 'Testset with information', 'currency' => 'USD', @@ -239,15 +250,15 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'skipLineItem' => 1, 'partial_payment_total' => $this->_expensiveFee, 'partial_amount_to_pay' => $actualPaidAmt, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $this->_contributionId = $contribution['id']; - $this->callAPISuccess('participant_payment', 'create', array( - 'participant_id' => $this->_participantId, + $this->callAPISuccess('participant_payment', 'create', [ + 'participant_id' => $this->_participantId, 'contribution_id' => $this->_contributionId, - )); + ]); $priceSetParams['price_' . $this->priceSetFieldID] = $this->expensiveFeeValueID; @@ -287,12 +298,12 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { public function testCRM21245() { $this->registerParticipantAndPay(50); $partiallyPaidContribuitonStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid'); - $this->assertEquals($this->callAPISuccessGetValue('Contribution', array('id' => $this->_contributionId, 'return' => 'contribution_status_id')), $partiallyPaidContribuitonStatus); + $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus); $priceSetParams['price_' . $this->priceSetFieldID] = $this->veryExpensiveFeeValueID; $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant'); CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem); - $this->assertEquals($this->callAPISuccessGetValue('Contribution', array('id' => $this->_contributionId, 'return' => 'contribution_status_id')), $partiallyPaidContribuitonStatus); + $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus); } /** @@ -325,16 +336,16 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $this->assertEquals($contributionBalance, CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId)); // retrieve the cancelled line-item information - $cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', array( + $cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', [ 'entity_table' => 'civicrm_participant', 'entity_id' => $this->_participantId, 'qty' => 0, - )); + ]); // retrieve the related financial lin-items - $financialItems = $this->callAPISuccess('FinancialItem', 'Get', array( + $financialItems = $this->callAPISuccess('FinancialItem', 'Get', [ 'entity_id' => $cancelledLineItem['id'], 'entity_table' => 'civicrm_line_item', - )); + ]); $this->assertEquals($financialItems['count'], 2, 'Financial Items for Cancelled fee is not proper'); $contributionCompletedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); @@ -357,7 +368,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $priceSet = CRM_Utils_Array::value($this->_priceSetID, $priceSet); $this->_feeBlock = CRM_Utils_Array::value('fields', $priceSet); - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -367,10 +378,10 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, - ); + ]; $participant = $this->callAPISuccess('Participant', 'create', $params); $this->_participantId = $participant['id']; - $contributionParams = array( + $contributionParams = [ 'total_amount' => 10, 'source' => 'Testset with information', 'currency' => 'USD', @@ -381,15 +392,15 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { 'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending'), 'receive_date' => date('Y-m-d') . " 00:00:00", 'skipLineItem' => 1, - ); + ]; $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams); $this->_contributionId = $contribution['id']; - $this->callAPISuccess('participant_payment', 'create', array( - 'participant_id' => $this->_participantId, + $this->callAPISuccess('participant_payment', 'create', [ + 'participant_id' => $this->_participantId, 'contribution_id' => $this->_contributionId, - )); + ]); // CASE 1: Choose text price qty 1 (x$10 = $10 amount) $priceSetParams['price_' . $this->priceSetFieldID] = 1; @@ -408,36 +419,36 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant'); CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, 0); - $financialItems = $this->callAPISuccess('FinancialItem', 'Get', array( + $financialItems = $this->callAPISuccess('FinancialItem', 'Get', [ 'entity_table' => 'civicrm_line_item', - 'entity_id' => array('IN' => array_keys($lineItem)), + 'entity_id' => ['IN' => array_keys($lineItem)], 'sequential' => 1, - )); + ]); $unpaidStatus = CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialItem', 'status_id', 'Unpaid'); - $expectedResults = array( - array( + $expectedResults = [ + [ // when qty 1 is used 'amount' => 10.00, 'status_id' => $unpaidStatus, 'entity_table' => 'civicrm_line_item', 'entity_id' => 1, - ), - array( + ], + [ // when qty 3 is used, add the surplus amount i.e. $30 - $10 = $20 'amount' => 20.00, 'status_id' => $unpaidStatus, 'entity_table' => 'civicrm_line_item', 'entity_id' => 1, - ), - array( + ], + [ // when qty 2 is used, add the surplus amount i.e. $20 - $30 = -$10 'amount' => -10.00, 'status_id' => $unpaidStatus, 'entity_table' => 'civicrm_line_item', 'entity_id' => 1, - ), - ); + ], + ]; // Check if 3 financial items were recorded $this->assertEquals(count($expectedResults), $financialItems['count']); foreach ($expectedResults as $key => $expectedResult) { @@ -504,16 +515,16 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase { $this->assertEquals($contributionBalance, CRM_Contribute_BAO_Contribution::getContributionBalance($this->_contributionId)); // retrieve the cancelled line-item information - $cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', array( + $cancelledLineItem = $this->callAPISuccessGetSingle('LineItem', [ 'entity_table' => 'civicrm_participant', 'entity_id' => $this->_participantId, 'qty' => 0, - )); + ]); // retrieve the related financial lin-items - $financialItems = $this->callAPISuccess('FinancialItem', 'Get', array( + $financialItems = $this->callAPISuccess('FinancialItem', 'Get', [ 'entity_id' => $cancelledLineItem['id'], 'entity_table' => 'civicrm_line_item', - )); + ]); $this->assertEquals($financialItems['count'], 2, 'Financial Items for Cancelled fee is not proper'); $contributionCompletedStatusID = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); diff --git a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php index e124b4d291..251e9ac104 100644 --- a/tests/phpunit/CRM/Event/BAO/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/BAO/ParticipantTest.php @@ -27,6 +27,7 @@ /** * Class CRM_Event_BAO_ParticipantTest + * * @group headless */ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { @@ -42,7 +43,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * Add() method (add and edit modes of participant) */ public function testAdd() { - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -52,7 +53,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, - ); + ]; // New Participant Created $participant = CRM_Event_BAO_Participant::add($params); @@ -65,11 +66,11 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'id', $this->_contactId, 'Check DB for contact of the participant' ); - $params = array_merge($params, array( + $params = array_merge($params, [ 'id' => $participant->id, 'role_id' => 2, 'status_id' => 3, - )); + ]); // Participant Edited $updatedParticipant = CRM_Event_BAO_Participant::add($params); @@ -89,14 +90,14 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * GetValues() method (fetch value of participant) */ public function testgetValuesWithValidParams() { - $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); - $params = array('id' => $participantId); - $values = $ids = array(); + $participantId = $this->participantCreate(['contact_id' => $this->_contactId, 'event_id' => $this->_eventId]); + $params = ['id' => $participantId]; + $values = $ids = []; $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); $compareValues = $fetchParticipant[$participantId]; - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -117,7 +118,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'cart_id' => NULL, 'must_wait' => NULL, 'transferred_to_contact_id' => NULL, - ); + ]; foreach ($compareValues as $key => $value) { if (substr($key, 0, 1) != '_' && $key != 'N') { @@ -134,8 +135,8 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * GetValues() method (checking for behavior when params are empty ) */ public function testgetValuesWithoutValidParams() { - $params = $values = $ids = array(); - $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); + $params = $values = $ids = []; + $this->participantCreate(['contact_id' => $this->_contactId, 'event_id' => $this->_eventId]); $fetchParticipant = CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNull($fetchParticipant); @@ -147,13 +148,13 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * EventFull() method (checking the event for full ) */ public function testEventFull() { - $eventParams = array( + $eventParams = [ 'max_participants' => 1, 'id' => $this->_eventId, - ); + ]; CRM_Event_BAO_Event::add($eventParams); - $participantId = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); + $participantId = $this->participantCreate(['contact_id' => $this->_contactId, 'event_id' => $this->_eventId]); $eventFull = CRM_Event_BAO_Participant::eventFull($this->_eventId); $this->assertEquals($eventFull, 'Sorry! We are already full', 'Checking if Event is full.'); @@ -178,8 +179,8 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * ParticipantDetails() method ( Checking the Participant Details ) */ public function testparticipantDetails() { - $participant = $this->callAPISuccess('Participant', 'create', array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); - $params = array('name' => 'Anderson, Anthony', 'title' => 'Annual CiviCRM meet'); + $participant = $this->callAPISuccess('Participant', 'create', ['contact_id' => $this->_contactId, 'event_id' => $this->_eventId]); + $params = ['name' => 'Anderson, Anthony', 'title' => 'Annual CiviCRM meet']; $participantDetails = CRM_Event_BAO_Participant::participantDetails($participant['id']); @@ -196,7 +197,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * DeleteParticipant() method ( Delete a Participant ) */ public function testdeleteParticipant() { - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -206,7 +207,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'status_id' => 1, 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, - ); + ]; // New Participant Created $participant = CRM_Event_BAO_Participant::add($params); @@ -230,14 +231,14 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * CheckDuplicate() method ( Checking for Duplicate Participant returns array of participant id) */ public function testcheckDuplicate() { - $duplicate = array(); + $duplicate = []; //Creating 3 new participants for ($i = 0; $i < 3; $i++) { - $partiId[] = $this->participantCreate(array('contact_id' => $this->_contactId, 'event_id' => $this->_eventId)); + $partiId[] = $this->participantCreate(['contact_id' => $this->_contactId, 'event_id' => $this->_eventId]); } - $params = array('event_id' => $this->_eventId, 'contact_id' => $this->_contactId); + $params = ['event_id' => $this->_eventId, 'contact_id' => $this->_contactId]; CRM_Event_BAO_Participant::checkDuplicate($params, $duplicate); $this->assertEquals(count($duplicate), 3, 'Equating the array contains with duplicate array.'); @@ -260,7 +261,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { * Create() method (create and updation of participant) */ public function testCreate() { - $params = array( + $params = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -271,7 +272,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'source' => 'Event_' . $this->_eventId, 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $this->_eventId, - ); + ]; $participant = CRM_Event_BAO_Participant::create($params); //Checking for Contact id in the participant table. @@ -284,12 +285,12 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'source_contact_id', $participant->id, 'Check DB for activity added for the participant' ); - $params = array_merge($params, array( + $params = array_merge($params, [ 'id' => $participant->id, 'role_id' => 2, 'status_id' => 3, 'note' => 'Test Event in edit mode is running successfully ....', - )); + ]); $participant = CRM_Event_BAO_Participant::create($params); @@ -352,24 +353,24 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { $this->assertDBCompareValue('CRM_Price_BAO_PriceSet', $priceset->id, 'title', 'id', $paramsSet['title'], 'Check DB for created priceset' ); - $paramsField = array( + $paramsField = [ 'label' => 'Price Field', 'name' => CRM_Utils_String::titleToVar('Price Field'), 'html_type' => 'Text', 'price' => 10, - 'option_label' => array('1' => 'Price Field'), - 'option_value' => array('1' => 10), - 'option_name' => array('1' => 10), - 'option_weight' => array('1' => 1), + 'option_label' => ['1' => 'Price Field'], + 'option_value' => ['1' => 10], + 'option_name' => ['1' => 10], + 'option_weight' => ['1' => 1], 'is_display_amounts' => 1, 'weight' => 1, 'options_per_line' => 1, - 'is_active' => array('1' => 1), + 'is_active' => ['1' => 1], 'price_set_id' => $priceset->id, 'is_enter_qty' => 1, - ); + ]; - $ids = array(); + $ids = []; $pricefield = CRM_Price_BAO_PriceField::create($paramsField, $ids); //Checking for priceset added in the table. @@ -378,7 +379,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { ); $eventId = $this->_eventId; - $participantParams = array( + $participantParams = [ 'send_receipt' => 1, 'is_test' => 0, 'is_pay_later' => 0, @@ -390,7 +391,7 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'contact_id' => $this->_contactId, 'note' => 'Note added for Event_' . $eventId, 'fee_level' => 'Price_Field - 55', - ); + ]; $participant = CRM_Event_BAO_Participant::add($participantParams); @@ -399,9 +400,9 @@ class CRM_Event_BAO_ParticipantTest extends CiviUnitTestCase { 'contact_id', $participant->id, 'Check DB for created participant' ); - $values = array(); - $ids = array(); - $params = array('id' => $participant->id); + $values = []; + $ids = []; + $params = ['id' => $participant->id]; CRM_Event_BAO_Participant::getValues($params, $values, $ids); $this->assertNotEquals(count($values), 0, 'Checking for empty array.'); diff --git a/tests/phpunit/CRM/Event/Form/ParticipantTest.php b/tests/phpunit/CRM/Event/Form/ParticipantTest.php index 0620678b4c..1b73d11180 100644 --- a/tests/phpunit/CRM/Event/Form/ParticipantTest.php +++ b/tests/phpunit/CRM/Event/Form/ParticipantTest.php @@ -20,13 +20,13 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { */ public function testSubmit() { $form = $this->getForm(); - $form->submit(array( + $form->submit([ 'register_date' => date('Ymd'), 'status_id' => 1, 'role_id' => 1, 'event_id' => $form->_eventId, - )); - $participants = $this->callAPISuccess('Participant', 'get', array()); + ]); + $participants = $this->callAPISuccess('Participant', 'get', []); $this->assertEquals(1, $participants['count']); } @@ -36,12 +36,12 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { * @throws \Exception */ public function testSubmitUnpaidPriceChangeWhileStillPending() { - $form = $this->getForm(array('is_monetary' => 1, 'financial_type_id' => 1)); + $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); $form->_quickConfig = TRUE; - $form->_lineItem = array( - 0 => array( - 13 => array( + $form->_lineItem = [ + 0 => [ + 13 => [ 'price_field_id' => $this->_ids['price_field'][0], 'price_field_value_id' => $this->_ids['price_field_value'][0], 'label' => 'Tiny-tots (ages 5-8)', @@ -59,20 +59,20 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'financial_type_id' => '4', 'tax_amount' => NULL, 'non_deductible_amount' => '0.00', - ), - ), - ); + ], + ], + ]; $form->setAction(CRM_Core_Action::ADD); $form->_priceSetId = $this->_ids['price_set']; - $form->submit(array( + $form->submit([ 'register_date' => date('Ymd'), 'status_id' => 5, 'role_id' => 1, 'event_id' => $form->_eventId, 'priceSetId' => $this->_ids['price_set'], - 'price_' . $this->_ids['price_field'][0] => array( + 'price_' . $this->_ids['price_field'][0] => [ $this->_ids['price_field_value'][0] => 1, - ), + ], 'is_pay_later' => 1, 'amount_level' => 'Too much', 'fee_amount' => 55, @@ -82,18 +82,18 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'financial_type_id' => 1, 'contribution_status_id' => 2, 'payment_instrument_id' => 1, - )); - $participants = $this->callAPISuccess('Participant', 'get', array()); + ]); + $participants = $this->callAPISuccess('Participant', 'get', []); $this->assertEquals(1, $participants['count']); - $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertEquals(2, $contribution['contribution_status_id']); - $items = $this->callAPISuccess('FinancialItem', 'get', array()); + $items = $this->callAPISuccess('FinancialItem', 'get', []); $this->assertEquals(1, $items['count']); $priceSetParams['price_' . $this->_ids['price_field'][0]] = $this->_ids['price_field_value'][1]; $lineItem = CRM_Price_BAO_LineItem::getLineItems($participants['id'], 'participant'); $this->assertEquals(55, $lineItem[1]['subTotal']); - $financialItems = $this->callAPISuccess('FinancialItem', 'get', array()); + $financialItems = $this->callAPISuccess('FinancialItem', 'get', []); $sum = 0; foreach ($financialItems['values'] as $financialItem) { $sum += $financialItem['amount']; @@ -105,7 +105,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { // Participants is updated to 0 but line remains. $this->assertEquals(0, $lineItem[1]['subTotal']); $this->assertEquals(100, $lineItem[2]['subTotal']); - $financialItems = $this->callAPISuccess('FinancialItem', 'get', array()); + $financialItems = $this->callAPISuccess('FinancialItem', 'get', []); $sum = 0; foreach ($financialItems['values'] as $financialItem) { @@ -178,27 +178,27 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { */ public function testSubmitWithPayment($thousandSeparator, $fromEmails = []) { $this->setCurrencySeparators($thousandSeparator); - $form = $this->getForm(array('is_monetary' => 1, 'financial_type_id' => 1)); + $form = $this->getForm(['is_monetary' => 1, 'financial_type_id' => 1]); $form->_mode = 'Live'; $form->_quickConfig = TRUE; - $paymentProcessorID = $this->processorCreate(array('is_test' => 0)); + $paymentProcessorID = $this->processorCreate(['is_test' => 0]); if (empty($fromEmails)) { $fromEmails = [ 'from_email_id' => ['abc@gmail.com' => 1], ]; } $form->_fromEmails = $fromEmails; - $form->submit(array( + $form->submit([ 'register_date' => date('Ymd'), 'status_id' => 1, 'role_id' => 1, 'event_id' => $form->_eventId, 'credit_card_number' => 4444333322221111, 'cvv2' => 123, - 'credit_card_exp_date' => array( + 'credit_card_exp_date' => [ 'M' => 9, 'Y' => 2025, - ), + ], 'credit_card_type' => 'Visa', 'billing_first_name' => 'Junko', 'billing_middle_name' => '', @@ -210,19 +210,19 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { 'billing_country_id-5' => 1228, 'payment_processor_id' => $paymentProcessorID, 'priceSetId' => '6', - 'price_7' => array( + 'price_7' => [ 13 => 1, - ), + ], 'amount_level' => 'Too much', 'fee_amount' => $this->formatMoneyInput(1550.55), 'total_amount' => $this->formatMoneyInput(1550.55), 'from_email_address' => array_keys($form->_fromEmails['from_email_id'])[0], 'send_receipt' => 1, 'receipt_text' => '', - )); - $participants = $this->callAPISuccess('Participant', 'get', array()); + ]); + $participants = $this->callAPISuccess('Participant', 'get', []); $this->assertEquals(1, $participants['count']); - $contribution = $this->callAPISuccessGetSingle('Contribution', array()); + $contribution = $this->callAPISuccessGetSingle('Contribution', []); $this->assertEquals(1550.55, $contribution['total_amount']); $this->assertEquals('Debit Card', $contribution['payment_instrument']); } @@ -247,26 +247,26 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { ]); //Get workflow id of event_offline receipt. - $workflowId = $this->callAPISuccess('OptionValue', 'get', array( - 'return' => array("id"), + $workflowId = $this->callAPISuccess('OptionValue', 'get', [ + 'return' => ["id"], 'option_group_id' => "msg_tpl_workflow_event", 'name' => "event_offline_receipt", - )); + ]); //Modify html to contain event_type_id token. - $result = $this->callAPISuccess('MessageTemplate', 'get', array( + $result = $this->callAPISuccess('MessageTemplate', 'get', [ 'sequential' => 1, - 'return' => array("id", "msg_html"), + 'return' => ["id", "msg_html"], 'workflow_id' => $workflowId['id'], 'is_default' => 1, - )); + ]); $oldMsg = $result['values'][0]['msg_html']; $pos = strpos($oldMsg, 'Please print this confirmation'); $newMsg = substr_replace($oldMsg, '

Test event type - {$event.event_type_id}

', $pos, 0); - $this->callAPISuccess('MessageTemplate', 'create', array( + $this->callAPISuccess('MessageTemplate', 'create', [ 'id' => $result['id'], 'msg_html' => $newMsg, - )); + ]); // Use the email created as the from email ensuring we are passing a numeric from to test dev/core#1069 $this->testSubmitWithPayment($thousandSeparator, ['from_email_id' => [$email['id'] => 1]]); @@ -297,7 +297,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { } $contactID = $this->individualCreate(); - /** @var CRM_Event_Form_Participant $form*/ + /** @var CRM_Event_Form_Participant $form */ $form = $this->getFormObject('CRM_Event_Form_Participant'); $form->_single = TRUE; $form->_contactID = $form->_contactId = $contactID; @@ -341,7 +341,7 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase { $fieldParams['name'] = CRM_Utils_String::titleToVar($fieldToCreate['label']); $fieldParams['price'] = $fieldToCreate['amount']; $this->_ids['price_field'][strtolower(CRM_Utils_String::titleToVar($fieldToCreate['label']))] = $textPriceFieldID = $this->callAPISuccess('PriceField', 'create', $fieldParams)['id']; - $this->_ids['price_field_value'][strtolower(CRM_Utils_String::titleToVar($fieldToCreate['label']))] = (int) $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $textPriceFieldID])['id']; + $this->_ids['price_field_value'][strtolower(CRM_Utils_String::titleToVar($fieldToCreate['label']))] = (int) $this->callAPISuccess('PriceFieldValue', 'getsingle', ['price_field_id' => $textPriceFieldID])['id']; } $form->_lineItem = [ diff --git a/tests/phpunit/CRM/Price/Form/OptionTest.php b/tests/phpunit/CRM/Price/Form/OptionTest.php index faf6c0b720..64fbd4ffc6 100644 --- a/tests/phpunit/CRM/Price/Form/OptionTest.php +++ b/tests/phpunit/CRM/Price/Form/OptionTest.php @@ -3,44 +3,48 @@ class CRM_Price_Form_OptionTest extends CiviUnitTestCase { protected $priceFieldValues; + protected $visibilityOptionsKeys; + protected $visibilityOptions; + protected $publicValue; + protected $adminValue; public function setUp() { parent::setUp(); - $this->visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array( + $this->visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ 'labelColumn' => 'name', - )); - $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array( + ]); + $this->visibilityOptionsKeys = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, [ 'labelColumn' => 'name', 'flip' => TRUE, - )); + ]); } public function testChangingUniquePublicOptionOnPublicFieldIsNotAllowed() { - $this->setUpPriceSet(array( + $this->setUpPriceSet([ 'html_type' => 'Select', 'visibility_id' => $this->visibilityOptionsKeys['public'], - 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_value' => array('1' => 100, '2' => 200), - 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_weight' => array('1' => 1, '2' => 2), - 'option_amount' => array('1' => 100, '2' => 200), - 'option_visibility_id' => array(1 => $this->visibilityOptionsKeys['public'], 2 => $this->visibilityOptionsKeys['admin']), - )); - - $params = array( + 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_value' => ['1' => 100, '2' => 200], + 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_weight' => ['1' => 1, '2' => 2], + 'option_amount' => ['1' => 100, '2' => 200], + 'option_visibility_id' => [1 => $this->visibilityOptionsKeys['public'], 2 => $this->visibilityOptionsKeys['admin']], + ]); + + $params = [ 'fieldId' => $this->publicValue['price_field_id'], 'optionId' => $this->publicValue['id'], 'visibility_id' => $this->visibilityOptionsKeys['admin'], - ); + ]; $form = new CRM_Price_Form_Option(); $form->_action = CRM_Core_Action::ADD; - $files = array(); + $files = []; $validationResult = $form->formRule($params, $files, $form); $this->assertType('array', $validationResult); @@ -48,26 +52,26 @@ class CRM_Price_Form_OptionTest extends CiviUnitTestCase { } public function testAddingPublicOptionToAdminFieldIsNotAllowed() { - $this->setUpPriceSet(array( + $this->setUpPriceSet([ 'html_type' => 'Select', 'visibility_id' => $this->visibilityOptionsKeys['admin'], - 'option_label' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_value' => array('1' => 100, '2' => 200), - 'option_name' => array('1' => 'Price Field 1', '2' => 'Price Field 2'), - 'option_weight' => array('1' => 1, '2' => 2), - 'option_amount' => array('1' => 100, '2' => 200), - 'option_visibility_id' => array(1 => $this->visibilityOptionsKeys['admin'], 2 => $this->visibilityOptionsKeys['admin']), - )); - - $params = array( + 'option_label' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_value' => ['1' => 100, '2' => 200], + 'option_name' => ['1' => 'Price Field 1', '2' => 'Price Field 2'], + 'option_weight' => ['1' => 1, '2' => 2], + 'option_amount' => ['1' => 100, '2' => 200], + 'option_visibility_id' => [1 => $this->visibilityOptionsKeys['admin'], 2 => $this->visibilityOptionsKeys['admin']], + ]); + + $params = [ 'fieldId' => $this->adminValue['price_field_id'], 'optionId' => $this->adminValue['id'], 'visibility_id' => $this->visibilityOptionsKeys['public'], - ); + ]; $form = new CRM_Price_Form_Option(); $form->_action = CRM_Core_Action::ADD; - $files = array(); + $files = []; $validationResult = $form->formRule($params, $files, $form); $this->assertType('array', $validationResult); diff --git a/tests/phpunit/api/v3/GroupTest.php b/tests/phpunit/api/v3/GroupTest.php index 3d077515a1..26caaeebf8 100644 --- a/tests/phpunit/api/v3/GroupTest.php +++ b/tests/phpunit/api/v3/GroupTest.php @@ -32,6 +32,7 @@ * @group headless */ class api_v3_GroupTest extends CiviUnitTestCase { + protected $_groupID; /** @@ -41,7 +42,7 @@ class api_v3_GroupTest extends CiviUnitTestCase { parent::setUp(); $this->_groupID = $this->groupCreate(); $config = CRM_Core_Config::singleton(); - $config->userPermissionClass->permissions = array(); + $config->userPermissionClass->permissions = []; } /** @@ -59,33 +60,36 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * Test missing required title parameter results in an error. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGroupCreateNoTitle($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name' => 'Test Group No title ', 'domain_id' => 1, 'description' => 'New Test Group Created', 'is_active' => 1, 'visibility' => 'Public Pages', - 'group_type' => array( + 'group_type' => [ '1' => 1, '2' => 1, - ), - ); + ], + ]; $this->callAPIFailure('group', 'create', $params, 'title'); } /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupWithEmptyParams($version) { $this->_apiversion = $version; - $group = $this->callAPISuccess('group', 'get', array()); + $group = $this->callAPISuccess('group', 'get', []); $group = $group["values"]; $this->assertNotNull(count($group)); @@ -98,7 +102,9 @@ class api_v3_GroupTest extends CiviUnitTestCase { * Test ability to get active, inactive and both. * * Default is active only. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupActiveAndInactive($version) { @@ -110,11 +116,12 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupParamsWithGroupId($version) { $this->_apiversion = $version; - $params = array('id' => $this->_groupID); + $params = ['id' => $this->_groupID]; $group = $this->callAPISuccess('group', 'get', $params); foreach ($group['values'] as $v) { @@ -128,13 +135,14 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupParamsWithGroupName($version) { $this->_apiversion = $version; - $params = array( + $params = [ 'name' => "Test Group 1", - ); + ]; $group = $this->callAPIAndDocument('group', 'get', $params, __FUNCTION__, __FILE__); $group = $group['values']; @@ -149,11 +157,12 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupParamsWithReturnName($version) { $this->_apiversion = $version; - $params = array(); + $params = []; $params['id'] = $this->_groupID; $params['return.name'] = 1; $group = $this->callAPISuccess('group', 'get', $params); @@ -164,11 +173,12 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetGroupParamsWithGroupTitle($version) { $this->_apiversion = $version; - $params = array(); + $params = []; $params['title'] = 'New Test Group Created'; $group = $this->callAPISuccess('group', 'get', $params); @@ -186,7 +196,7 @@ class api_v3_GroupTest extends CiviUnitTestCase { * FIXME: Api4 */ public function testGroupCreateWithTypeAndParent() { - $params = array( + $params = [ 'name' => 'Test Group type', 'title' => 'Test Group Type', 'description' => 'Test Group with Group Type', @@ -195,7 +205,7 @@ class api_v3_GroupTest extends CiviUnitTestCase { 'parents' => "", 'visibility' => 'Public Pages', 'group_type' => [1, 2], - ); + ]; $result = $this->callAPISuccess('Group', 'create', $params); $group = $result['values'][$result['id']]; @@ -205,35 +215,35 @@ class api_v3_GroupTest extends CiviUnitTestCase { $this->assertEquals($group['group_type'], $params['group_type']); //Pass group_type param in checkbox format. - $params = array_merge($params, array( + $params = array_merge($params, [ 'name' => 'Test Checkbox Format', 'title' => 'Test Checkbox Format', - 'group_type' => array(2 => 1), - )); + 'group_type' => [2 => 1], + ]); $result = $this->callAPISuccess('Group', 'create', $params); $group = $result['values'][$result['id']]; $this->assertEquals($group['name'], "Test Checkbox Format"); $this->assertEquals($group['group_type'], array_keys($params['group_type'])); //assert single value for group_type and parent - $params = array_merge($params, array( + $params = array_merge($params, [ 'name' => 'Test Group 2', 'title' => 'Test Group 2', 'group_type' => 2, 'parents' => $result['id'], 'sequential' => 1, - )); + ]); $group2 = $this->callAPISuccess('Group', 'create', $params)['values'][0]; - $this->assertEquals($group2['group_type'], array($params['group_type'])); + $this->assertEquals($group2['group_type'], [$params['group_type']]); $this->assertEquals($params['parents'], $group2['parents']); // Test array format for parents. - $params = array_merge($params, array( + $params = array_merge($params, [ 'name' => 'Test Group 3', 'title' => 'Test Group 3', 'parents' => [$result['id'], $group2['id']], - )); + ]); $group3 = $this->callAPISuccess('Group', 'create', $params)['values'][0]; $parents = $this->callAPISuccess('Group', 'getvalue', ['return' => 'parents', 'id' => $group3['id']]); @@ -265,11 +275,12 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetNonExistingGroup($version) { $this->_apiversion = $version; - $params = array(); + $params = []; $params['title'] = 'No such group Exist'; $group = $this->callAPISuccess('group', 'get', $params); $this->assertEquals(0, $group['count']); @@ -277,43 +288,45 @@ class api_v3_GroupTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testgroupdeleteParamsnoId($version) { $this->_apiversion = $version; - $group = $this->callAPIFailure('group', 'delete', array()); + $group = $this->callAPIFailure('group', 'delete', []); } /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testgetfields($version) { $this->_apiversion = $version; $description = "Demonstrate use of getfields to interrogate api."; - $params = array('action' => 'create'); + $params = ['action' => 'create']; $result = $this->callAPIAndDocument('group', 'getfields', $params, __FUNCTION__, __FILE__, $description); $this->assertEquals('is_active', $result['values']['is_active']['name']); } public function testIllegalParentsParams() { - $params = array( + $params = [ 'title' => 'Test illegal Group', 'domain_id' => 1, 'description' => 'Testing illegal Parents params', 'is_active' => 1, 'parents' => "(SELECT api_key FROM civicrm_contact where id = 1)", - ); + ]; $this->callAPIFailure('group', 'create', $params); unset($params['parents']); $this->callAPISuccess('group', 'create', $params); - $group1 = $this->callAPISuccess('group', 'get', array( + $group1 = $this->callAPISuccess('group', 'get', [ 'title' => 'Test illegal Group', - 'parents' => array('IS NOT NULL' => 1), - )); + 'parents' => ['IS NOT NULL' => 1], + ]); $this->assertEquals(0, $group1['count']); $params['title'] = 'Test illegal Group 2'; - $params['parents'] = array(); + $params['parents'] = []; $params['parents'][$this->_groupID] = 'test Group'; $params['parents']["(SELECT api_key FROM civicrm_contact where id = 1)"] = "Test"; $this->callAPIFailure('group', 'create', $params); @@ -327,11 +340,11 @@ class api_v3_GroupTest extends CiviUnitTestCase { */ public function testGroupGetACLs() { $this->createLoggedInUser(); - CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM'); - $this->callAPISuccessGetCount('Group', array('check_permissions' => 1), 0); - $this->hookClass->setHook('civicrm_aclGroup', array($this, 'aclGroupAllGroups')); + CRM_Core_Config::singleton()->userPermissionClass->permissions = ['access CiviCRM']; + $this->callAPISuccessGetCount('Group', ['check_permissions' => 1], 0); + $this->hookClass->setHook('civicrm_aclGroup', [$this, 'aclGroupAllGroups']); unset(Civi::$statics['CRM_ACL_API']['group_permission']); - $this->callAPISuccessGetCount('Group', array('check_permissions' => 1), 1); + $this->callAPISuccessGetCount('Group', ['check_permissions' => 1], 1); } /** @@ -344,7 +357,7 @@ class api_v3_GroupTest extends CiviUnitTestCase { * @param array $ids */ public function aclGroupAllGroups($type, $contactID, $tableName, $allGroups, &$ids) { - $group = $this->callAPISuccess('Group', 'get', array('name' => 'Test Group 1')); + $group = $this->callAPISuccess('Group', 'get', ['name' => 'Test Group 1']); $ids = array_keys($group['values']); } diff --git a/tests/phpunit/api/v3/ImTest.php b/tests/phpunit/api/v3/ImTest.php index 1d49b331b3..0f8a4ba145 100644 --- a/tests/phpunit/api/v3/ImTest.php +++ b/tests/phpunit/api/v3/ImTest.php @@ -33,8 +33,11 @@ * @group headless */ class api_v3_ImTest extends CiviUnitTestCase { + protected $params; + protected $id; + protected $_entity; public $DBResetRequired = FALSE; @@ -45,17 +48,20 @@ class api_v3_ImTest extends CiviUnitTestCase { $this->_entity = 'im'; $this->_contactID = $this->organizationCreate(); - $this->params = array( + $this->params = [ 'contact_id' => $this->_contactID, 'name' => 'My Yahoo IM Handle', 'location_type_id' => 1, 'provider_id' => 1, - ); + ]; } /** * @param int $version + * * @dataProvider versionThreeAndFour + * + * @throws \Exception */ public function testCreateIm($version) { $this->_apiversion = $version; @@ -67,27 +73,29 @@ class api_v3_ImTest extends CiviUnitTestCase { /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetIm($version) { $this->_apiversion = $version; - $result = $this->callAPISuccess($this->_entity, 'create', $this->params); + $this->callAPISuccess($this->_entity, 'create', $this->params); $result = $this->callAPIAndDocument($this->_entity, 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id'])); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $result['id']]); } /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testDeleteIm($version) { $this->_apiversion = $version; $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => $result['id']); - $result = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $deleteParams = ['id' => $result['id']]; + $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(0, $checkDeleted['count']); } @@ -95,10 +103,10 @@ class api_v3_ImTest extends CiviUnitTestCase { * Skip api4 test - delete behaves differently */ public function testDeleteImInvalid() { - $result = $this->callAPISuccess($this->_entity, 'create', $this->params); - $deleteParams = array('id' => 600); - $result = $this->callAPIFailure($this->_entity, 'delete', $deleteParams); - $checkDeleted = $this->callAPISuccess($this->_entity, 'get', array()); + $this->callAPISuccess($this->_entity, 'create', $this->params); + $deleteParams = ['id' => 600]; + $this->callAPIFailure($this->_entity, 'delete', $deleteParams); + $checkDeleted = $this->callAPISuccess($this->_entity, 'get', []); $this->assertEquals(1, $checkDeleted['count']); } diff --git a/tests/phpunit/api/v3/LocBlockTest.php b/tests/phpunit/api/v3/LocBlockTest.php index c3f8b85b4b..01059ae999 100644 --- a/tests/phpunit/api/v3/LocBlockTest.php +++ b/tests/phpunit/api/v3/LocBlockTest.php @@ -27,10 +27,13 @@ /** * Class api_v3_LocBlockTest + * * @group headless */ class api_v3_LocBlockTest extends CiviUnitTestCase { + protected $_apiversion = 3; + protected $_entity = 'loc_block'; /** @@ -45,25 +48,25 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { * Test creating location block. */ public function testCreateLocBlock() { - $email = $this->callAPISuccess('email', 'create', array( + $email = $this->callAPISuccess('email', 'create', [ 'contact_id' => 'null', 'email' => 'test@loc.block', - )); - $phone = $this->callAPISuccess('phone', 'create', array( + ]); + $phone = $this->callAPISuccess('phone', 'create', [ 'contact_id' => 'null', 'location_type_id' => 1, 'phone' => '1234567', - )); - $address = $this->callAPISuccess('address', 'create', array( + ]); + $address = $this->callAPISuccess('address', 'create', [ 'contact_id' => 'null', 'location_type_id' => 1, 'street_address' => '1234567', - )); - $params = array( + ]); + $params = [ 'address_id' => $address['id'], 'phone_id' => $phone['id'], 'email_id' => $email['id'], - ); + ]; $description = 'Create locBlock with existing entities'; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description); $id = $result['id']; @@ -76,34 +79,34 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { * Test creating location block entities. */ public function testCreateLocBlockEntities() { - $params = array( - 'email' => array( + $params = [ + 'email' => [ 'location_type_id' => 1, 'email' => 'test2@loc.block', - ), - 'phone' => array( + ], + 'phone' => [ 'location_type_id' => 1, 'phone' => '987654321', - ), - 'phone_2' => array( + ], + 'phone_2' => [ 'location_type_id' => 1, 'phone' => '456-7890', - ), - 'address' => array( + ], + 'address' => [ 'location_type_id' => 1, 'street_address' => '987654321', - ), - ); + ], + ]; $description = "Create entities and locBlock in 1 api call."; $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__, $description, 'CreateEntities'); $id = $result['id']; $this->assertEquals(1, $result['count']); // Now check our results using the return param 'all'. - $getParams = array( + $getParams = [ 'id' => $id, 'return' => 'all', - ); + ]; // Can't use callAPISuccess with getsingle. $result = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__, 'Get entities and location block in 1 api call'); $result = array_pop($result['values']); @@ -115,7 +118,7 @@ class api_v3_LocBlockTest extends CiviUnitTestCase { $this->assertEquals($params['phone_2']['phone'], $result['phone_2']['phone']); $this->assertEquals($params['address']['street_address'], $result['address']['street_address']); - $this->callAPISuccess($this->_entity, 'delete', array('id' => $id)); + $this->callAPISuccess($this->_entity, 'delete', ['id' => $id]); } } diff --git a/tests/phpunit/api/v3/MailSettingsTest.php b/tests/phpunit/api/v3/MailSettingsTest.php index 2db2e1972c..046281d719 100644 --- a/tests/phpunit/api/v3/MailSettingsTest.php +++ b/tests/phpunit/api/v3/MailSettingsTest.php @@ -27,16 +27,21 @@ /** * Class api_v3_MailSettingsTest + * * @group headless */ class api_v3_MailSettingsTest extends CiviUnitTestCase { + protected $_apiversion = 3; + protected $params; + protected $id; + public $DBResetRequired = FALSE; public function setUp() { - $this->params = array( + $this->params = [ 'domain_id' => 1, 'name' => "my mail setting", 'domain' => 'setting.com', @@ -45,44 +50,50 @@ class api_v3_MailSettingsTest extends CiviUnitTestCase { 'username' => 'sue', 'password' => 'pass', 'is_default' => 1, - ); + ]; parent::setUp(); $this->useTransaction(TRUE); } /** * Test creation. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateMailSettings($version) { $this->_apiversion = $version; - $this->callAPISuccessGetCount('mail_settings', array(), 1); + $this->callAPISuccessGetCount('mail_settings', [], 1); $result = $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); - $this->callAPISuccessGetCount('mail_settings', array(), 1); + $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); + $this->callAPISuccessGetCount('mail_settings', [], 1); } /** * Test caches cleared adequately. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testCreateUpdateMailSettings($version) { $this->_apiversion = $version; $result = $this->callAPISuccess('MailSettings', 'create', $this->params); $this->assertEquals('setting.com', CRM_Core_BAO_MailSettings::defaultDomain()); - $this->callAPISuccess('mail_settings', 'create', array('id' => $result['id'], 'domain' => 'updated.com')); + $this->callAPISuccess('mail_settings', 'create', ['id' => $result['id'], 'domain' => 'updated.com']); $this->assertEquals('updated.com', CRM_Core_BAO_MailSettings::defaultDomain()); - $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); - $this->callAPISuccessGetCount('mail_settings', array(), 1); + $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); + $this->callAPISuccessGetCount('mail_settings', [], 1); } /** * Test get method. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetMailSettings($version) { @@ -91,12 +102,13 @@ class api_v3_MailSettingsTest extends CiviUnitTestCase { $result = $this->callAPIAndDocument('MailSettings', 'get', $this->params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertNotNull($result['values'][$result['id']]['id']); - $this->callAPISuccess('MailSettings', 'delete', array('id' => $result['id'])); - $this->callAPISuccessGetCount('mail_settings', array(), 1); + $this->callAPISuccess('MailSettings', 'delete', ['id' => $result['id']]); + $this->callAPISuccessGetCount('mail_settings', [], 1); } /** * @param int $version + * * @dataProvider versionThreeAndFour */ public function testDeleteMailSettings($version) { @@ -104,24 +116,26 @@ class api_v3_MailSettingsTest extends CiviUnitTestCase { $this->callAPIAndDocument('MailSettings', 'create', $this->params, __FUNCTION__, __FILE__); $entity = $this->callAPISuccess('MailSettings', 'get', $this->params); $this->assertEquals('setting.com', $entity['values'][$entity['id']]['domain']); - $this->callAPIAndDocument('MailSettings', 'delete', array('id' => $entity['id']), __FUNCTION__, __FILE__); - $checkDeleted = $this->callAPISuccess('MailSettings', 'get', array()); + $this->callAPIAndDocument('MailSettings', 'delete', ['id' => $entity['id']], __FUNCTION__, __FILE__); + $checkDeleted = $this->callAPISuccess('MailSettings', 'get', []); $this->assertEquals('EXAMPLE.ORG', $checkDeleted['values'][$checkDeleted['id']]['domain']); } /** * Test chained delete. + * * @param int $version + * * @dataProvider versionThreeAndFour */ public function testGetMailSettingsChainDelete($version) { $this->_apiversion = $version; $description = "Demonstrates get + delete in the same call."; $subFile = 'ChainedGetDelete'; - $params = array( + $params = [ 'name' => "delete this setting", 'api.MailSettings.delete' => 1, - ); + ]; $this->callAPISuccess('MailSettings', 'create', ['name' => "delete this setting"] + $this->params); $result = $this->callAPIAndDocument('MailSettings', 'get', $params, __FUNCTION__, __FILE__, $description, $subFile); $this->assertEquals(0, $this->callAPISuccess('MailSettings', 'getcount', ['name' => "delete this setting"])); diff --git a/tests/phpunit/api/v3/OptionGroupTest.php b/tests/phpunit/api/v3/OptionGroupTest.php index a503e7d4be..779e6a2e90 100644 --- a/tests/phpunit/api/v3/OptionGroupTest.php +++ b/tests/phpunit/api/v3/OptionGroupTest.php @@ -27,9 +27,11 @@ /** * Class api_v3_OptionGroupTest + * * @group headless */ class api_v3_OptionGroupTest extends CiviUnitTestCase { + protected $_apiversion = 3; protected $_entity = 'OptionGroup'; @@ -37,84 +39,84 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase { public function setUp() { parent::setUp(); $this->useTransaction(TRUE); - $this->_params = array( + $this->_params = [ 'name' => 'our test Option Group', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; } /** * Good to test option group as a representative on the Camel Case. */ public function testGetOptionGroupGetFields() { - $result = $this->callAPISuccess('option_group', 'getfields', array()); + $result = $this->callAPISuccess('option_group', 'getfields', []); $this->assertFalse(empty($result['values'])); } public function testGetOptionGroupGetFieldsCreateAction() { - $result = $this->callAPISuccess('option_group', 'getfields', array('action' => 'create')); + $result = $this->callAPISuccess('option_group', 'getfields', ['action' => 'create']); $this->assertFalse(empty($result['values'])); $this->assertEquals($result['values']['name']['api.unique'], 1); } public function testGetOptionGroupByID() { - $result = $this->callAPISuccess('option_group', 'get', array('id' => 1)); + $result = $this->callAPISuccess('option_group', 'get', ['id' => 1]); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['id']); } public function testGetOptionGroupByName() { - $params = array('name' => 'preferred_communication_method'); + $params = ['name' => 'preferred_communication_method']; $result = $this->callAPIAndDocument('option_group', 'get', $params, __FUNCTION__, __FILE__); $this->assertEquals(1, $result['count']); $this->assertEquals(1, $result['id']); } public function testGetOptionGroup() { - $result = $this->callAPISuccess('option_group', 'get', array()); + $result = $this->callAPISuccess('option_group', 'get', []); $this->assertGreaterThan(1, $result['count']); } public function testGetOptionDoesNotExist() { - $result = $this->callAPISuccess('option_group', 'get', array('name' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB')); + $result = $this->callAPISuccess('option_group', 'get', ['name' => 'FSIGUBSFGOMUUBSFGMOOUUBSFGMOOBUFSGMOOIIB']); $this->assertEquals(0, $result['count']); } public function testGetOptionCreateSuccess() { - $params = array( + $params = [ 'sequential' => 1, 'name' => 'civicrm_event.amount.560', 'is_reserved' => 1, 'is_active' => 1, - 'api.OptionValue.create' => array( + 'api.OptionValue.create' => [ 'label' => 'workshop', 'value' => 35, 'is_default' => 1, 'is_active' => 1, 'format.only_id' => 1, - ), - ); + ], + ]; $result = $this->callAPIAndDocument('OptionGroup', 'create', $params, __FUNCTION__, __FILE__); $this->assertEquals('civicrm_event.amount.560', $result['values'][0]['name']); $this->assertTrue(is_int($result['values'][0]['api.OptionValue.create'])); $this->assertGreaterThan(0, $result['values'][0]['api.OptionValue.create']); - $this->callAPISuccess('OptionGroup', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $result['id']]); } /** * Test the error message when a failure is due to a key duplication issue. */ public function testGetOptionCreateFailOnDuplicate() { - $params = array( + $params = [ 'sequential' => 1, 'name' => 'civicrm_dup entry', 'is_reserved' => 1, 'is_active' => 1, - ); + ]; $result1 = $this->callAPISuccess('OptionGroup', 'create', $params); $result = $this->callAPIFailure('OptionGroup', 'create', $params, "Field: `name` must be unique. An conflicting entity already exists - id: " . $result1['id']); - $this->callAPISuccess('OptionGroup', 'delete', array('id' => $result1['id'])); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $result1['id']]); } /** @@ -123,29 +125,26 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase { * Check error returned. */ public function testGetOptionCreateFailRollback() { - $countFirst = $this->callAPISuccess('OptionGroup', 'getcount', array( - 'options' => array('limit' => 5000), - ) - ); - $params = array( + $countFirst = $this->callAPISuccess('OptionGroup', 'getcount', ['options' => ['limit' => 5000]]); + $params = [ 'sequential' => 1, 'name' => 'civicrm_rolback_test', 'is_reserved' => 1, 'is_active' => 1, // executing within useTransactional() test case 'is_transactional' => 'nest', - 'api.OptionValue.create' => array( + 'api.OptionValue.create' => [ 'label' => 'invalid entry', 'value' => 35, 'domain_id' => 999, 'is_active' => '0', 'debug' => 0, - ), - ); + ], + ]; $result = $this->callAPIFailure('OptionGroup', 'create', $params); - $countAfter = $this->callAPISuccess('OptionGroup', 'getcount', array( - 'options' => array('limit' => 5000), - )); + $countAfter = $this->callAPISuccess('OptionGroup', 'getcount', [ + 'options' => ['limit' => 5000], + ]); $this->assertEquals($countFirst, $countAfter, 'Count of option groups should not have changed due to rollback triggered by option value In line ' . __LINE__ ); @@ -156,9 +155,9 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase { */ public function testCreateUpdateOptionGroup() { $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $params = array_merge($this->_params, array('id' => $result['id'], 'is_active' => 0)); + $params = array_merge($this->_params, ['id' => $result['id'], 'is_active' => 0]); $this->callAPISuccess($this->_entity, 'create', $params); - $this->callAPISuccess('OptionGroup', 'delete', array('id' => $result['id'])); + $this->callAPISuccess('OptionGroup', 'delete', ['id' => $result['id']]); } /** @@ -166,28 +165,30 @@ class api_v3_OptionGroupTest extends CiviUnitTestCase { */ public function testDeleteOptionGroup() { $result = $this->callAPISuccess($this->_entity, 'create', $this->_params); - $this->callAPIAndDocument('OptionGroup', 'delete', array('id' => $result['id']), __FUNCTION__, __FILE__); + $this->callAPIAndDocument('OptionGroup', 'delete', ['id' => $result['id']], __FUNCTION__, __FILE__); } /** * Ensure only one option value exists after calling ensureOptionValueExists. + * + * @throws \CRM_Core_Exception */ public function testEnsureOptionGroupExistsExistingValue() { - CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array('name' => 'participant_role')); - $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'participant_role')); + CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(['name' => 'participant_role']); + $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'participant_role']); } /** * Ensure only one option value exists adds a new value. */ public function testEnsureOptionGroupExistsNewValue() { - $optionGroupID = CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array( + $optionGroupID = CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([ 'name' => 'Bombed', 'title' => ts('Catastrophy'), 'description' => ts('blah blah'), 'is_reserved' => 1, - )); - $optionGroup = $this->callAPISuccessGetSingle('OptionGroup', array('name' => 'Bombed')); + ]); + $optionGroup = $this->callAPISuccessGetSingle('OptionGroup', ['name' => 'Bombed']); $this->assertEquals($optionGroupID, $optionGroup['id']); } -- 2.25.1