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
f8d10b75
Commit
f8d10b75
authored
3 months ago
by
colemanw
Browse files
Options
Downloads
Patches
Plain Diff
Api3 - Delete Constant API (deprecated since 2014)
parent
dc14c2fe
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/v3/Constant.php
+0
-179
0 additions, 179 deletions
api/v3/Constant.php
tests/phpunit/api/v3/ConstantTest.php
+0
-148
0 additions, 148 deletions
tests/phpunit/api/v3/ConstantTest.php
tests/phpunit/api/v3/SyntaxConformanceTest.php
+1
-8
1 addition, 8 deletions
tests/phpunit/api/v3/SyntaxConformanceTest.php
with
1 addition
and
335 deletions
api/v3/Constant.php
deleted
100644 → 0
+
0
−
179
View file @
dc14c2fe
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* CiviCRM APIv3 pseudoconstants
*
* @deprecated
* The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.
* @package CiviCRM_APIv3
*/
/**
* Declare deprecated api entity.
*
* @deprecated api notice
* @return string
* to indicate this entire api entity is deprecated
*/
function
_civicrm_api3_constant_deprecation
()
{
return
'The Constant api is deprecated as of CiviCRM 4.4. Please use the getoptions api action instead.'
;
}
/**
* Get constant values (deprecated).
*
* @deprecated as of CiviCRM 4.4.
* It's recommended to use the api getoptions action instead
*
* @param array $params
* Name of a public static method of
* CRM_Core_PseudoConstant: one of
* activityStatus
* activityType
* addressee
* allGroup
* country
* countryIsoCode
* county
* currencyCode
* currencySymbols
* customGroup
* emailGreeting
* fromEmailAddress
* gender
* group
* groupIterator
* honor
* IMProvider
* individualPrefix
* individualSuffix
* locationType
* locationVcardName
* mailProtocol
* mappingTypes
* paymentProcessor
* paymentProcessorType
* pcm
* phoneType
* postalGreeting
* priority
* relationshipType
* stateProvince
* stateProvinceAbbreviation
* stateProvinceForCountry
* staticGroup
* tag
* tasks
* ufGroup
* visibility
* worldRegion
* wysiwygEditor
*
* @return array
*/
function
civicrm_api3_constant_get
(
$params
)
{
$name
=
$params
[
'name'
];
// all the stuff about classes should be adequately replaced by the bit in the 'else'
//ie $values = call_user_func(array('CRM_Utils_PseudoConstant', 'getConstant'), $name);
// once tests are 100% can try removing the first block & a similar block from Generic:getoptions
// Whitelist approach is safer
$allowedClasses
=
[
'CRM_Core_PseudoConstant'
,
'CRM_Event_PseudoConstant'
,
'CRM_Contribute_PseudoConstant'
,
'CRM_Member_PseudoConstant'
,
];
$className
=
$allowedClasses
[
0
];
if
(
!
empty
(
$params
[
'class'
])
&&
in_array
(
$params
[
'class'
],
$allowedClasses
))
{
$className
=
$params
[
'class'
];
}
$callable
=
"
$className
::
$name
"
;
if
(
is_callable
(
$callable
))
{
if
(
empty
(
$params
))
{
$values
=
call_user_func
([
$className
,
$name
]);
}
else
{
$values
=
call_user_func
([
$className
,
$name
]);
//@TODO XAV take out the param the COOKIE, Entity, Action and so there are only the "real param" in it
//$values = call_user_func_array( array( $className, $name ), $params );
}
return
civicrm_api3_create_success
(
$values
,
$params
,
'Constant'
);
}
else
{
$values
=
call_user_func
([
'CRM_Utils_PseudoConstant'
,
'getConstant'
],
$name
);
if
(
!
empty
(
$values
))
{
return
civicrm_api3_create_success
(
$values
,
$params
,
'Constant'
);
}
}
return
civicrm_api3_create_error
(
'Unknown civicrm constant or method not callable'
);
}
/**
* Adjust metadata for constant get action.
*
* @param array $params
*/
function
_civicrm_api3_constant_get_spec
(
&
$params
)
{
$options
=
[
'activityStatus'
,
'activityType'
,
'addressee'
,
'allGroup'
,
'country'
,
'countryIsoCode'
,
'county'
,
'currencyCode'
,
'currencySymbols'
,
'customGroup'
,
'emailGreeting'
,
'fromEmailAddress'
,
'gender'
,
'group'
,
'honor'
,
'IMProvider'
,
'individualPrefix'
,
'individualSuffix'
,
'locationType'
,
'locationVcardName'
,
'mailProtocol'
,
'mappingTypes'
,
'paymentInstrument'
,
'paymentProcessor'
,
'paymentProcessorType'
,
'pcm'
,
'phoneType'
,
'postalGreeting'
,
'priority'
,
'relationshipType'
,
'stateProvince'
,
'stateProvinceAbbreviation'
,
'stateProvinceForCountry'
,
'staticGroup'
,
'tag'
,
'tasks'
,
'ufGroup'
,
'visibility'
,
'worldRegion'
,
'wysiwygEditor'
,
];
$params
=
[
'name'
=>
[
'title'
=>
'Constant Name'
,
'name'
=>
'name'
,
'api.required'
=>
1
,
'options'
=>
array_combine
(
$options
,
$options
),
'type'
=>
CRM_Utils_Type
::
T_STRING
,
],
];
}
This diff is collapsed.
Click to expand it.
tests/phpunit/api/v3/ConstantTest.php
deleted
100644 → 0
+
0
−
148
View file @
dc14c2fe
<?php
/**
* File for the TestConstant class
*
* (PHP 5)
*
* @author Walt Haas <walt@dharmatech.org> (801) 534-1262
* @copyright Copyright CiviCRM LLC (C) 2009
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html
* GNU Affero General Public License version 3
* @version $Id: ConstantTest.php 31254 2010-12-15 10:09:29Z eileen $
* @package CiviCRM_APIv3
* @subpackage API_Constant
*
* This file is part of CiviCRM
*
* CiviCRM is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* CiviCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
/**
* Test APIv3 civicrm_activity_* functions
*
* @package CiviCRM_APIv3
* @subpackage API_Constant
* @group headless
*/
class
api_v3_ConstantTest
extends
CiviUnitTestCase
{
/**
* Test setup for every test.
*
* Connect to the database, truncate the tables that will be used
* and redirect stdin to a temporary file
*/
public
function
setUp
():
void
{
// Connect to the database
parent
::
setUp
();
}
/**
* Test civicrm_constant_get( ) for unknown constant
*/
public
function
testUnknownConstant
():
void
{
$result
=
$this
->
callAPIFailure
(
'constant'
,
'get'
,
[
'name'
=>
'thisTypeDoesNotExist'
,
]);
}
/**
* Test civicrm_constant_get( 'activityStatus' )
*/
public
function
testActivityStatus
():
void
{
$result
=
$this
->
callAPISuccess
(
'constant'
,
'get'
,
[
'name'
=>
'activityStatus'
,
]);
$this
->
assertTrue
(
$result
[
'count'
]
>
5
,
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Scheduled'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Completed'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Cancelled'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
}
/**
* Test civicrm_constant_get( 'activityType' )
*/
public
function
testActivityType
():
void
{
$result
=
$this
->
callAPISuccess
(
'constant'
,
'get'
,
[
'name'
=>
'activityType'
,
]);
$this
->
assertTrue
(
$result
[
'count'
]
>
2
,
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Meeting'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
}
/**
* Test civicrm_address_getoptions( 'location_type_id' )
* @param int $version
* @dataProvider versionThreeAndFour
*/
public
function
testLocationTypeGet
(
$version
)
{
$this
->
_apiversion
=
$version
;
// needed to get rid of cached values from previous tests
CRM_Core_PseudoConstant
::
flush
();
$params
=
[
'field'
=>
'location_type_id'
,
];
$result
=
$this
->
callAPISuccess
(
'address'
,
'getoptions'
,
$params
);
$this
->
assertTrue
(
$result
[
'count'
]
>
3
,
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Home'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Work'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Main'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Billing'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
}
/**
* Test civicrm_phone_getoptions( 'phone_type_id' )
* @param int $version
* @dataProvider versionThreeAndFour
*/
public
function
testPhoneType
(
$version
)
{
$this
->
_apiversion
=
$version
;
$params
=
[
'field'
=>
'phone_type_id'
,
];
$result
=
$this
->
callAPISuccess
(
'phone'
,
'getoptions'
,
$params
);
$this
->
assertEquals
(
5
,
$result
[
'count'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Phone'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Mobile'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Fax'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Pager'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Voicemail'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
}
/**
* Test civicrm_constant_get( 'mailProtocol' )
* @param int $version
* @dataProvider versionThreeAndFour
*/
public
function
testmailProtocol
(
$version
)
{
$this
->
_apiversion
=
$version
;
$params
=
[
'field'
=>
'protocol'
,
];
$result
=
$this
->
callAPISuccess
(
'mail_settings'
,
'getoptions'
,
$params
);
$this
->
assertEquals
(
4
,
$result
[
'count'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'IMAP'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Maildir'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'POP3'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
$this
->
assertContains
(
'Localdir'
,
$result
[
'values'
],
"In line "
.
__LINE__
);
}
}
This diff is collapsed.
Click to expand it.
tests/phpunit/api/v3/SyntaxConformanceTest.php
+
1
−
8
View file @
f8d10b75
...
...
@@ -92,7 +92,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'Afform'
,
'Profile'
,
'CustomValue'
,
'Constant'
,
'CustomSearch'
,
'Extension'
,
'ReportTemplate'
,
...
...
@@ -287,7 +286,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
public
static
function
toBeSkipped_get
(
$sequential
=
FALSE
)
{
$entitiesWithoutGet
=
[
'MailingEventResubscribe'
,
'Location'
,
];
if
(
$sequential
===
TRUE
)
{
return
$entitiesWithoutGet
;
...
...
@@ -324,7 +322,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
* @return array
*/
public
static
function
toBeSkipped_create
(
$sequential
=
FALSE
)
{
$entitiesWithoutCreate
=
[
'
Constant'
,
'Entity'
,
'Location
'
,
'Profile'
,
'MailingRecipients'
];
$entitiesWithoutCreate
=
[
'
Entity
'
,
'Profile'
,
'MailingRecipients'
];
if
(
$sequential
===
TRUE
)
{
return
$entitiesWithoutCreate
;
}
...
...
@@ -348,9 +346,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'MailingEventSubscribe'
,
'MailingEventUnsubscribe'
,
'MailingRecipients'
,
'Constant'
,
'Entity'
,
'Location'
,
'Domain'
,
'Profile'
,
'CustomValue'
,
...
...
@@ -400,7 +396,6 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
// ones that are not real entities hence not extendable.
'Entity'
,
'Constant'
,
'Attachment'
,
'CustomSearch'
,
'CustomValue'
,
...
...
@@ -493,9 +488,7 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {
'Mailing'
,
'MailingEventUnsubscribe'
,
'MailingEventSubscribe'
,
'Constant'
,
'Entity'
,
'Location'
,
'Profile'
,
'CustomValue'
,
'UFJoin'
,
...
...
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