*/
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');
$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();
]);
// 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.
$this->_docTypes = CRM_Core_SelectValues::documentApplicationType();
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_alterMailParams',
- array($this, 'hook_alterMailParams'));
+ [$this, 'hook_alterMailParams']);
}
/**
// 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);
// 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().
'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.
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__);
//. 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",
// 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',
'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');
/** @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();
* 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();
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();
$this->_ut->assertEquals(
$expectedRecipients,
$recipients,
- "Incorrect recipients: " . print_r(array('expected' => $expectedRecipients, 'actual' => $recipients), TRUE)
+ "Incorrect recipients: " . print_r(['expected' => $expectedRecipients, 'actual' => $recipients], TRUE)
);
}
$this->_ut->assertEquals(
$expectedSubjects,
$subjects,
- "Incorrect subjects: " . print_r(array('expected' => $expectedSubjects, 'actual' => $subjects), TRUE)
+ "Incorrect subjects: " . print_r(['expected' => $expectedSubjects, 'actual' => $subjects], TRUE)
);
}
);
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]),
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;
}
*/
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__);
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();
$a = $this->a = CRM_Utils_Cache::create($cacheA);
$b = $this->b = CRM_Utils_Cache::create($cacheB);
- return array($a, $b);
+ return [$a, $b];
}
}
\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();
}
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']);
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']) . ';';
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;
}
$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) {
$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']]),
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);
}
$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) {
$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);
//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);
//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);
//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);
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'],
// 'return' => 'api_key',
//));
- civicrm_api3('Contact', 'create', array(
+ civicrm_api3('Contact', 'create', [
'id' => $this->adminContactId,
'api_key' => self::getApiKey(),
- ));
+ ]);
}
protected static function getApiKey() {