3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Test that the core actions for APIv3 entities comply with standard syntax+behavior.
31 * By default, this tests all API entities. To only test specific entities, call phpunit with
32 * environment variable SYNTAX_CONFORMANCE_ENTITIES, e.g.
34 * env SYNTAX_CONFORMANCE_ENTITIES="Contact Event" ./scripts/phpunit api_v3_SyntaxConformanceTest
36 * @package CiviCRM_APIv3
37 * @subpackage API_Core
40 class api_v3_SyntaxConformanceTest
extends CiviUnitTestCase
{
41 protected $_apiversion = 3;
44 * @var array e.g. $this->deletes['CRM_Contact_DAO_Contact'][] = $contactID;
46 protected $deletableTestObjects;
49 * This test case doesn't require DB reset.
51 public $DBResetRequired = FALSE;
56 * Map custom group entities to civicrm components.
58 static $componentMap = array(
59 'Contribution' => 'CiviContribute',
60 'Membership' => 'CiviMember',
61 'Participant' => 'CiviEvent',
62 'Event' => 'CiviEvent',
64 'Pledge' => 'CiviPledge',
65 'Grant' => 'CiviGrant',
66 'Campaign' => 'CiviCampaign',
67 'Survey' => 'CiviCampaign',
73 * There are two types of missing APIs:
74 * Those that are to be implemented
75 * (in some future version when someone steps in -hint hint-). List the entities in toBeImplemented[ {$action} ]
76 * Those that don't exist
77 * and that will never exist (eg an obsoleted Entity
78 * they need to be returned by the function toBeSkipped_{$action} (because it has to be a static method and therefore couldn't access a this->toBeSkipped)
80 public function setUp() {
82 $this->enableCiviCampaign();
83 $this->toBeImplemented
['get'] = array(
84 'CxnApp', // CxnApp.get exists but relies on remote data outside our control; QA w/UtilsTest::testBasicArrayGet
96 $this->toBeImplemented
['create'] = array(
111 'SavedSearch', //work fine in local
114 $this->toBeImplemented
['delete'] = array(
128 $this->onlyIDNonZeroCount
['get'] = array(
135 $this->deprecatedAPI
= array('Location', 'ActivityType', 'SurveyRespondant');
136 $this->deletableTestObjects
= array();
139 public function tearDown() {
140 foreach ($this->deletableTestObjects
as $entityName => $entities) {
141 foreach ($entities as $entityID) {
142 CRM_Core_DAO
::deleteTestObjects($entityName, array('id' => $entityID));
148 * Generate list of all entities.
155 public static function entities($skip = array()) {
156 // The order of operations in here is screwy. In the case where SYNTAX_CONFORMANCE_ENTITIES is
157 // defined, we should be able to parse+return it immediately. However, some weird dependency
158 // crept into the system where civicrm_api('Entity','get') must be called as part of entities()
159 // (even if its return value is ignored).
161 $tmp = civicrm_api('Entity', 'Get', array('version' => 3));
162 if (getenv('SYNTAX_CONFORMANCE_ENTITIES')) {
164 'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES')),
168 if (!is_array($skip)) {
171 $tmp = array_diff($tmp['values'], $skip);
173 foreach ($tmp as $e) {
174 $entities[] = array($e);
180 * Get list of entities for get test.
184 public static function entities_get() {
185 // all the entities, beside the ones flagged
186 return static::entities(static::toBeSkipped_get(TRUE));
190 * Get entities for create tests.
194 public static function entities_create() {
195 return static::entities(static::toBeSkipped_create(TRUE));
201 public static function entities_updatesingle() {
202 return static::entities(static::toBeSkipped_updatesingle(TRUE));
208 public static function entities_getlimit() {
209 return static::entities(static::toBeSkipped_getlimit());
213 * Generate list of entities that can be retrieved using SQL operator syntax.
217 public static function entities_getSqlOperators() {
218 return static::entities(static::toBeSkipped_getSqlOperators());
224 public static function entities_delete() {
225 return static::entities(static::toBeSkipped_delete(TRUE));
231 public static function entities_getfields() {
232 return static::entities(static::toBeSkipped_getfields(TRUE));
238 public static function custom_data_entities_get() {
239 return static::custom_data_entities();
245 public static function custom_data_entities() {
246 $entities = CRM_Core_BAO_CustomQuery
::$extendsMap;
247 $enabledComponents = Civi
::settings()->get('enable_components');
248 $customDataEntities = array();
249 $invalidEntities = array('Individual', 'Organization', 'Household');
250 $entitiesToFix = array('Case', 'Relationship');
251 foreach ($entities as $entityName => $entity) {
252 if (!in_array($entityName, $invalidEntities)
253 && !in_array($entityName, $entitiesToFix)
255 if (!empty(self
::$componentMap[$entityName]) && empty($enabledComponents[self
::$componentMap[$entityName]])) {
256 CRM_Core_BAO_ConfigSetting
::enableComponent(self
::$componentMap[$entityName]);
258 $customDataEntities[] = array($entityName);
261 return $customDataEntities;
265 * Get entities to be skipped on get tests.
267 * @param bool $sequential
271 public static function toBeSkipped_get($sequential = FALSE) {
272 $entitiesWithoutGet = array(
273 'MailingEventSubscribe',
274 'MailingEventConfirm',
275 'MailingEventResubscribe',
276 'MailingEventUnsubscribe',
279 if ($sequential === TRUE) {
280 return $entitiesWithoutGet;
283 foreach ($entitiesWithoutGet as $e) {
284 $entities[] = array($e);
290 * Get entities to be skipped for get call.
292 * Mailing Contact Just doesn't support id. We have always insisted on finding a way to
293 * support id in API but in this case the underlying tables are crying out for a restructure
294 * & it just doesn't make sense.
296 * User doesn't support get By ID because the user id is actually the CMS user ID & is not part of
297 * CiviCRM - so can only be tested through UserTest - not SyntaxConformanceTest.
299 * Entity doesn't support get By ID because it simply gives the result of string Entites in CiviCRM
301 * @param bool $sequential
304 * Entities that cannot be retrieved by ID
306 public static function toBeSkipped_getByID($sequential = FALSE) {
307 return array('MailingContact', 'User', 'Attachment', 'Entity');
311 * @param bool $sequential
315 public static function toBeSkipped_create($sequential = FALSE) {
316 $entitiesWithoutCreate = array('Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients');
317 if ($sequential === TRUE) {
318 return $entitiesWithoutCreate;
321 foreach ($entitiesWithoutCreate as $e) {
322 $entities[] = array($e);
328 * @param bool $sequential
332 public static function toBeSkipped_delete($sequential = FALSE) {
333 $entitiesWithout = array(
335 'MailingEventConfirm',
336 'MailingEventResubscribe',
337 'MailingEventSubscribe',
338 'MailingEventUnsubscribe',
350 if ($sequential === TRUE) {
351 return $entitiesWithout;
354 foreach ($entitiesWithout as $e) {
355 $entities[] = array($e);
361 * @param bool $sequential
364 * @todo add metadata for ALL these entities
366 public static function toBeSkipped_getfields($sequential = FALSE) {
367 $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
368 if ($sequential === TRUE) {
369 return $entitiesWithMetadataNotYetFixed;
372 foreach ($entitiesWithMetadataNotYetFixed as $e) {
373 $entities[] = array($e);
379 * Generate list of entities to test for get by id functions.
380 * @param bool $sequential
382 * Entities to be skipped
384 public static function toBeSkipped_automock($sequential = FALSE) {
385 $entitiesWithoutGet = array(
389 'ParticipantPayment',
399 if ($sequential === TRUE) {
400 return $entitiesWithoutGet;
403 foreach ($entitiesWithoutGet as $e) {
404 $entities[] = array($e);
410 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
411 * @param bool $sequential
414 public static function toBeSkipped_updatesingle($sequential = FALSE) {
415 $entitiesWithout = array(
417 // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields
422 'MailingEventUnsubscribe',
423 'MailingEventSubscribe',
449 'MailingEventConfirm',
454 'MailingEventResubscribe',
461 'ParticipantPayment',
470 //skip this because it doesn't make sense to update logs,
473 if ($sequential === TRUE) {
474 return $entitiesWithout;
477 foreach ($entitiesWithout as $e) {
482 return array('pledge');
487 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
489 public static function toBeSkipped_getlimit() {
490 $entitiesWithout = array(
492 //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
494 // non-standard api - has inappropriate mandatory fields & doesn't implement limit
496 // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right
498 // can't handle creating 25
500 // fails on 5 limit - probably a set up problem
502 //a bit of a pseudoapi - keys by domain
504 return $entitiesWithout;
508 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
510 public static function toBeSkipped_getSqlOperators() {
511 $entitiesWithout = array(
512 'Case', //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
513 'Contact', // on the todo list!
514 'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit
515 'Extension', // can't handle creating 25
516 'Note', // note has a default get that isn't implemented in createTestObject -meaning you don't 'get' them
517 'Setting', //a bit of a pseudoapi - keys by domain
519 return $entitiesWithout;
528 public function getKnownUnworkablesUpdateSingle($entity, $key) {
529 // can't update values are values for which updates don't result in the value being changed
530 $knownFailures = array(
531 'ActionSchedule' => array(
532 'cant_update' => array(
536 'ActivityContact' => array(
537 'cant_update' => array(
539 //we have an FK on activity_id + contact_id + record id so if we don't leave this one distinct we get an FK constraint error
543 'cant_update' => array(
544 'state_province_id', //issues with country id - need to ensure same country
545 'master_id', //creates relationship
547 'cant_return' => array(),
550 'cant_update' => array(
551 'entity_table', // believe this field is defined in error
553 'cant_return' => array(
558 'cant_update' => array(
562 'MembershipBlock' => array(
563 'cant_update' => array(
564 // The fake/auto-generated values leave us unable to properly cleanup fake data
569 'ContributionSoft' => array(
570 'cant_update' => array(
571 // can't be changed through api
576 'cant_update' => array(
577 // This is being legitimately manipulated to always have a valid primary - skip.
581 'Navigation' => array(
582 'cant_update' => array(
583 // Weight is deliberately altered when this is changed - skip.
587 'LocationType' => array(
588 'cant_update' => array(
589 // I'm on the fence about whether the test should skip or the behaviour is wrong.
590 // display_name is set to match name if display_name is not provided. It would be more 'normal'
591 // to only calculate a default IF id is not set - but perhaps the current behaviour is kind
592 // of what someone updating the name expects..
597 'cant_update' => array(
598 'pledge_original_installment_amount',
600 'original_installment_amount',
602 'amount', // can't be changed through API,
604 'break_return' => array(// if these are passed in they are retrieved from the wrong table
607 'contribution_page_id',
608 'financial_account_id',
612 'cant_return' => array(// can't be retrieved from api
613 'honor_type_id', //due to uniquename missing
621 'initial_reminder_day',
622 'additional_reminder_day',
624 'pledge_contribution_page_id',
626 'pledge_campaign_id',
627 'pledge_financial_type_id',
630 'PaymentProcessorType' => array(
631 'cant_update' => array(
634 'break_return' => array(),
635 'cant_return' => array(),
637 'PriceFieldValue' => array(
638 'cant_update' => array(
639 'weight', //won't update as there is no 1 in the same price set
642 'ReportInstance' => array(
643 // View mode is part of the navigation which is not retrieved by the api.
644 'cant_return' => array('view_mode'),
646 'SavedSearch' => array(
647 // I think the fields below are generated based on form_values.
648 'cant_update' => array(
655 'StatusPreference' => array(
656 'break_return' => array(
661 if (empty($knownFailures[$entity]) ||
empty($knownFailures[$entity][$key])) {
664 return $knownFailures[$entity][$key];
667 /* ----- testing the _get ----- */
670 * @dataProvider toBeSkipped_get
671 * Entities that don't need a get action
674 public function testNotImplemented_get($Entity) {
675 $result = civicrm_api($Entity, 'Get', array('version' => 3));
676 $this->assertEquals(1, $result['is_error']);
677 // $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']);
678 $this->assertRegExp('/API (.*) does not exist/', $result['error_message']);
682 * @dataProvider entities
683 * @expectedException PHPUnit_Framework_Error
686 public function testWithoutParam_get($Entity) {
687 // should get php complaining that a param is missing
688 $result = civicrm_api($Entity, 'Get');
692 * @dataProvider entities
695 public function testGetFields($Entity) {
696 if (in_array($Entity, $this->deprecatedAPI
) ||
$Entity == 'Entity' ||
$Entity == 'CustomValue') {
700 $result = civicrm_api($Entity, 'getfields', array('version' => 3));
701 $this->assertTrue(is_array($result['values']), "$Entity ::get fields doesn't return values array in line " . __LINE__
);
702 foreach ($result['values'] as $key => $value) {
703 $this->assertTrue(is_array($value), $Entity . "::" . $key . " is not an array in line " . __LINE__
);
708 * @dataProvider entities_get
711 public function testEmptyParam_get($Entity) {
713 if (in_array($Entity, $this->toBeImplemented
['get'])) {
714 // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented");
717 $result = civicrm_api($Entity, 'Get', array());
718 $this->assertEquals(1, $result['is_error']);
719 $this->assertContains("Unknown api version", $result['error_message']);
723 * @dataProvider entities_get
726 public function testEmptyParam_getString($Entity) {
728 if (in_array($Entity, $this->toBeImplemented
['get'])) {
729 // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented");
732 $result = $this->callAPIFailure($Entity, 'Get', 'string');
733 $this->assertEquals(2000, $result['error_code']);
734 $this->assertEquals('Input variable `params` is not an array', $result['error_message']);
738 * @dataProvider entities_get
739 * @Xdepends testEmptyParam_get // no need to test the simple if the empty doesn't work/is skipped. doesn't seem to work
742 public function testSimple_get($Entity) {
743 // $this->markTestSkipped("test gives core error on test server (but not on our locals). Skip until we can get server to pass");
744 if (in_array($Entity, $this->toBeImplemented
['get'])) {
747 $result = civicrm_api($Entity, 'Get', array('version' => 3));
748 // @TODO: list the get that have mandatory params
749 if ($result['is_error']) {
750 $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
751 // either id or contact_id or entity_id is one of the field missing
752 $this->assertContains("id", $result['error_message']);
755 $this->assertEquals(3, $result['version']);
756 $this->assertArrayHasKey('count', $result);
757 $this->assertArrayHasKey('values', $result);
762 * @dataProvider custom_data_entities_get
765 public function testCustomDataGet($entityName) {
766 $this->createLoggedInUser();// so subsidiary activities are created
767 // We are not passing 'check_permissions' so the the more limited permissions *should* be
768 // ignored but per CRM-17700 there is a history of custom data applying permissions when it shouldn't.
769 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= array('access CiviCRM', 'view my contact');
770 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, $entityName . 'Test.php');
771 $customFieldName = 'custom_' . $ids['custom_field_id'];
772 $objects = $this->getMockableBAOObjects($entityName, 1);
773 $params = array('id' => $objects[0]->id
, 'custom_' . $ids['custom_field_id'] => "custom string");
774 $result = $this->callAPISuccess($entityName, 'create', $params);
776 $getParams = array('id' => $result['id'], 'return' => array($customFieldName));
777 $check = $this->callAPISuccess($entityName, 'get', $getParams);
778 $this->assertEquals("custom string", $check['values'][$check['id']][$customFieldName]);
780 $this->customFieldDelete($ids['custom_field_id']);
781 $this->customGroupDelete($ids['custom_group_id']);
782 $this->callAPISuccess($entityName, 'delete', array('id' => $result['id']));
783 $this->quickCleanup(array('civicrm_uf_match'));
787 * @dataProvider entities_get
790 public function testAcceptsOnlyID_get($Entity) {
791 // big random number. fun fact: if you multiply it by pi^e, the result is another random number, but bigger ;)
792 $nonExistantID = 30867307034;
793 if (in_array($Entity, $this->toBeImplemented
['get'])
794 ||
in_array($Entity, $this->toBeSkipped_getByID())
800 // the below function returns different values and hence an early return
801 // we'll fix this once beta1 is released
804 $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
806 if ($result['is_error']) {
807 // just to get a clearer message in the log
808 $this->assertEquals("only id should be enough", $result['error_message']);
810 if (!in_array($Entity, $this->onlyIDNonZeroCount
['get'])) {
811 $this->assertEquals(0, $result['count']);
816 * Create two entities and make sure we can fetch them individually by ID.
818 * @dataProvider entities_get
820 * limitations include the problem with avoiding loops when creating test objects -
821 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
822 * Currency - only seems to support US
825 public function testByID_get($entityName) {
826 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
827 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
831 $baos = $this->getMockableBAOObjects($entityName);
832 list($baoObj1, $baoObj2) = $baos;
835 $result = $this->callAPISuccess($entityName, 'get', array(
836 'id' => $baoObj1->id
,
839 $this->assertTrue(!empty($result['values'][$baoObj1->id
]), 'Should find first object by id');
840 $this->assertEquals($baoObj1->id
, $result['values'][$baoObj1->id
]['id'], 'Should find id on first object');
841 $this->assertEquals(1, count($result['values']));
843 // fetch second by ID
844 $result = $this->callAPISuccess($entityName, 'get', array(
845 'id' => $baoObj2->id
,
847 $this->assertTrue(!empty($result['values'][$baoObj2->id
]), 'Should find second object by id');
848 $this->assertEquals($baoObj2->id
, $result['values'][$baoObj2->id
]['id'], 'Should find id on second object');
849 $this->assertEquals(1, count($result['values']));
853 * Ensure that the "get" operation accepts limiting the #result records.
855 * TODO Consider making a separate entity list ("entities_getlimit")
856 * For the moment, the "entities_updatesingle" list should give a good
857 * sense for which entities support createTestObject
859 * @dataProvider entities_getlimit
861 * @param string $entityName
863 public function testLimit($entityName) {
864 $cases = array(); // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
866 array('options' => array('limit' => NULL)),
868 'check that a NULL limit returns unlimited',
871 array('options' => array('limit' => FALSE)),
873 'check that a FALSE limit returns unlimited',
876 array('options' => array('limit' => 0)),
878 'check that a 0 limit returns unlimited',
881 array('options' => array('limit' => 5)),
883 'check that a 5 limit returns 5',
888 'check that no limit returns 25',
891 $baoString = _civicrm_api3_get_BAO($entityName);
892 if (empty($baoString)) {
893 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
897 // make 30 test items -- 30 > 25 (the default limit)
899 for ($i = 0; $i < 30; $i++
) {
900 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
901 $ids[] = $baoObj->id
;
905 // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
906 foreach ($cases as $case) {
907 $this->checkLimitAgainstExpected($entityName, $case[0], $case[1], $case[2]);
909 //non preferred / legacy syntax
910 if (isset($case[0]['options']['limit'])) {
911 $this->checkLimitAgainstExpected($entityName, array('rowCount' => $case[0]['options']['limit']), $case[1], $case[2]);
912 $this->checkLimitAgainstExpected($entityName, array('option_limit' => $case[0]['options']['limit']), $case[1], $case[2]);
913 $this->checkLimitAgainstExpected($entityName, array('option.limit' => $case[0]['options']['limit']), $case[1], $case[2]);
916 foreach ($ids as $id) {
917 CRM_Core_DAO
::deleteTestObjects($baoString, array('id' => $id));
923 * Ensure that the "get" operation accepts limiting the #result records.
925 * @dataProvider entities_getSqlOperators
927 * @param string $entityName
929 public function testSqlOperators($entityName) {
930 $toBeIgnored = array_merge($this->toBeImplemented
['get'],
931 $this->deprecatedAPI
,
932 $this->toBeSkipped_get(TRUE),
933 $this->toBeSkipped_getByID()
935 if (in_array($entityName, $toBeIgnored)) {
939 $baoString = _civicrm_api3_get_BAO($entityName);
941 $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0), 'return' => 'id'));
942 $entities = array_keys($entities['values']);
943 $totalEntities = count($entities);
944 if ($totalEntities < 3) {
946 for ($i = 0; $i < 3 - $totalEntities; $i++
) {
947 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
948 $ids[] = $baoObj->id
;
953 $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0)));
954 $entities = array_keys($entities['values']);
955 $this->assertGreaterThan(2, $totalEntities);
956 $this->callAPISuccess($entityName, 'getsingle', array('id' => array('IN' => array($entities[0]))));
957 $this->callAPISuccessGetCount($entityName, array('id' => array('NOT IN' => array($entities[0]))), $totalEntities - 1);
958 $this->callAPISuccessGetCount($entityName, array('id' => array('>' => $entities[0])), $totalEntities - 1);
962 * Check that get fetches an appropriate number of results.
964 * @param string $entityName
965 * Name of entity to test.
966 * @param array $params
968 * @param string $message
970 public function checkLimitAgainstExpected($entityName, $params, $limit, $message) {
971 $result = $this->callAPISuccess($entityName, 'get', $params);
973 $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
974 $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
977 $this->assertEquals($limit, $result['count'], $message);
978 $this->assertEquals($limit, count($result['values']), $message);
983 * Create two entities and make sure we can fetch them individually by ID (e.g. using "contact_id=>2"
986 * @dataProvider entities_get
988 * limitations include the problem with avoiding loops when creating test objects -
989 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
990 * Currency - only seems to support US
992 * @throws \PHPUnit_Framework_IncompleteTestError
994 public function testByIDAlias_get($entityName) {
995 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
996 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1000 $baoString = _civicrm_api3_get_BAO($entityName);
1001 if (empty($baoString)) {
1002 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
1006 $idFieldName = _civicrm_api_get_entity_name_from_camel($entityName) . '_id';
1009 $baoObj1 = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1010 $this->assertTrue(is_int($baoObj1->id
), 'check first id');
1011 $this->deletableTestObjects
[$baoString][] = $baoObj1->id
;
1012 $baoObj2 = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1013 $this->assertTrue(is_int($baoObj2->id
), 'check second id');
1014 $this->deletableTestObjects
[$baoString][] = $baoObj2->id
;
1016 // fetch first by ID
1017 $result = civicrm_api($entityName, 'get', array(
1019 $idFieldName => $baoObj1->id
,
1021 $this->assertAPISuccess($result);
1022 $this->assertTrue(!empty($result['values'][$baoObj1->id
]), 'Should find first object by id');
1023 $this->assertEquals($baoObj1->id
, $result['values'][$baoObj1->id
]['id'], 'Should find id on first object');
1024 $this->assertEquals(1, count($result['values']));
1026 // fetch second by ID
1027 $result = civicrm_api($entityName, 'get', array(
1029 $idFieldName => $baoObj2->id
,
1031 $this->assertAPISuccess($result);
1032 $this->assertTrue(!empty($result['values'][$baoObj2->id
]), 'Should find second object by id');
1033 $this->assertEquals($baoObj2->id
, $result['values'][$baoObj2->id
]['id'], 'Should find id on second object');
1034 $this->assertEquals(1, count($result['values']));
1038 * @dataProvider entities_get
1041 public function testNonExistantID_get($Entity) {
1042 // cf testAcceptsOnlyID_get
1043 $nonExistantID = 30867307034;
1044 if (in_array($Entity, $this->toBeImplemented
['get'])) {
1048 $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
1050 // redundant with testAcceptsOnlyID_get
1051 if ($result['is_error']) {
1055 $this->assertArrayHasKey('version', $result);
1056 $this->assertEquals(3, $result['version']);
1057 if (!in_array($Entity, $this->onlyIDNonZeroCount
['get'])) {
1058 $this->assertEquals(0, $result['count']);
1062 /* ---- testing the _create ---- */
1065 * @dataProvider toBeSkipped_create
1066 entities that don't need a create action
1069 public function testNotImplemented_create($Entity) {
1070 $result = civicrm_api($Entity, 'Create', array('version' => 3));
1071 $this->assertEquals(1, $result['is_error']);
1072 $this->assertContains(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message']));
1076 * @dataProvider entities
1077 * @expectedException CiviCRM_API3_Exception
1080 public function testWithoutParam_create($Entity) {
1081 if ($Entity === 'Setting') {
1082 $this->markTestSkipped('It seems OK for setting to skip here as it silently sips invalid params');
1084 elseif ($Entity === 'Mailing') {
1085 $this->markTestSkipped('It seems OK for "Mailing" to skip here because you can create empty drafts');
1087 // should create php complaining that a param is missing
1088 civicrm_api3($Entity, 'Create');
1092 * @dataProvider entities_create
1094 * Check that create doesn't work with an invalid
1096 * @throws \PHPUnit_Framework_IncompleteTestError
1098 public function testInvalidSort_get($Entity) {
1099 $invalidEntitys = array('ActivityType', 'Setting', 'System');
1100 if (in_array($Entity, $invalidEntitys)) {
1101 $this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently sips invalid params');
1103 $result = $this->callAPIFailure($Entity, 'get', array('options' => array('sort' => 'sleep(1)')));
1107 * @dataProvider entities_create
1109 * Check that create doesn't work with an invalid
1111 * @throws \PHPUnit_Framework_IncompleteTestError
1113 public function testValidSortSingleArrayById_get($Entity) {
1114 $invalidEntitys = array('ActivityType', 'Setting', 'System');
1117 'id desc' => '_id desc',
1118 'id DESC' => '_id DESC',
1119 'id ASC' => '_id ASC',
1120 'id asc' => '_id asc');
1121 foreach ($tests as $test => $expected) {
1122 if (in_array($Entity, $invalidEntitys)) {
1123 $this->markTestSkipped('It seems OK for ' . $Entity . ' to skip here as it silently ignores passed in params');
1125 $params = array('sort' => array($test));
1126 $result = _civicrm_api3_get_options_from_params($params, FALSE, $Entity, 'get');
1127 $lowercase_entity = _civicrm_api_get_entity_name_from_camel($Entity);
1128 $this->assertEquals($lowercase_entity . $expected, $result['sort']);
1133 * @dataProvider entities_create
1135 * Check that create doesn't work with an invalid
1137 * @throws \PHPUnit_Framework_IncompleteTestError
1139 public function testInvalidID_create($Entity) {
1140 // turn test off for noew
1141 $this->markTestIncomplete("Entity [ $Entity ] cannot be mocked - no known DAO");
1143 if (in_array($Entity, $this->toBeImplemented
['create'])) {
1144 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1147 $result = $this->callAPIFailure($Entity, 'Create', array('id' => 999));
1151 * @dataProvider entities
1153 public function testCreateWrongTypeParamTag_create() {
1154 $result = civicrm_api("Tag", 'Create', 'this is not a string');
1155 $this->assertEquals(1, $result['is_error']);
1156 $this->assertEquals("Input variable `params` is not an array", $result['error_message']);
1160 * @dataProvider entities_updatesingle
1162 * limitations include the problem with avoiding loops when creating test objects -
1163 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
1164 * Currency - only seems to support US
1165 * @param $entityName
1167 public function testCreateSingleValueAlter($entityName) {
1168 if (in_array($entityName, $this->toBeImplemented
['create'])) {
1169 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1173 $baoString = _civicrm_api3_get_BAO($entityName);
1174 $this->assertNotEmpty($baoString, $entityName);
1175 $this->assertNotEmpty($entityName, $entityName);
1176 $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all')));
1177 if ($entityName != 'Pledge') {
1178 $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all')));
1180 $fields = $fields['values'];
1181 $return = array_keys($fieldsGet['values']);
1182 $valuesNotToReturn = $this->getKnownUnworkablesUpdateSingle($entityName, 'break_return');
1183 // these can't be requested as return values
1184 $entityValuesThatDoNotWork = array_merge(
1185 $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_update'),
1186 $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_return'),
1190 $return = array_diff($return, $valuesNotToReturn);
1191 $baoObj = new CRM_Core_DAO();
1192 $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
1194 $getEntities = $this->callAPISuccess($entityName, 'get', array(
1196 'return' => $return,
1198 'sort' => 'id DESC',
1203 // lets use first rather than assume only one exists
1204 $entity = $getEntities['values'][0];
1205 $entity2 = $getEntities['values'][1];
1206 $this->deletableTestObjects
[$baoString][] = $entity['id'];
1207 $this->deletableTestObjects
[$baoString][] = $entity2['id'];
1208 foreach ($fields as $field => $specs) {
1210 $fieldName = $field;
1211 if ($field == 'currency' ||
$field == 'id' ||
$field == strtolower($entityName) . '_id'
1212 ||
in_array($field, $entityValuesThatDoNotWork)
1214 //@todo id & entity_id are correct but we should fix currency & frequency_day
1217 $this->assertArrayHasKey('type', $specs, "the _spec function for $entityName field $field does not specify the type");
1218 switch ($specs['type']) {
1219 case CRM_Utils_Type
::T_DATE
:
1220 $entity[$fieldName] = '2012-05-20';
1223 case CRM_Utils_Type
::T_TIMESTAMP
:
1225 $entity[$fieldName] = '2012-05-20 03:05:20';
1228 case CRM_Utils_Type
::T_STRING
:
1229 case CRM_Utils_Type
::T_BLOB
:
1230 case CRM_Utils_Type
::T_MEDIUMBLOB
:
1231 case CRM_Utils_Type
::T_TEXT
:
1232 case CRM_Utils_Type
::T_LONGTEXT
:
1233 case CRM_Utils_Type
::T_EMAIL
:
1234 if ($fieldName == 'form_values' && $entityName == 'SavedSearch') {
1235 // This is a hack for the SavedSearch API.
1236 // It expects form_values to be an array.
1237 // If you want to fix this, you should definitely read this forum
1239 // http://forum.civicrm.org/index.php/topic,33990.0.html
1240 // See also my question on the CiviCRM Stack Exchange:
1241 // https://civicrm.stackexchange.com/questions/3437
1242 $entity[$fieldName] = array('sort_name' => "SortName2");
1245 $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array
::Value('maxlength', $specs, 100));
1246 if ($fieldName == 'email') {
1247 $entity[$fieldName] = strtolower($entity[$fieldName]);
1249 // typecast with array to satisfy changes made in CRM-13160
1250 if ($entityName == 'MembershipType' && in_array($fieldName, array(
1251 'relationship_type_id',
1252 'relationship_direction',
1255 $entity[$fieldName] = (array) $entity[$fieldName];
1260 case CRM_Utils_Type
::T_INT
:
1261 // probably created with a 1
1262 if ($fieldName == 'weight') {
1263 $entity[$fieldName] = 2;
1265 elseif (!empty($specs['FKClassName'])) {
1266 if ($specs['FKClassName'] == $baoString) {
1267 $entity[$fieldName] = (string) $entity2['id'];
1270 if (!empty($entity[$fieldName])) {
1271 $resetFKTo = array($fieldName => $entity[$fieldName]);
1273 $entity[$fieldName] = (string) empty($entity2[$field]) ?
'' : $entity2[$field];
1274 //todo - there isn't always something set here - & our checking on unset values is limited
1275 if (empty($entity[$field])) {
1276 unset($entity[$field]);
1281 $entity[$fieldName] = '6';
1285 case CRM_Utils_Type
::T_BOOLEAN
:
1286 // probably created with a 1
1287 $entity[$fieldName] = '0';
1290 case CRM_Utils_Type
::T_FLOAT
:
1291 case CRM_Utils_Type
::T_MONEY
:
1292 $entity[$field] = '22.75';
1295 case CRM_Utils_Type
::T_URL
:
1296 $entity[$field] = 'warm.beer.com';
1298 if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) ||
!empty($specs['options']))) {
1299 $options = CRM_Utils_Array
::value('options', $specs, array());
1301 //eg. pdf_format id doesn't ship with any
1302 if (isset($specs['pseudoconstant']['optionGroupName'])) {
1303 $optionValue = $this->callAPISuccess('option_value', 'create', array(
1304 'option_group_id' => $specs['pseudoconstant']['optionGroupName'],
1305 'label' => 'new option value',
1308 $optionValue = $optionValue['values'];
1309 $keyColumn = CRM_Utils_Array
::value('keyColumn', $specs['pseudoconstant'], 'value');
1310 $options[$optionValue[0][$keyColumn]] = 'new option value';
1313 $entity[$field] = array_rand($options);
1315 if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
1316 // in the weird situation where a field has both an fk and pseudoconstant defined,
1317 // e.g. campaign_id field, need to flush caches.
1318 // FIXME: Why doesn't creating a campaign clear caches?
1319 civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
1321 $updateParams = array(
1322 'id' => $entity['id'],
1323 $field => isset($entity[$field]) ?
$entity[$field] : NULL,
1325 if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
1326 //api has special handling on these 2 fields for backward compatibility reasons
1327 $entity['contribution_type_id'] = $updateParams['financial_type_id'];
1329 if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) {
1330 //api has special handling on these 2 fields for backward compatibility reasons
1331 $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date'];
1334 $update = $this->callAPISuccess($entityName, 'create', $updateParams);
1335 $checkParams = array(
1336 'id' => $entity['id'],
1338 'return' => $return,
1340 'sort' => 'id DESC',
1345 $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
1347 $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array(
1348 'update-params' => $updateParams,
1349 'update-result' => $update,
1350 'getsingle-params' => $checkParams,
1351 'getsingle-result' => $checkEntity,
1352 'expected entity' => $entity,
1355 //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
1356 $entity = array_merge($entity, $resetFKTo);
1357 $updateParams = array_merge($updateParams, $resetFKTo);
1358 $this->callAPISuccess($entityName, 'create', $updateParams);
1359 if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
1360 //api has special handling on these 2 fields for backward compatibility reasons
1361 $entity['contribution_type_id'] = $updateParams['financial_type_id'];
1363 if (isset($updateParams['next_sched_contribution_date']) && in_array($entityName, array('ContributionRecur'))) {
1364 //api has special handling on these 2 fields for backward compatibility reasons
1365 $entity['next_sched_contribution'] = $updateParams['next_sched_contribution_date'];
1372 /* ---- testing the _getFields ---- */
1374 /* ---- testing the _delete ---- */
1377 * @dataProvider toBeSkipped_delete
1378 entities that don't need a delete action
1381 public function testNotImplemented_delete($Entity) {
1382 $nonExistantID = 151416349;
1383 $result = civicrm_api($Entity, 'Delete', array('version' => 3, 'id' => $nonExistantID));
1384 $this->assertEquals(1, $result['is_error']);
1385 $this->assertContains(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message']));
1389 * @dataProvider entities
1390 * @expectedException PHPUnit_Framework_Error
1393 public function testWithoutParam_delete($Entity) {
1394 // should delete php complaining that a param is missing
1395 $result = civicrm_api($Entity, 'Delete');
1399 * @dataProvider entities_delete
1402 public function testEmptyParam_delete($Entity) {
1403 if (in_array($Entity, $this->toBeImplemented
['delete'])) {
1404 // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
1407 $result = civicrm_api($Entity, 'Delete', array());
1408 $this->assertEquals(1, $result['is_error']);
1409 $this->assertContains("Unknown api version", $result['error_message']);
1413 * @dataProvider entities_delete
1415 * @throws \PHPUnit_Framework_IncompleteTestError
1417 public function testInvalidID_delete($Entity) {
1418 $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999));
1422 * @dataProvider entities
1424 public function testDeleteWrongTypeParamTag_delete() {
1425 $result = civicrm_api("Tag", 'Delete', 'this is not a string');
1426 $this->assertEquals(1, $result['is_error']);
1427 $this->assertEquals("Input variable `params` is not an array", $result['error_message']);
1431 * Create two entities and make sure delete action only deletes one!
1433 * @dataProvider entities_delete
1435 * limitations include the problem with avoiding loops when creating test objects -
1436 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
1437 * Currency - only seems to support US
1438 * @param $entityName
1439 * @throws \PHPUnit_Framework_IncompleteTestError
1441 public function testByID_delete($entityName) {
1442 // turn test off for noew
1443 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
1446 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
1447 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1450 $startCount = $this->callAPISuccess($entityName, 'getcount', array());
1452 $baos = $this->getMockableBAOObjects($entityName, $createcount);
1453 list($baoObj1, $baoObj2) = $baos;
1455 // make sure exactly 2 exist
1456 $result = $this->callAPISuccess($entityName, 'getcount', array(),
1457 $createcount +
$startCount
1460 $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id
));
1461 //make sure 1 less exists now
1462 $result = $this->callAPISuccess($entityName, 'getcount', array(),
1463 ($createcount +
$startCount) - 1
1466 //make sure id #1 exists
1467 $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj1->id
),
1470 //make sure id #2 desn't exist
1471 $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj2->id
),
1477 * Create two entities and make sure delete action only deletes one!
1479 * @dataProvider entities_getfields
1482 public function testGetfieldsHasTitle($entity) {
1483 $entities = $this->getEntitiesSupportingCustomFields();
1484 if (in_array($entity, $entities)) {
1485 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, $entity . 'Test.php');
1487 $actions = $this->callAPISuccess($entity, 'getactions', array());
1488 foreach ($actions['values'] as $action) {
1489 if (substr($action, -7) == '_create' ||
substr($action, -4) == '_get' ||
substr($action, -7) == '_delete') {
1490 //getactions can't distinguish between contribution_page.create & contribution_page.create
1493 $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action));
1494 if (!empty($ids) && in_array($action, array('create', 'get'))) {
1495 $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']);
1498 foreach ($fields['values'] as $fieldName => $fieldSpec) {
1499 $this->assertArrayHasKey('title', $fieldSpec, "no title for $entity - $fieldName on action $action");
1500 $this->assertNotEmpty($fieldSpec['title'], "empty title for $entity - $fieldName");
1504 $this->customFieldDelete($ids['custom_field_id']);
1505 $this->customGroupDelete($ids['custom_group_id']);
1512 public function getEntitiesSupportingCustomFields() {
1513 $entities = self
::custom_data_entities_get();
1514 $returnEntities = array();
1515 foreach ($entities as $entityArray) {
1516 $returnEntities[] = $entityArray[0];
1518 return $returnEntities;
1522 * @param string $entityName
1527 private function getMockableBAOObjects($entityName, $count = 2) {
1528 $baoString = _civicrm_api3_get_BAO($entityName);
1529 if (empty($baoString)) {
1530 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
1535 while ($i < $count) {
1537 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1538 $this->assertTrue(is_int($baoObj->id
), 'check first id');
1539 $this->deletableTestObjects
[$baoString][] = $baoObj->id
;
1547 * Verify that HTML metacharacters provided as inputs appear consistently.
1550 * At time of writing, the encoding scheme requires (for example) that an
1551 * event title be partially-HTML-escaped before writing to DB. To provide
1552 * consistency, the API must perform extra encoding and decoding on some
1555 * In this example, the event 'title' is subject to encoding, but the
1556 * event 'description' is not.
1558 public function testEncodeDecodeConsistency() {
1560 $createResult = civicrm_api('Event', 'Create', array(
1562 'title' => 'CiviCRM <> TheRest',
1563 'description' => 'TheRest <> CiviCRM',
1564 'event_type_id' => 1,
1566 'start_date' => 20081021,
1568 $this->assertAPISuccess($createResult);
1569 $eventId = $createResult['id'];
1570 $this->assertEquals('CiviCRM <> TheRest', $createResult['values'][$eventId]['title']);
1571 $this->assertEquals('TheRest <> CiviCRM', $createResult['values'][$eventId]['description']);
1573 // Verify "get" handles decoding in result value
1574 $getByIdResult = civicrm_api('Event', 'Get', array(
1578 $this->assertAPISuccess($getByIdResult);
1579 $this->assertEquals('CiviCRM <> TheRest', $getByIdResult['values'][$eventId]['title']);
1580 $this->assertEquals('TheRest <> CiviCRM', $getByIdResult['values'][$eventId]['description']);
1582 // Verify "get" handles encoding in search value
1583 $getByTitleResult = civicrm_api('Event', 'Get', array(
1585 'title' => 'CiviCRM <> TheRest',
1587 $this->assertAPISuccess($getByTitleResult);
1588 $this->assertEquals('CiviCRM <> TheRest', $getByTitleResult['values'][$eventId]['title']);
1589 $this->assertEquals('TheRest <> CiviCRM', $getByTitleResult['values'][$eventId]['description']);
1591 // Verify that "getSingle" handles decoding
1592 $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', array(
1596 $this->assertEquals('CiviCRM <> TheRest', $getSingleResult['title']);
1597 $this->assertEquals('TheRest <> CiviCRM', $getSingleResult['description']);
1599 // Verify that chaining handles decoding
1600 $chainResult = $this->callAPISuccess('Event', 'Get', array(
1602 'api.event.get' => array(),
1604 $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['title']);
1605 $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['description']);
1606 $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['api.event.get']['values'][0]['title']);
1607 $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['api.event.get']['values'][0]['description']);
1609 // Verify that "setvalue" handles encoding for updates
1610 $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
1614 'value' => 'setValueTitle: CiviCRM <> TheRest',
1616 $this->assertAPISuccess($setValueTitleResult);
1617 $this->assertEquals('setValueTitle: CiviCRM <> TheRest', $setValueTitleResult['values']['title']);
1618 $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
1621 'field' => 'description',
1622 'value' => 'setValueDescription: TheRest <> CiviCRM',
1624 //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
1625 $this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']);
1629 * Verify that write operations (create/update) use partial HTML-encoding
1631 * In this example, the event 'title' is subject to encoding, but the
1632 * event 'description' is not.
1634 public function testEncodeWrite() {
1636 $createResult = civicrm_api('Event', 'Create', array(
1638 'title' => 'createNew: CiviCRM <> TheRest',
1639 'description' => 'createNew: TheRest <> CiviCRM',
1640 'event_type_id' => 1,
1642 'start_date' => 20081021,
1644 $this->assertAPISuccess($createResult);
1645 $eventId = $createResult['id'];
1646 $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1647 1 => array($eventId, 'Integer'),
1649 $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1650 1 => array($eventId, 'Integer'),
1653 // Verify that "create" handles encoding for updates
1654 $createWithIdResult = civicrm_api('Event', 'Create', array(
1657 'title' => 'createWithId: CiviCRM <> TheRest',
1658 'description' => 'createWithId: TheRest <> CiviCRM',
1660 $this->assertAPISuccess($createWithIdResult);
1661 $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1662 1 => array($eventId, 'Integer'),
1664 $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1665 1 => array($eventId, 'Integer'),
1668 // Verify that "setvalue" handles encoding for updates
1669 $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
1673 'value' => 'setValueTitle: CiviCRM <> TheRest',
1675 $this->assertAPISuccess($setValueTitleResult);
1676 $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1677 1 => array($eventId, 'Integer'),
1679 $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
1682 'field' => 'description',
1683 'value' => 'setValueDescription: TheRest <> CiviCRM',
1685 //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
1686 $this->assertAPISuccess($setValueDescriptionResult);
1687 $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1688 1 => array($eventId, 'Integer'),