Skip to content

Commit

Permalink
[NFC] Cleanup on test class
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Sep 13, 2021
1 parent 8d0e0ca commit d96ce0b
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ trait CRMTraits_Custom_CustomDataTrait {
* Create a custom group with fields of multiple types.
*
* @param array $groupParams
*
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function createCustomGroupWithFieldsOfAllTypes($groupParams = []) {
public function createCustomGroupWithFieldsOfAllTypes(array $groupParams = []): void {
$this->createCustomGroup($groupParams);
$this->ids['CustomField'] = $this->createCustomFieldsOfAllTypes();
}
Expand All @@ -39,11 +36,8 @@ public function createCustomGroupWithFieldsOfAllTypes($groupParams = []) {
* @param array $params
*
* @return int
*
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function createCustomGroup($params = []) {
public function createCustomGroup(array $params = []): int {
$params = array_merge([
'title' => 'Custom Group',
'extends' => $this->entity ?? 'Contact',
Expand Down Expand Up @@ -71,7 +65,7 @@ public function createCustomGroup($params = []) {
*
* @return string
*/
public function getCustomGroupTable($identifier = 'Custom Group') {
public function getCustomGroupTable(string $identifier = 'Custom Group'): string {
return $this->callAPISuccessGetValue('CustomGroup', ['id' => $this->ids['CustomGroup'][$identifier], 'return' => 'table_name']);
}

Expand All @@ -83,7 +77,7 @@ public function getCustomGroupTable($identifier = 'Custom Group') {
*
* @return string
*/
protected function getCustomFieldColumnName($key) {
protected function getCustomFieldColumnName(string $key): string {
return $this->callAPISuccessGetValue('CustomField', ['id' => $this->getCustomFieldID($key), 'return' => 'column_name']);
}

Expand Down Expand Up @@ -148,7 +142,7 @@ public function createCustomGroupWithFieldOfType(array $groupParams = [], string
/**
* @return array
*/
public function createCustomFieldsOfAllTypes() {
public function createCustomFieldsOfAllTypes(): array {
$customGroupID = $this->ids['CustomGroup']['Custom Group'];
$ids = [];
$ids['text'] = (int) $this->createTextCustomField(['custom_group_id' => $customGroupID])['id'];
Expand Down Expand Up @@ -178,7 +172,7 @@ public function createCustomFieldsOfAllTypes() {
*
* @return string
*/
protected function getCustomFieldName($key) {
protected function getCustomFieldName(string $key): string {
return 'custom_' . $this->getCustomFieldID($key);
}

Expand All @@ -191,7 +185,7 @@ protected function getCustomFieldName($key) {
* @return int
* @throws \API_Exception
*/
protected function addOptionToCustomField($key, $values) {
protected function addOptionToCustomField(string $key, array $values): int {
$optionGroupID = CustomField::get(FALSE)
->addWhere('id', '=', $this->getCustomFieldID($key))
->addSelect('option_group_id')
Expand All @@ -212,7 +206,7 @@ protected function addOptionToCustomField($key, $values) {
*
* @return string
*/
protected function getCustomFieldID($key) {
protected function getCustomFieldID(string $key): string {
return $this->ids['CustomField'][$key];
}

Expand Down Expand Up @@ -252,7 +246,7 @@ protected function getOptionGroupName(string $key): string {
*
* @return array
*/
protected function createIntCustomField($params = []) {
protected function createIntCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('Int'), $params);
return $this->callAPISuccess('CustomField', 'create', $params)['values'][0];
}
Expand All @@ -265,7 +259,7 @@ protected function createIntCustomField($params = []) {
*
* @return array
*/
protected function createBooleanCustomField($params = []) {
protected function createBooleanCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('Boolean'), $params);
return $this->callAPISuccess('CustomField', 'create', $params)['values'][0];
}
Expand All @@ -278,7 +272,7 @@ protected function createBooleanCustomField($params = []) {
*
* @return array
*/
protected function createContactReferenceCustomField($params = []) {
protected function createContactReferenceCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('ContactReference'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -291,7 +285,7 @@ protected function createContactReferenceCustomField($params = []) {
*
* @return array
*/
protected function createTextCustomField($params = []) {
protected function createTextCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('String'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -304,7 +298,7 @@ protected function createTextCustomField($params = []) {
*
* @return array
*/
protected function createLinkCustomField($params = []) {
protected function createLinkCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('Link'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -317,7 +311,7 @@ protected function createLinkCustomField($params = []) {
*
* @return array
*/
protected function createCountryCustomField($params = []) {
protected function createCountryCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('Country'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -330,7 +324,7 @@ protected function createCountryCustomField($params = []) {
*
* @return array
*/
protected function createMultiCountryCustomField($params = []) {
protected function createMultiCountryCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('Country', 'Multi-Select Country'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -343,7 +337,7 @@ protected function createMultiCountryCustomField($params = []) {
*
* @return array
*/
protected function createStateCustomField($params = []) {
protected function createStateCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('StateProvince'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -356,7 +350,7 @@ protected function createStateCustomField($params = []) {
*
* @return array
*/
protected function createMultiStateCustomField($params = []) {
protected function createMultiStateCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('StateProvince', 'Multi-Select State/Province'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -369,7 +363,7 @@ protected function createMultiStateCustomField($params = []) {
*
* @return array
*/
protected function createFileCustomField($params = []) {
protected function createFileCustomField(array $params = []): array {
$params = array_merge($this->getFieldsValuesByType('File'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand Down Expand Up @@ -407,7 +401,7 @@ protected function createAutoCompleteCustomField(array $params): array {
*
* @return array
*/
protected function createDateCustomField($params): array {
protected function createDateCustomField(array $params): array {
$params = array_merge($this->getFieldsValuesByType('Date'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}
Expand All @@ -431,20 +425,20 @@ protected function createStringCheckboxCustomField(array $params): array {
*
* @return array
*/
protected function createIntegerRadioCustomField($params): array {
protected function createIntegerRadioCustomField(array $params): array {
$params = array_merge($this->getFieldsValuesByType('Int', 'Radio'), $params);
return $this->callAPISuccess('custom_field', 'create', $params)['values'][0];
}

/**
* Get default field values for the type of field.
*
* @param $dataType
* @param string $dataType
* @param string $htmlType
*
* @return mixed
* @return array
*/
public function getFieldsValuesByType($dataType, $htmlType = 'default') {
public function getFieldsValuesByType(string $dataType, string $htmlType = 'default'): array {
$values = $this->getAvailableFieldCombinations()[$dataType];
return array_merge([
'is_searchable' => 1,
Expand All @@ -465,7 +459,7 @@ public function getFieldsValuesByType($dataType, $htmlType = 'default') {
*
* @return array
*/
protected function getAvailableFieldCombinations() {
protected function getAvailableFieldCombinations(): array {
return [
'String' => [
'default' => [
Expand Down Expand Up @@ -823,7 +817,7 @@ protected function getAvailableFieldCombinations() {
'label' => 'test_link',
'html_type' => 'Link',
'data_type' => 'Link',
'default_value' => 'http://civicrm.org',
'default_value' => 'https://civicrm.org',
],
],
'ContactReference' => [
Expand Down

0 comments on commit d96ce0b

Please sign in to comment.