Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
986c105a
Commit
986c105a
authored
3 years ago
by
Eileen McNaughton
Browse files
Options
Downloads
Patches
Plain Diff
[NFC] Cleanup on test class
parent
f7aed6e3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
+1
-1
1 addition, 1 deletion
tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
+25
-31
25 additions, 31 deletions
tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
with
26 additions
and
32 deletions
tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
+
1
−
1
View file @
986c105a
...
...
@@ -710,7 +710,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase {
'id'
=>
$this
->
getCustomFieldID
(
'link'
),
'label'
=>
'test_link'
,
'groupTitle'
=>
'Custom Group'
,
'default_value'
=>
'http://civicrm.org'
,
'default_value'
=>
'http
s
://civicrm.org'
,
'custom_group_id'
=>
$customGroupID
,
'extends'
=>
'Contact'
,
'extends_entity_column_value'
=>
NULL
,
...
...
This diff is collapsed.
Click to expand it.
tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
+
25
−
31
View file @
986c105a
...
...
@@ -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
();
}
...
...
@@ -39,11 +36,8 @@ trait CRMTraits_Custom_CustomDataTrait {
* @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'
,
...
...
@@ -71,7 +65,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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'
]);
}
...
...
@@ -83,7 +77,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @return string
*/
protected
function
getCustomFieldColumnName
(
$key
)
{
protected
function
getCustomFieldColumnName
(
string
$key
):
string
{
return
$this
->
callAPISuccessGetValue
(
'CustomField'
,
[
'id'
=>
$this
->
getCustomFieldID
(
$key
),
'return'
=>
'column_name'
]);
}
...
...
@@ -148,7 +142,7 @@ trait CRMTraits_Custom_CustomDataTrait {
/**
* @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'
];
...
...
@@ -178,7 +172,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @return string
*/
protected
function
getCustomFieldName
(
$key
)
{
protected
function
getCustomFieldName
(
string
$key
):
string
{
return
'custom_'
.
$this
->
getCustomFieldID
(
$key
);
}
...
...
@@ -191,7 +185,7 @@ trait CRMTraits_Custom_CustomDataTrait {
* @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'
)
...
...
@@ -212,7 +206,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @return string
*/
protected
function
getCustomFieldID
(
$key
)
{
protected
function
getCustomFieldID
(
string
$key
):
string
{
return
$this
->
ids
[
'CustomField'
][
$key
];
}
...
...
@@ -252,7 +246,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -265,7 +259,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -278,7 +272,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -291,7 +285,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -304,7 +298,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -317,7 +311,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -330,7 +324,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -343,7 +337,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -356,7 +350,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -369,7 +363,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -407,7 +401,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -431,7 +425,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @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
];
}
...
...
@@ -439,12 +433,12 @@ trait CRMTraits_Custom_CustomDataTrait {
/**
* 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
,
...
...
@@ -465,7 +459,7 @@ trait CRMTraits_Custom_CustomDataTrait {
*
* @return array
*/
protected
function
getAvailableFieldCombinations
()
{
protected
function
getAvailableFieldCombinations
()
:
array
{
return
[
'String'
=>
[
'default'
=>
[
...
...
@@ -823,7 +817,7 @@ trait CRMTraits_Custom_CustomDataTrait {
'label'
=>
'test_link'
,
'html_type'
=>
'Link'
,
'data_type'
=>
'Link'
,
'default_value'
=>
'http://civicrm.org'
,
'default_value'
=>
'http
s
://civicrm.org'
,
],
],
'ContactReference'
=>
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment