From d6bf55a72e57975092dac57930bc4ba45be454c1 Mon Sep 17 00:00:00 2001 From: colemanw Date: Mon, 2 Oct 2023 15:08:26 -0400 Subject: [PATCH] Test - Convert arrays to short syntax --- tests/phpunit/CRM/Case/BAO/CaseTest.php | 16 +-- .../Contribute/BAO/ContributionRecurTest.php | 2 +- .../Form/Task/PDFLetterCommonTest.php | 2 +- .../phpunit/CRM/Mailing/MailingSystemTest.php | 10 +- tests/phpunit/CRM/Utils/FileTest.php | 2 +- tests/phpunit/CiviTest/CiviCaseTestCase.php | 14 +-- .../phpunit/CiviTest/CiviEndToEndTestCase.php | 4 +- tests/phpunit/CiviTest/CiviMailUtils.php | 4 +- tests/phpunit/CiviTest/CiviReportTestCase.php | 4 +- .../phpunit/CiviTest/CiviTestSMSProvider.php | 2 +- tests/phpunit/CiviTest/bootstrap.php | 2 +- tests/phpunit/E2E/Cache/CacheTestCase.php | 4 +- tests/phpunit/E2E/Cache/TwoInstancesTest.php | 2 +- tests/phpunit/E2E/Core/AssetBuilderTest.php | 36 +++--- tests/phpunit/E2E/Core/PrevNextTest.php | 2 +- tests/phpunit/E2E/Extern/BaseRestTest.php | 112 +++++++++--------- 16 files changed, 109 insertions(+), 109 deletions(-) diff --git a/tests/phpunit/CRM/Case/BAO/CaseTest.php b/tests/phpunit/CRM/Case/BAO/CaseTest.php index 40a3ab39aa..0dd3ce1ee2 100644 --- a/tests/phpunit/CRM/Case/BAO/CaseTest.php +++ b/tests/phpunit/CRM/Case/BAO/CaseTest.php @@ -275,28 +275,28 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { */ public function testCaseReassignForCustomFiles(): void { $individual = $this->individualCreate(); - $customGroup = $this->customGroupCreate(array( + $customGroup = $this->customGroupCreate([ 'extends' => 'Case', - )); + ]); $customGroup = $customGroup['values'][$customGroup['id']]; - $customFileFieldA = $this->customFieldCreate(array( + $customFileFieldA = $this->customFieldCreate([ 'custom_group_id' => $customGroup['id'], 'html_type' => 'File', 'is_active' => 1, 'default_value' => 'null', 'label' => 'Custom File A', 'data_type' => 'File', - )); + ]); - $customFileFieldB = $this->customFieldCreate(array( + $customFileFieldB = $this->customFieldCreate([ 'custom_group_id' => $customGroup['id'], 'html_type' => 'File', 'is_active' => 1, 'default_value' => 'null', 'label' => 'Custom File B', 'data_type' => 'File', - )); + ]); // Create two files to attach to the new case $filepath = Civi::paths()->getPath('[civicrm.files]/custom'); @@ -309,11 +309,11 @@ class CRM_Case_BAO_CaseTest extends CiviUnitTestCase { $caseObj = $this->createCase($individual); - $this->callAPISuccess('Case', 'create', array( + $this->callAPISuccess('Case', 'create', [ 'id' => $caseObj->id, 'custom_' . $customFileFieldA['id'] => $fileA['id'], 'custom_' . $customFileFieldB['id'] => $fileB['id'], - )); + ]); $reassignIndividual = $this->individualCreate(); $this->createLoggedInUser(); diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php index 1206088082..76f0dd7ede 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionRecurTest.php @@ -289,7 +289,7 @@ class CRM_Contribute_BAO_ContributionRecurTest extends CiviUnitTestCase { ]); // Register "contribution create" hook - $this->hookClass->setHook('civicrm_post', array($this, 'implementHookPost')); + $this->hookClass->setHook('civicrm_post', [$this, 'implementHookPost']); \Civi::$statics['testCreateTemplateContributionFromFirstContributionTest']['custom_field_id'] = $custom_field['id']; // Make sure a template contribution exists. diff --git a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php index 547eaa1b24..08d463637e 100644 --- a/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php +++ b/tests/phpunit/CRM/Contribute/Form/Task/PDFLetterCommonTest.php @@ -41,7 +41,7 @@ class CRM_Contribute_Form_Task_PDFLetterCommonTest extends CiviUnitTestCase { $this->_docTypes = CRM_Core_SelectValues::documentApplicationType(); $hooks = \CRM_Utils_Hook::singleton(); $hooks->setHook('civicrm_alterMailParams', - array($this, 'hook_alterMailParams')); + [$this, 'hook_alterMailParams']); } /** diff --git a/tests/phpunit/CRM/Mailing/MailingSystemTest.php b/tests/phpunit/CRM/Mailing/MailingSystemTest.php index 20d7bd08c4..280ee6e0ac 100644 --- a/tests/phpunit/CRM/Mailing/MailingSystemTest.php +++ b/tests/phpunit/CRM/Mailing/MailingSystemTest.php @@ -187,8 +187,8 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest { // The following code is exactly the same as runMailingSuccess() except that we store the ID of the mailing. $mailing_1 = $this->callAPISuccess('Mailing', 'create', $mailingParams); - $mut->assertRecipients(array()); - $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE)); + $mut->assertRecipients([]); + $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]); $allMessages = $mut->getAllMessages('ezc'); $this->assertCount(1, $allMessages); @@ -300,8 +300,8 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest { // The following code is exactly the same as runMailingSuccess() except that we store the ID of the mailing. $mailing_1 = $this->callAPISuccess('mailing', 'create', $mailingParams); - $mut->assertRecipients(array()); - $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE)); + $mut->assertRecipients([]); + $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]); $allMessages = $mut->getAllMessages('ezc'); // There are exactly two contacts produced by setUp(). @@ -325,7 +325,7 @@ class CRM_Mailing_MailingSystemTest extends CRM_Mailing_BaseMailingSystemTest { 'body_text' => 'Please just {action.unsubscribeUrl}', ]; $this->callAPISuccess('mailing', 'create', $mailingParams); - $_ = $this->callAPISuccess('job', 'process_mailing', array('runInNonProductionEnvironment' => TRUE)); + $_ = $this->callAPISuccess('job', 'process_mailing', ['runInNonProductionEnvironment' => TRUE]); $allMessages = $mut->getAllMessages('ezc'); // We should have 2+2 messages sent by the mail system now. diff --git a/tests/phpunit/CRM/Utils/FileTest.php b/tests/phpunit/CRM/Utils/FileTest.php index f514b70b09..973f5c0bbf 100644 --- a/tests/phpunit/CRM/Utils/FileTest.php +++ b/tests/phpunit/CRM/Utils/FileTest.php @@ -429,7 +429,7 @@ class CRM_Utils_FileTest extends CiviUnitTestCase { try { $cmd = 'cv ev -v ' . escapeshellarg("return require \"$outFile\";"); - $descriptorSpec = array(0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']); + $descriptorSpec = [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; $oldOutput = getenv('CV_OUTPUT'); putenv("CV_OUTPUT=json"); $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__); diff --git a/tests/phpunit/CiviTest/CiviCaseTestCase.php b/tests/phpunit/CiviTest/CiviCaseTestCase.php index 0d1f615d91..5b35bd6202 100644 --- a/tests/phpunit/CiviTest/CiviCaseTestCase.php +++ b/tests/phpunit/CiviTest/CiviCaseTestCase.php @@ -39,10 +39,10 @@ class CiviCaseTestCase extends CiviUnitTestCase { //. Using XML was causing breakage as id numbers were changing over time // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a // state where tests could run afterwards without re-loading. - $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array( + $this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', [ 'name' => 'case_status', 'format.only_id' => 1, - )); + ]); $optionValues = [ 'Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", @@ -67,7 +67,7 @@ class CiviCaseTestCase extends CiviUnitTestCase { // Now, the rule is simply: use the "name" from "civicrm_case_type.name". $this->caseType = 'housing_support'; $this->caseTypeId = 1; - $this->tablesToTruncate = array( + $this->tablesToTruncate = [ 'civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', @@ -81,14 +81,14 @@ class CiviCaseTestCase extends CiviUnitTestCase { 'civicrm_relationship', 'civicrm_relationship_type', 'civicrm_uf_match', - ); + ]; $this->quickCleanup($this->tablesToTruncate); $this->loadAllFixtures(); // enable the default custom templates for the case type xml files - $this->customDirectories(array('template_path' => TRUE)); + $this->customDirectories(['template_path' => TRUE]); // case is not enabled by default $enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase'); @@ -96,7 +96,7 @@ class CiviCaseTestCase extends CiviUnitTestCase { /** @var \CRM_Utils_Hook_UnitTests $hooks */ $hooks = \CRM_Utils_Hook::singleton(); - $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); + $hooks->setHook('civicrm_caseTypes', [$this, 'hook_caseTypes']); \CRM_Case_XMLRepository::singleton(TRUE); \CRM_Case_XMLProcessor::flushStaticCaches(); @@ -113,7 +113,7 @@ class CiviCaseTestCase extends CiviUnitTestCase { * This method is called after a test is executed. */ public function tearDown(): void { - $this->customDirectories(array('template_path' => FALSE)); + $this->customDirectories(['template_path' => FALSE]); $this->quickCleanup($this->tablesToTruncate, TRUE); CRM_Case_XMLRepository::singleton(TRUE); parent::tearDown(); diff --git a/tests/phpunit/CiviTest/CiviEndToEndTestCase.php b/tests/phpunit/CiviTest/CiviEndToEndTestCase.php index 272670c071..4434150e53 100644 --- a/tests/phpunit/CiviTest/CiviEndToEndTestCase.php +++ b/tests/phpunit/CiviTest/CiviEndToEndTestCase.php @@ -13,10 +13,10 @@ class CiviEndToEndTestCase extends PHPUnit\Framework\TestCase implements \Civi\T public static function setUpBeforeClass(): void { CRM_Core_Config::singleton(1, 1); - CRM_Utils_System::loadBootStrap(array( + CRM_Utils_System::loadBootStrap([ 'name' => $GLOBALS['_CV']['ADMIN_USER'], 'pass' => $GLOBALS['_CV']['ADMIN_PASS'], - )); + ]); CRM_Utils_System::synchronizeUsers(); parent::setUpBeforeClass(); diff --git a/tests/phpunit/CiviTest/CiviMailUtils.php b/tests/phpunit/CiviTest/CiviMailUtils.php index 347f7b2935..272423759f 100644 --- a/tests/phpunit/CiviTest/CiviMailUtils.php +++ b/tests/phpunit/CiviTest/CiviMailUtils.php @@ -221,7 +221,7 @@ class CiviMailUtils extends PHPUnit\Framework\TestCase { $this->_ut->assertEquals( $expectedRecipients, $recipients, - "Incorrect recipients: " . print_r(array('expected' => $expectedRecipients, 'actual' => $recipients), TRUE) + "Incorrect recipients: " . print_r(['expected' => $expectedRecipients, 'actual' => $recipients], TRUE) ); } @@ -242,7 +242,7 @@ class CiviMailUtils extends PHPUnit\Framework\TestCase { $this->_ut->assertEquals( $expectedSubjects, $subjects, - "Incorrect subjects: " . print_r(array('expected' => $expectedSubjects, 'actual' => $subjects), TRUE) + "Incorrect subjects: " . print_r(['expected' => $expectedSubjects, 'actual' => $subjects], TRUE) ); } diff --git a/tests/phpunit/CiviTest/CiviReportTestCase.php b/tests/phpunit/CiviTest/CiviReportTestCase.php index 687f808524..45789ec48f 100644 --- a/tests/phpunit/CiviTest/CiviReportTestCase.php +++ b/tests/phpunit/CiviTest/CiviReportTestCase.php @@ -126,10 +126,10 @@ class CiviReportTestCase extends CiviUnitTestCase { ); foreach ($actualCsvArray as $intKey => $strVal) { - $rowData = var_export(array( + $rowData = var_export([ 'expected' => $expectedCsvArray[$intKey], 'actual' => $actualCsvArray[$intKey], - ), TRUE); + ], TRUE); $this->assertNotNull($expectedCsvArray[$intKey]); $this->assertEquals( count($actualCsvArray[$intKey]), diff --git a/tests/phpunit/CiviTest/CiviTestSMSProvider.php b/tests/phpunit/CiviTest/CiviTestSMSProvider.php index 9d7d80ee9f..075c18c3ea 100644 --- a/tests/phpunit/CiviTest/CiviTestSMSProvider.php +++ b/tests/phpunit/CiviTest/CiviTestSMSProvider.php @@ -24,7 +24,7 @@ class CiviTestSMSProvider extends CRM_SMS_Provider { public static function &singleton($providerParams = [], $force = FALSE) { if (isset($providerParams['provider'])) { - $providers = CRM_SMS_BAO_Provider::getProviders(NULL, array('name' => $providerParams['provider'])); + $providers = CRM_SMS_BAO_Provider::getProviders(NULL, ['name' => $providerParams['provider']]); $provider = current($providers); $providerID = $provider['id'] ?? NULL; } diff --git a/tests/phpunit/CiviTest/bootstrap.php b/tests/phpunit/CiviTest/bootstrap.php index a12fc99235..017fbff91c 100644 --- a/tests/phpunit/CiviTest/bootstrap.php +++ b/tests/phpunit/CiviTest/bootstrap.php @@ -79,7 +79,7 @@ function _phpunit_mockoloader($prefix, $base_dir, $class) { */ function cv($cmd, $decode = 'json') { $cmd = 'cv ' . $cmd; - $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR); + $descriptorSpec = [0 => ["pipe", "r"], 1 => ["pipe", "w"], 2 => STDERR]; $oldOutput = getenv('CV_OUTPUT'); putenv("CV_OUTPUT=json"); $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__); diff --git a/tests/phpunit/E2E/Cache/CacheTestCase.php b/tests/phpunit/E2E/Cache/CacheTestCase.php index d66f6b1501..fe27030030 100644 --- a/tests/phpunit/E2E/Cache/CacheTestCase.php +++ b/tests/phpunit/E2E/Cache/CacheTestCase.php @@ -20,10 +20,10 @@ abstract class E2E_Cache_CacheTestCase extends CiviSimpleCacheTest implements \C public static function setUpBeforeClass(): void { CRM_Core_Config::singleton(1, 1); - CRM_Utils_System::loadBootStrap(array( + CRM_Utils_System::loadBootStrap([ 'name' => $GLOBALS['_CV']['ADMIN_USER'], 'pass' => $GLOBALS['_CV']['ADMIN_PASS'], - )); + ]); CRM_Utils_System::synchronizeUsers(); parent::setUpBeforeClass(); diff --git a/tests/phpunit/E2E/Cache/TwoInstancesTest.php b/tests/phpunit/E2E/Cache/TwoInstancesTest.php index dc3069bccf..8cf5bf014b 100644 --- a/tests/phpunit/E2E/Cache/TwoInstancesTest.php +++ b/tests/phpunit/E2E/Cache/TwoInstancesTest.php @@ -176,7 +176,7 @@ class E2E_Cache_TwoInstancesTest extends CiviEndToEndTestCase { $a = $this->a = CRM_Utils_Cache::create($cacheA); $b = $this->b = CRM_Utils_Cache::create($cacheB); - return array($a, $b); + return [$a, $b]; } } diff --git a/tests/phpunit/E2E/Core/AssetBuilderTest.php b/tests/phpunit/E2E/Core/AssetBuilderTest.php index 991329beec..699628319a 100644 --- a/tests/phpunit/E2E/Core/AssetBuilderTest.php +++ b/tests/phpunit/E2E/Core/AssetBuilderTest.php @@ -23,15 +23,15 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { \Civi::service('asset_builder')->clear(); $this->fired['hook_civicrm_buildAsset'] = 0; - \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', array($this, 'counter')); - \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', array($this, 'buildSquareTxt')); - \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', array($this, 'buildSquareJs')); + \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', [$this, 'counter']); + \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', [$this, 'buildSquareTxt']); + \Civi::dispatcher()->addListener('hook_civicrm_buildAsset', [$this, 'buildSquareJs']); } protected function tearDown(): void { - \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'counter')); - \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'buildSquareTxt')); - \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', array($this, 'buildSquareJs')); + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', [$this, 'counter']); + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', [$this, 'buildSquareTxt']); + \Civi::dispatcher()->removeListener('hook_civicrm_buildAsset', [$this, 'buildSquareJs']); parent::tearDown(); } @@ -51,7 +51,7 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { if ($e->asset !== 'square.txt') { return; } - $this->assertTrue(in_array($e->params['x'], array(11, 12))); + $this->assertTrue(in_array($e->params['x'], [11, 12])); $e->mimeType = 'text/plain'; $e->content = "Square: " . ($e->params['x'] * $e->params['x']); @@ -65,7 +65,7 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { if ($e->asset !== 'square.js') { return; } - $this->assertTrue(in_array($e->params['x'], array(11, 12))); + $this->assertTrue(in_array($e->params['x'], [11, 12])); $e->mimeType = 'application/javascript'; $e->content = "var square=" . ($e->params['x'] * $e->params['x']) . ';'; @@ -78,24 +78,24 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { public function getExamples() { $examples = []; - $examples[] = array( + $examples[] = [ 0 => 'square.txt', - 1 => array('x' => 11), + 1 => ['x' => 11], 2 => 'text/plain', 3 => 'Square: 121', - ); - $examples[] = array( + ]; + $examples[] = [ 0 => 'square.txt', - 1 => array('x' => 12), + 1 => ['x' => 12], 2 => 'text/plain', 3 => 'Square: 144', - ); - $examples[] = array( + ]; + $examples[] = [ 0 => 'square.js', - 1 => array('x' => 12), + 1 => ['x' => 12], 2 => 'application/javascript', 3 => 'var square=144;', - ); + ]; return $examples; } @@ -171,7 +171,7 @@ class AssetBuilderTest extends \CiviEndToEndTestCase { $url = \Civi::service('asset_builder')->getUrl('invalid.json'); try { $guzzleClient = new \GuzzleHttp\Client(); - $guzzleResponse = $guzzleClient->request('GET', $url, array('timeout' => 2)); + $guzzleResponse = $guzzleClient->request('GET', $url, ['timeout' => 2]); $this->fail('Expecting ClientException... but it was not thrown!'); } catch (\GuzzleHttp\Exception\ClientException $e) { diff --git a/tests/phpunit/E2E/Core/PrevNextTest.php b/tests/phpunit/E2E/Core/PrevNextTest.php index c1a5bd90aa..35eb6b6ab6 100644 --- a/tests/phpunit/E2E/Core/PrevNextTest.php +++ b/tests/phpunit/E2E/Core/PrevNextTest.php @@ -54,7 +54,7 @@ class PrevNextTest extends \CiviEndToEndTestCase { $sql = $query->searchQuery($start, $prefillLimit, $sort, FALSE, $query->_includeContactIds, FALSE, TRUE, TRUE); $selectSQL = "SELECT DISTINCT %1, contact_a.id, contact_a.sort_name"; - $sql = str_replace(array("SELECT contact_a.id as contact_id", "SELECT contact_a.id as id"), $selectSQL, $sql); + $sql = str_replace(["SELECT contact_a.id as contact_id", "SELECT contact_a.id as id"], $selectSQL, $sql); $this->assertTrue( $this->prevNext->fillWithSql($this->cacheKey, $sql, [1 => [$this->cacheKey, 'String']]), diff --git a/tests/phpunit/E2E/Extern/BaseRestTest.php b/tests/phpunit/E2E/Extern/BaseRestTest.php index 9d12ae31a4..1bcfd8d844 100644 --- a/tests/phpunit/E2E/Extern/BaseRestTest.php +++ b/tests/phpunit/E2E/Extern/BaseRestTest.php @@ -71,18 +71,18 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { protected function tearDown(): void { if (!empty($this->old_api_keys)) { foreach ($this->old_api_keys as $cid => $apiKey) { - civicrm_api3('Contact', 'create', array( + civicrm_api3('Contact', 'create', [ 'id' => $cid, 'api_key' => $apiKey, - )); + ]); } } parent::tearDown(); if (isset($this->nocms_contact_id)) { - $deleteParams = array( + $deleteParams = [ "id" => $this->nocms_contact_id, "skip_undelete" => 1, - ); + ]; $res = civicrm_api3("Contact", "delete", $deleteParams); unset($this->nocms_contact_id); } @@ -98,124 +98,124 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { $cases = []; // entity,action: omit apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "entity" => "Contact", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", - ), + ], // is_error 1, - ); + ]; // entity,action: valid apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "entity" => "Contact", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), - ), + ], // is_error 0, - ); + ]; // entity,action: bad apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "entity" => "Contact", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => 'garbage_' . self::getApiKey(), - ), + ], // is_error 1, - ); + ]; // entity,action: valid apiKey, invalid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "entity" => "Contactses", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), - ), + ], // is_error 1, - ); + ]; // q=civicrm/entity/action: omit apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "q" => "civicrm/contact/get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", - ), + ], // is_error 1, - ); + ]; // q=civicrm/entity/action: valid apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "q" => "civicrm/contact/get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), - ), + ], // is_error 0, - ); + ]; // q=civicrm/entity/action: invalid apiKey, valid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "q" => "civicrm/contact/get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => 'garbage_' . self::getApiKey(), - ), + ], // is_error 1, - ); + ]; // q=civicrm/entity/action: valid apiKey, invalid entity+action - $cases[] = array( + $cases[] = [ // query - array( + [ "q" => "civicrm/contactses/get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), - ), + ], // is_error 1, - ); + ]; // q=civicrm/entity/action: valid apiKey, invalid entity+action // XXX Actually Ping is valid, no? - $cases[] = array( + $cases[] = [ // query - array( + [ "q" => "civicrm/ping", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), - ), + ], // is_error 0, - ); + ]; if (!$this->isOldQSupported()) { $cases = array_filter($cases, function($case) { @@ -242,11 +242,11 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { $result = json_decode($data, TRUE); if ($result === NULL) { - $msg = print_r(array( + $msg = print_r([ 'restUrl' => $this->getRestUrl(), 'query' => $query, 'response data' => $data, - ), TRUE); + ], TRUE); $this->assertNotNull($result, $msg); } $this->assertAPIErrorCode($result, $is_error); @@ -261,22 +261,22 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { //Create contact with api_key $test_key = "testing1234"; - $contactParams = array( + $contactParams = [ "api_key" => $test_key, "contact_type" => "Individual", "first_name" => "RestTester1", - ); + ]; $contact = civicrm_api3("Contact", "create", $contactParams); $this->nocms_contact_id = $contact["id"]; // The key associates with a real contact but not a real user - $params = array( + $params = [ "entity" => "Contact", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => $test_key, - ); + ]; $response = $http->post($this->getRestUrl(), ['form_params' => $params]); $this->assertStatusCode(200, $response); @@ -295,14 +295,14 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { //Create contact with api_key // The key associates with a real contact but not a real user - $params = array( + $params = [ "entity" => "Contact", "action" => "get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => self::getApiKey(), "id" => "user_contact_id", - ); + ]; $response = $http->post($this->getRestUrl(), ['form_params' => $params]); $this->assertStatusCode(200, $response); $result = json_decode((string) $response->getBody(), TRUE); @@ -322,21 +322,21 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { //Create contact with api_key $test_key = "testing1234"; - $contactParams = array( + $contactParams = [ "api_key" => $test_key, "contact_type" => "Individual", "first_name" => "RestTester1", - ); + ]; $contact = civicrm_api3("Contact", "create", $contactParams); $this->nocms_contact_id = $contact["id"]; // The key associates with a real contact but not a real user - $params = array( + $params = [ "q" => "civicrm/contact/get", "key" => $GLOBALS['_CV']['CIVI_SITE_KEY'], "json" => "1", "api_key" => $test_key, - ); + ]; $response = $http->post($this->getRestUrl(), ['form_params' => $params]); $this->assertStatusCode(200, $response); @@ -347,10 +347,10 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { protected function updateAdminApiKey() { /** @var int $adminContactId */ - $this->adminContactId = civicrm_api3('contact', 'getvalue', array( + $this->adminContactId = civicrm_api3('contact', 'getvalue', [ 'id' => '@user:' . $GLOBALS['_CV']['ADMIN_USER'], 'return' => 'id', - )); + ]); $this->old_api_keys[$this->adminContactId] = CRM_Core_DAO::singleValueQuery('SELECT api_key FROM civicrm_contact WHERE id = %1', [ 1 => [$this->adminContactId, 'Positive'], @@ -361,10 +361,10 @@ abstract class E2E_Extern_BaseRestTest extends CiviEndToEndTestCase { // 'return' => 'api_key', //)); - civicrm_api3('Contact', 'create', array( + civicrm_api3('Contact', 'create', [ 'id' => $this->adminContactId, 'api_key' => self::getApiKey(), - )); + ]); } protected static function getApiKey() { -- 2.25.1