3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test that the core actions for APIv3 entities comply with standard syntax+behavior.
34 * By default, this tests all API entities. To only test specific entities, call phpunit with
35 * environment variable SYNTAX_CONFORMANCE_ENTITIES, e.g.
37 * env SYNTAX_CONFORMANCE_ENTITIES="Contact Event" ./scripts/phpunit api_v3_SyntaxConformanceTest
39 * @package CiviCRM_APIv3
40 * @subpackage API_Core
42 class api_v3_SyntaxConformanceTest
extends CiviUnitTestCase
{
43 protected $_apiversion = 3;
46 * @var array e.g. $this->deletes['CRM_Contact_DAO_Contact'][] = $contactID;
48 protected $deletableTestObjects;
51 * This test case doesn't require DB reset.
53 public $DBResetRequired = FALSE;
58 * Map custom group entities to civicrm components.
60 static $componentMap = array(
61 'Contribution' => 'CiviContribute',
62 'Membership' => 'CiviMember',
63 'Participant' => 'CiviEvent',
64 'Event' => 'CiviEvent',
66 'Pledge' => 'CiviPledge',
67 'Grant' => 'CiviGrant',
68 'Campaign' => 'CiviCampaign',
69 'Survey' => 'CiviCampaign',
75 * There are two types of missing APIs:
76 * Those that are to be implemented
77 * (in some future version when someone steps in -hint hint-). List the entities in toBeImplemented[ {$action} ]
78 * Those that don't exist
79 * and that will never exist (eg an obsoleted Entity
80 * 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)
82 public function setUp() {
84 $this->enableCiviCampaign();
85 $this->toBeImplemented
['get'] = array(
86 'CxnApp', // CxnApp.get exists but relies on remote data outside our control; QA w/UtilsTest::testBasicArrayGet
97 $this->toBeImplemented
['create'] = array(
111 'SavedSearch', //work fine in local
113 $this->toBeImplemented
['delete'] = array(
126 $this->onlyIDNonZeroCount
['get'] = array(
133 $this->deprecatedAPI
= array('Location', 'ActivityType', 'SurveyRespondant');
134 $this->deletableTestObjects
= array();
137 public function tearDown() {
138 foreach ($this->deletableTestObjects
as $entityName => $entities) {
139 foreach ($entities as $entityID) {
140 CRM_Core_DAO
::deleteTestObjects($entityName, array('id' => $entityID));
146 * Generate list of all entities.
153 public static function entities($skip = array()) {
154 // The order of operations in here is screwy. In the case where SYNTAX_CONFORMANCE_ENTITIES is
155 // defined, we should be able to parse+return it immediately. However, some weird dependency
156 // crept into the system where civicrm_api('Entity','get') must be called as part of entities()
157 // (even if its return value is ignored).
159 $tmp = civicrm_api('Entity', 'Get', array('version' => 3));
160 if (getenv('SYNTAX_CONFORMANCE_ENTITIES')) {
162 'values' => explode(' ', getenv('SYNTAX_CONFORMANCE_ENTITIES')),
166 if (!is_array($skip)) {
169 $tmp = array_diff($tmp['values'], $skip);
171 foreach ($tmp as $e) {
172 $entities[] = array($e);
178 * Get list of entities for get test.
182 public static function entities_get() {
183 // all the entities, beside the ones flagged
184 return static::entities(static::toBeSkipped_get(TRUE));
188 * Get entities for create tests.
192 public static function entities_create() {
193 return static::entities(static::toBeSkipped_create(TRUE));
199 public static function entities_updatesingle() {
200 return static::entities(static::toBeSkipped_updatesingle(TRUE));
206 public static function entities_getlimit() {
207 return static::entities(static::toBeSkipped_getlimit());
211 * Generate list of entities that can be retrieved using SQL operator syntax.
215 public static function entities_getSqlOperators() {
216 return static::entities(static::toBeSkipped_getSqlOperators());
222 public static function entities_delete() {
223 return static::entities(static::toBeSkipped_delete(TRUE));
229 public static function entities_getfields() {
230 return static::entities(static::toBeSkipped_getfields(TRUE));
236 public static function custom_data_entities_get() {
237 return static::custom_data_entities();
243 public static function custom_data_entities() {
244 $entities = CRM_Core_BAO_CustomQuery
::$extendsMap;
245 $enabledComponents = Civi
::settings()->get('enable_components');
246 $customDataEntities = array();
247 $invalidEntities = array('Individual', 'Organization', 'Household');
248 $entitiesToFix = array('Case', 'Relationship');
249 foreach ($entities as $entityName => $entity) {
250 if (!in_array($entityName, $invalidEntities)
251 && !in_array($entityName, $entitiesToFix)
253 if (!empty(self
::$componentMap[$entityName]) && empty($enabledComponents[self
::$componentMap[$entityName]])) {
254 CRM_Core_BAO_ConfigSetting
::enableComponent(self
::$componentMap[$entityName]);
256 $customDataEntities[] = array($entityName);
259 return $customDataEntities;
263 * Get entities to be skipped on get tests.
265 * @param bool $sequential
269 public static function toBeSkipped_get($sequential = FALSE) {
270 $entitiesWithoutGet = array(
271 'MailingEventSubscribe',
272 'MailingEventConfirm',
273 'MailingEventResubscribe',
274 'MailingEventUnsubscribe',
277 if ($sequential === TRUE) {
278 return $entitiesWithoutGet;
281 foreach ($entitiesWithoutGet as $e) {
282 $entities[] = array($e);
288 * Get entities to be skipped for get call.
290 * Mailing Contact Just doesn't support id. We have always insisted on finding a way to
291 * support id in API but in this case the underlying tables are crying out for a restructure
292 * & it just doesn't make sense.
294 * User doesn't support get By ID because the user id is actually the CMS user ID & is not part of
295 * CiviCRM - so can only be tested through UserTest - not SyntaxConformanceTest.
297 * Entity doesn't support get By ID because it simply gives the result of string Entites in CiviCRM
299 * @param bool $sequential
302 * Entities that cannot be retrieved by ID
304 public static function toBeSkipped_getByID($sequential = FALSE) {
305 return array('MailingContact', 'User', 'Attachment', 'Entity');
309 * @param bool $sequential
313 public static function toBeSkipped_create($sequential = FALSE) {
314 $entitiesWithoutCreate = array('Constant', 'Entity', 'Location', 'Profile', 'MailingRecipients');
315 if ($sequential === TRUE) {
316 return $entitiesWithoutCreate;
319 foreach ($entitiesWithoutCreate as $e) {
320 $entities[] = array($e);
326 * @param bool $sequential
330 public static function toBeSkipped_delete($sequential = FALSE) {
331 $entitiesWithout = array(
333 'MailingEventConfirm',
334 'MailingEventResubscribe',
335 'MailingEventSubscribe',
336 'MailingEventUnsubscribe',
347 if ($sequential === TRUE) {
348 return $entitiesWithout;
351 foreach ($entitiesWithout as $e) {
352 $entities[] = array($e);
358 * @param bool $sequential
361 * @todo add metadata for ALL these entities
363 public static function toBeSkipped_getfields($sequential = FALSE) {
364 $entitiesWithMetadataNotYetFixed = array('ReportTemplate', 'CustomSearch');
365 if ($sequential === TRUE) {
366 return $entitiesWithMetadataNotYetFixed;
369 foreach ($entitiesWithMetadataNotYetFixed as $e) {
370 $entities[] = array($e);
376 * Generate list of entities to test for get by id functions.
377 * @param bool $sequential
379 * Entities to be skipped
381 public static function toBeSkipped_automock($sequential = FALSE) {
382 $entitiesWithoutGet = array(
386 'ParticipantPayment',
395 if ($sequential === TRUE) {
396 return $entitiesWithoutGet;
399 foreach ($entitiesWithoutGet as $e) {
400 $entities[] = array($e);
407 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
408 * @param bool $sequential
411 public static function toBeSkipped_updatesingle($sequential = FALSE) {
412 $entitiesWithout = array(
414 // pseudo-entity; testUpdateSingleValueAlter doesn't introspect properly on it. Multiple magic fields
419 'MailingEventUnsubscribe',
420 'MailingEventSubscribe',
446 'MailingEventConfirm',
450 'MailingEventResubscribe',
457 'ParticipantPayment',
466 //skip this because it doesn't make sense to update logs,
468 if ($sequential === TRUE) {
469 return $entitiesWithout;
472 foreach ($entitiesWithout as $e) {
477 return array('pledge');
482 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
484 public static function toBeSkipped_getlimit() {
485 $entitiesWithout = array(
487 //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
489 // non-standard api - has inappropriate mandatory fields & doesn't implement limit
491 // failed 'check that a 5 limit returns 5' - probably is_template field is wrong or something, or could be limit doesn't work right
493 // can't handle creating 25
495 // fails on 5 limit - probably a set up problem
497 //a bit of a pseudoapi - keys by domain
499 return $entitiesWithout;
503 * At this stage exclude the ones that don't pass & add them as we can troubleshoot them
505 public static function toBeSkipped_getSqlOperators() {
506 $entitiesWithout = array(
507 'Case', //case api has non-std mandatory fields one of (case_id, contact_id, activity_id, contact_id)
508 'Contact', // on the todo list!
509 'EntityTag', // non-standard api - has inappropriate mandatory fields & doesn't implement limit
510 'Extension', // can't handle creating 25
511 'Note', // note has a default get that isn't implemented in createTestObject -meaning you don't 'get' them
512 'Setting', //a bit of a pseudoapi - keys by domain
514 return $entitiesWithout;
523 public function getKnownUnworkablesUpdateSingle($entity, $key) {
524 // can't update values are values for which updates don't result in the value being changed
525 $knownFailures = array(
526 'ActionSchedule' => array(
527 'cant_update' => array(
531 'ActivityContact' => array(
532 'cant_update' => array(
534 //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
538 'cant_update' => array(
539 'state_province_id', //issues with country id - need to ensure same country
540 'master_id', //creates relationship
542 'cant_return' => array(),
545 'cant_update' => array(
546 'entity_table', // believe this field is defined in error
548 'cant_return' => array(
553 'cant_update' => array(
557 'MembershipBlock' => array(
558 'cant_update' => array(
559 // The fake/auto-generated values leave us unable to properly cleanup fake data
564 'ContributionSoft' => array(
565 'cant_update' => array(
566 // can't be changed through api
571 'cant_update' => array(
572 // This is being legitimately manipulated to always have a valid primary - skip.
576 'Navigation' => array(
577 'cant_update' => array(
578 // Weight is deliberately altered when this is changed - skip.
582 'LocationType' => array(
583 'cant_update' => array(
584 // I'm on the fence about whether the test should skip or the behaviour is wrong.
585 // display_name is set to match name if display_name is not provided. It would be more 'normal'
586 // to only calculate a default IF id is not set - but perhaps the current behaviour is kind
587 // of what someone updating the name expects..
592 'cant_update' => array(
593 'pledge_original_installment_amount',
595 'original_installment_amount',
597 'amount', // can't be changed through API,
599 'break_return' => array(// if these are passed in they are retrieved from the wrong table
602 'contribution_page_id',
603 'financial_account_id',
607 'cant_return' => array(// can't be retrieved from api
608 'honor_type_id', //due to uniquename missing
616 'initial_reminder_day',
617 'additional_reminder_day',
619 'pledge_contribution_page_id',
621 'pledge_campaign_id',
622 'pledge_financial_type_id',
625 'PaymentProcessorType' => array(
626 'cant_update' => array(
629 'break_return' => array(),
630 'cant_return' => array(),
632 'PriceFieldValue' => array(
633 'cant_update' => array(
634 'weight', //won't update as there is no 1 in the same price set
637 'ReportInstance' => array(
638 // View mode is part of the navigation which is not retrieved by the api.
639 'cant_return' => array('view_mode'),
641 'SavedSearch' => array(
642 // I think the fields below are generated based on form_values.
643 'cant_update' => array(
650 'StatusPreference' => array(
651 'break_return' => array(
656 if (empty($knownFailures[$entity]) ||
empty($knownFailures[$entity][$key])) {
659 return $knownFailures[$entity][$key];
662 /* ----- testing the _get ----- */
665 * @dataProvider toBeSkipped_get
666 * Entities that don't need a get action
669 public function testNotImplemented_get($Entity) {
670 $result = civicrm_api($Entity, 'Get', array('version' => 3));
671 $this->assertEquals(1, $result['is_error']);
672 // $this->assertContains("API ($Entity, Get) does not exist", $result['error_message']);
673 $this->assertRegExp('/API (.*) does not exist/', $result['error_message']);
677 * @dataProvider entities
678 * @expectedException PHPUnit_Framework_Error
681 public function testWithoutParam_get($Entity) {
682 // should get php complaining that a param is missing
683 $result = civicrm_api($Entity, 'Get');
687 * @dataProvider entities
690 public function testGetFields($Entity) {
691 if (in_array($Entity, $this->deprecatedAPI
) ||
$Entity == 'Entity' ||
$Entity == 'CustomValue') {
695 $result = civicrm_api($Entity, 'getfields', array('version' => 3));
696 $this->assertTrue(is_array($result['values']), "$Entity ::get fields doesn't return values array in line " . __LINE__
);
697 foreach ($result['values'] as $key => $value) {
698 $this->assertTrue(is_array($value), $Entity . "::" . $key . " is not an array in line " . __LINE__
);
703 * @dataProvider entities_get
706 public function testEmptyParam_get($Entity) {
708 if (in_array($Entity, $this->toBeImplemented
['get'])) {
709 // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented");
712 $result = civicrm_api($Entity, 'Get', array());
713 $this->assertEquals(1, $result['is_error']);
714 $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
718 * @dataProvider entities_get
721 public function testEmptyParam_getString($Entity) {
723 if (in_array($Entity, $this->toBeImplemented
['get'])) {
724 // $this->markTestIncomplete("civicrm_api3_{$Entity}_get to be implemented");
727 $result = $this->callAPIFailure($Entity, 'Get', 'string');
728 $this->assertEquals(2000, $result['error_code']);
729 $this->assertEquals('Input variable `params` is not an array', $result['error_message']);
733 * @dataProvider entities_get
734 * @Xdepends testEmptyParam_get // no need to test the simple if the empty doesn't work/is skipped. doesn't seem to work
737 public function testSimple_get($Entity) {
738 // $this->markTestSkipped("test gives core error on test server (but not on our locals). Skip until we can get server to pass");
739 if (in_array($Entity, $this->toBeImplemented
['get'])) {
742 $result = civicrm_api($Entity, 'Get', array('version' => 3));
743 // @TODO: list the get that have mandatory params
744 if ($result['is_error']) {
745 $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
746 // either id or contact_id or entity_id is one of the field missing
747 $this->assertContains("id", $result['error_message']);
750 $this->assertEquals(3, $result['version']);
751 $this->assertArrayHasKey('count', $result);
752 $this->assertArrayHasKey('values', $result);
757 * @dataProvider custom_data_entities_get
760 public function testCustomDataGet($entityName) {
761 $this->createLoggedInUser();// so subsidiary activities are created
762 // We are not passing 'check_permissions' so the the more limited permissions *should* be
763 // ignored but per CRM-17700 there is a history of custom data applying permissions when it shouldn't.
764 CRM_Core_Config
::singleton()->userPermissionClass
->permissions
= array('access CiviCRM', 'view my contact');
765 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, $entityName . 'Test.php');
766 $customFieldName = 'custom_' . $ids['custom_field_id'];
767 $objects = $this->getMockableBAOObjects($entityName, 1);
768 $params = array('id' => $objects[0]->id
, 'custom_' . $ids['custom_field_id'] => "custom string");
769 $result = $this->callAPISuccess($entityName, 'create', $params);
771 $getParams = array('id' => $result['id'], 'return' => array($customFieldName));
772 $check = $this->callAPISuccess($entityName, 'get', $getParams);
773 $this->assertEquals("custom string", $check['values'][$check['id']][$customFieldName]);
775 $this->customFieldDelete($ids['custom_field_id']);
776 $this->customGroupDelete($ids['custom_group_id']);
777 $this->callAPISuccess($entityName, 'delete', array('id' => $result['id']));
778 $this->quickCleanup(array('civicrm_uf_match'));
782 * @dataProvider entities_get
785 public function testAcceptsOnlyID_get($Entity) {
786 // big random number. fun fact: if you multiply it by pi^e, the result is another random number, but bigger ;)
787 $nonExistantID = 30867307034;
788 if (in_array($Entity, $this->toBeImplemented
['get'])
789 ||
in_array($Entity, $this->toBeSkipped_getByID())
795 // the below function returns different values and hence an early return
796 // we'll fix this once beta1 is released
799 $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
801 if ($result['is_error']) {
802 // just to get a clearer message in the log
803 $this->assertEquals("only id should be enough", $result['error_message']);
805 if (!in_array($Entity, $this->onlyIDNonZeroCount
['get'])) {
806 $this->assertEquals(0, $result['count']);
811 * Create two entities and make sure we can fetch them individually by ID.
813 * @dataProvider entities_get
815 * limitations include the problem with avoiding loops when creating test objects -
816 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
817 * Currency - only seems to support US
820 public function testByID_get($entityName) {
821 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
822 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
826 $baos = $this->getMockableBAOObjects($entityName);
827 list($baoObj1, $baoObj2) = $baos;
830 $result = $this->callAPISuccess($entityName, 'get', array(
831 'id' => $baoObj1->id
,
834 $this->assertTrue(!empty($result['values'][$baoObj1->id
]), 'Should find first object by id');
835 $this->assertEquals($baoObj1->id
, $result['values'][$baoObj1->id
]['id'], 'Should find id on first object');
836 $this->assertEquals(1, count($result['values']));
838 // fetch second by ID
839 $result = $this->callAPISuccess($entityName, 'get', array(
840 'id' => $baoObj2->id
,
842 $this->assertTrue(!empty($result['values'][$baoObj2->id
]), 'Should find second object by id');
843 $this->assertEquals($baoObj2->id
, $result['values'][$baoObj2->id
]['id'], 'Should find id on second object');
844 $this->assertEquals(1, count($result['values']));
848 * Ensure that the "get" operation accepts limiting the #result records.
850 * TODO Consider making a separate entity list ("entities_getlimit")
851 * For the moment, the "entities_updatesingle" list should give a good
852 * sense for which entities support createTestObject
854 * @dataProvider entities_getlimit
856 * @param string $entityName
858 public function testLimit($entityName) {
859 $cases = array(); // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
861 array('options' => array('limit' => NULL)),
863 'check that a NULL limit returns unlimited',
866 array('options' => array('limit' => FALSE)),
868 'check that a FALSE limit returns unlimited',
871 array('options' => array('limit' => 0)),
873 'check that a 0 limit returns unlimited',
876 array('options' => array('limit' => 5)),
878 'check that a 5 limit returns 5',
883 'check that no limit returns 25',
886 $baoString = _civicrm_api3_get_BAO($entityName);
887 if (empty($baoString)) {
888 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
892 // make 30 test items -- 30 > 25 (the default limit)
894 for ($i = 0; $i < 30; $i++
) {
895 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
896 $ids[] = $baoObj->id
;
899 // each case is array(0 => $inputtedApiOptions, 1 => $expectedResultCount)
900 foreach ($cases as $case) {
901 $this->checkLimitAgainstExpected($entityName, $case[0], $case[1], $case[2]);
903 //non preferred / legacy syntax
904 if (isset($case[0]['options']['limit'])) {
905 $this->checkLimitAgainstExpected($entityName, array('rowCount' => $case[0]['options']['limit']), $case[1], $case[2]);
906 $this->checkLimitAgainstExpected($entityName, array('option_limit' => $case[0]['options']['limit']), $case[1], $case[2]);
907 $this->checkLimitAgainstExpected($entityName, array('option.limit' => $case[0]['options']['limit']), $case[1], $case[2]);
910 foreach ($ids as $id) {
911 CRM_Core_DAO
::deleteTestObjects($baoString, array('id' => $id));
917 * Ensure that the "get" operation accepts limiting the #result records.
919 * @dataProvider entities_getSqlOperators
921 * @param string $entityName
923 public function testSqlOperators($entityName) {
924 $toBeIgnored = array_merge($this->toBeImplemented
['get'],
925 $this->deprecatedAPI
,
926 $this->toBeSkipped_get(TRUE),
927 $this->toBeSkipped_getByID()
929 if (in_array($entityName, $toBeIgnored)) {
933 $baoString = _civicrm_api3_get_BAO($entityName);
935 $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0), 'return' => 'id'));
936 $entities = array_keys($entities['values']);
937 $totalEntities = count($entities);
938 if ($totalEntities < 3) {
940 for ($i = 0; $i < 3 - $totalEntities; $i++
) {
941 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
942 $ids[] = $baoObj->id
;
946 $entities = $this->callAPISuccess($entityName, 'get', array('options' => array('limit' => 0)));
947 $entities = array_keys($entities['values']);
948 $this->assertGreaterThan(2, $totalEntities);
949 $this->callAPISuccess($entityName, 'getsingle', array('id' => array('IN' => array($entities[0]))));
950 $this->callAPISuccessGetCount($entityName, array('id' => array('NOT IN' => array($entities[0]))), $totalEntities - 1);
951 $this->callAPISuccessGetCount($entityName, array('id' => array('>' => $entities[0])), $totalEntities - 1);
955 * Check that get fetches an appropriate number of results.
957 * @param string $entityName
958 * Name of entity to test.
959 * @param array $params
961 * @param string $message
963 public function checkLimitAgainstExpected($entityName, $params, $limit, $message) {
964 $result = $this->callAPISuccess($entityName, 'get', $params);
966 $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
967 $this->assertGreaterThanOrEqual($limit, $result['count'], $message);
970 $this->assertEquals($limit, $result['count'], $message);
971 $this->assertEquals($limit, count($result['values']), $message);
976 * Create two entities and make sure we can fetch them individually by ID (e.g. using "contact_id=>2"
979 * @dataProvider entities_get
981 * limitations include the problem with avoiding loops when creating test objects -
982 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
983 * Currency - only seems to support US
985 * @throws \PHPUnit_Framework_IncompleteTestError
987 public function testByIDAlias_get($entityName) {
988 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
989 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
993 $baoString = _civicrm_api3_get_BAO($entityName);
994 if (empty($baoString)) {
995 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
999 $idFieldName = _civicrm_api_get_entity_name_from_camel($entityName) . '_id';
1002 $baoObj1 = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1003 $this->assertTrue(is_int($baoObj1->id
), 'check first id');
1004 $this->deletableTestObjects
[$baoString][] = $baoObj1->id
;
1005 $baoObj2 = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1006 $this->assertTrue(is_int($baoObj2->id
), 'check second id');
1007 $this->deletableTestObjects
[$baoString][] = $baoObj2->id
;
1009 // fetch first by ID
1010 $result = civicrm_api($entityName, 'get', array(
1012 $idFieldName => $baoObj1->id
,
1014 $this->assertAPISuccess($result);
1015 $this->assertTrue(!empty($result['values'][$baoObj1->id
]), 'Should find first object by id');
1016 $this->assertEquals($baoObj1->id
, $result['values'][$baoObj1->id
]['id'], 'Should find id on first object');
1017 $this->assertEquals(1, count($result['values']));
1019 // fetch second by ID
1020 $result = civicrm_api($entityName, 'get', array(
1022 $idFieldName => $baoObj2->id
,
1024 $this->assertAPISuccess($result);
1025 $this->assertTrue(!empty($result['values'][$baoObj2->id
]), 'Should find second object by id');
1026 $this->assertEquals($baoObj2->id
, $result['values'][$baoObj2->id
]['id'], 'Should find id on second object');
1027 $this->assertEquals(1, count($result['values']));
1031 * @dataProvider entities_get
1034 public function testNonExistantID_get($Entity) {
1035 // cf testAcceptsOnlyID_get
1036 $nonExistantID = 30867307034;
1037 if (in_array($Entity, $this->toBeImplemented
['get'])) {
1041 $result = civicrm_api($Entity, 'Get', array('version' => 3, 'id' => $nonExistantID));
1043 // redundant with testAcceptsOnlyID_get
1044 if ($result['is_error']) {
1048 $this->assertArrayHasKey('version', $result);
1049 $this->assertEquals(3, $result['version']);
1050 if (!in_array($Entity, $this->onlyIDNonZeroCount
['get'])) {
1051 $this->assertEquals(0, $result['count']);
1055 /* ---- testing the _create ---- */
1058 * @dataProvider toBeSkipped_create
1059 entities that don't need a create action
1062 public function testNotImplemented_create($Entity) {
1063 $result = civicrm_api($Entity, 'Create', array('version' => 3));
1064 $this->assertEquals(1, $result['is_error']);
1065 $this->assertContains(strtolower("API ($Entity, Create) does not exist"), strtolower($result['error_message']));
1069 * @dataProvider entities
1070 * @expectedException PHPUnit_Framework_Error
1073 public function testWithoutParam_create($Entity) {
1074 // should create php complaining that a param is missing
1075 $result = civicrm_api($Entity, 'Create');
1079 * @dataProvider entities_create
1081 * @throws \PHPUnit_Framework_IncompleteTestError
1083 public function testEmptyParam_create($Entity) {
1084 $this->markTestIncomplete("fixing this test to test the api functions fails on numerous tests
1085 which will either create a completely blank entity (batch, participant status) or
1086 have a damn good crack at it (e.g mailing job). Marking this as incomplete beats false success");
1088 if (in_array($Entity, $this->toBeImplemented
['create'])) {
1089 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1092 $result = $this->callAPIFailure($Entity, 'Create', array());
1093 $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
1097 * @dataProvider entities_create
1099 * Check that create doesn't work with an invalid
1101 * @throws \PHPUnit_Framework_IncompleteTestError
1103 public function testInvalidID_create($Entity) {
1104 // turn test off for noew
1105 $this->markTestIncomplete("Entity [ $Entity ] cannot be mocked - no known DAO");
1107 if (in_array($Entity, $this->toBeImplemented
['create'])) {
1108 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1111 $result = $this->callAPIFailure($Entity, 'Create', array('id' => 999));
1115 * @dataProvider entities
1117 public function testCreateWrongTypeParamTag_create() {
1118 $result = civicrm_api("Tag", 'Create', 'this is not a string');
1119 $this->assertEquals(1, $result['is_error']);
1120 $this->assertEquals("Input variable `params` is not an array", $result['error_message']);
1124 * @dataProvider entities_updatesingle
1126 * limitations include the problem with avoiding loops when creating test objects -
1127 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
1128 * Currency - only seems to support US
1129 * @param $entityName
1131 public function testCreateSingleValueAlter($entityName) {
1132 if (in_array($entityName, $this->toBeImplemented
['create'])) {
1133 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1137 $baoString = _civicrm_api3_get_BAO($entityName);
1138 $this->assertNotEmpty($baoString, $entityName);
1139 $this->assertNotEmpty($entityName, $entityName);
1140 $fieldsGet = $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'get', 'options' => array('get_options' => 'all')));
1141 if ($entityName != 'Pledge') {
1142 $fields = $this->callAPISuccess($entityName, 'getfields', array('action' => 'create', 'options' => array('get_options' => 'all')));
1144 $fields = $fields['values'];
1145 $return = array_keys($fieldsGet['values']);
1146 $valuesNotToReturn = $this->getKnownUnworkablesUpdateSingle($entityName, 'break_return');
1147 // these can't be requested as return values
1148 $entityValuesThatDoNotWork = array_merge(
1149 $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_update'),
1150 $this->getKnownUnworkablesUpdateSingle($entityName, 'cant_return'),
1154 $return = array_diff($return, $valuesNotToReturn);
1155 $baoObj = new CRM_Core_DAO();
1156 $baoObj->createTestObject($baoString, array('currency' => 'USD'), 2, 0);
1158 $getEntities = $this->callAPISuccess($entityName, 'get', array(
1160 'return' => $return,
1162 'sort' => 'id DESC',
1167 // lets use first rather than assume only one exists
1168 $entity = $getEntities['values'][0];
1169 $entity2 = $getEntities['values'][1];
1170 $this->deletableTestObjects
[$baoString][] = $entity['id'];
1171 $this->deletableTestObjects
[$baoString][] = $entity2['id'];
1172 foreach ($fields as $field => $specs) {
1174 $fieldName = $field;
1175 if (!empty($specs['uniquename'])) {
1176 $fieldName = $specs['uniquename'];
1178 if ($field == 'currency' ||
$field == 'id' ||
$field == strtolower($entityName) . '_id'
1179 ||
in_array($field, $entityValuesThatDoNotWork)
1181 //@todo id & entity_id are correct but we should fix currency & frequency_day
1184 $this->assertArrayHasKey('type', $specs, "the _spec function for $entityName field $field does not specify the type");
1185 switch ($specs['type']) {
1186 case CRM_Utils_Type
::T_DATE
:
1187 $entity[$fieldName] = '2012-05-20';
1190 case CRM_Utils_Type
::T_TIMESTAMP
:
1192 $entity[$fieldName] = '2012-05-20 03:05:20';
1195 case CRM_Utils_Type
::T_STRING
:
1196 case CRM_Utils_Type
::T_BLOB
:
1197 case CRM_Utils_Type
::T_MEDIUMBLOB
:
1198 case CRM_Utils_Type
::T_TEXT
:
1199 case CRM_Utils_Type
::T_LONGTEXT
:
1200 case CRM_Utils_Type
::T_EMAIL
:
1201 if ($fieldName == 'form_values' && $entityName == 'SavedSearch') {
1202 // This is a hack for the SavedSearch API.
1203 // It expects form_values to be an array.
1204 // If you want to fix this, you should definitely read this forum
1206 // http://forum.civicrm.org/index.php/topic,33990.0.html
1207 // See also my question on the CiviCRM Stack Exchange:
1208 // https://civicrm.stackexchange.com/questions/3437
1209 $entity[$fieldName] = array('sort_name' => "SortName2");
1212 $entity[$fieldName] = substr('New String', 0, CRM_Utils_Array
::Value('maxlength', $specs, 100));
1213 if ($fieldName == 'email') {
1214 $entity[$fieldName] = strtolower($entity[$fieldName]);
1216 // typecast with array to satisfy changes made in CRM-13160
1217 if ($entityName == 'MembershipType' && in_array($fieldName, array(
1218 'relationship_type_id',
1219 'relationship_direction',
1222 $entity[$fieldName] = (array) $entity[$fieldName];
1227 case CRM_Utils_Type
::T_INT
:
1228 // probably created with a 1
1229 if ($fieldName == 'weight') {
1230 $entity[$fieldName] = 2;
1232 elseif (!empty($specs['FKClassName'])) {
1233 if ($specs['FKClassName'] == $baoString) {
1234 $entity[$fieldName] = (string) $entity2['id'];
1237 $uniqueName = CRM_Utils_Array
::value('uniqueName', $specs, $fieldName);
1238 if (!empty($entity[$fieldName])) {
1239 $resetFKTo = array($fieldName => $entity[$fieldName], $uniqueName => $entity[$fieldName]);
1241 $entity[$fieldName] = (string) empty($entity2[$field]) ? CRM_Utils_Array
::value($uniqueName, $entity2) : $entity2[$field];
1242 //todo - there isn't always something set here - & our checking on unset values is limited
1243 if (empty($entity[$field])) {
1244 unset($entity[$field]);
1249 $entity[$fieldName] = '6';
1253 case CRM_Utils_Type
::T_BOOLEAN
:
1254 // probably created with a 1
1255 $entity[$fieldName] = '0';
1258 case CRM_Utils_Type
::T_FLOAT
:
1259 case CRM_Utils_Type
::T_MONEY
:
1260 $entity[$field] = '22.75';
1263 case CRM_Utils_Type
::T_URL
:
1264 $entity[$field] = 'warm.beer.com';
1266 if (empty($specs['FKClassName']) && (!empty($specs['pseudoconstant']) ||
!empty($specs['options']))) {
1267 $options = CRM_Utils_Array
::value('options', $specs, array());
1269 //eg. pdf_format id doesn't ship with any
1270 if (isset($specs['pseudoconstant']['optionGroupName'])) {
1271 $optionValue = $this->callAPISuccess('option_value', 'create', array(
1272 'option_group_id' => $specs['pseudoconstant']['optionGroupName'],
1273 'label' => 'new option value',
1276 $optionValue = $optionValue['values'];
1277 $keyColumn = CRM_Utils_Array
::value('keyColumn', $specs['pseudoconstant'], 'value');
1278 $options[$optionValue[0][$keyColumn]] = 'new option value';
1281 $entity[$field] = array_rand($options);
1283 if (!empty($specs['FKClassName']) && !empty($specs['pseudoconstant'])) {
1284 // in the weird situation where a field has both an fk and pseudoconstant defined,
1285 // e.g. campaign_id field, need to flush caches.
1286 // FIXME: Why doesn't creating a campaign clear caches?
1287 civicrm_api3($entityName, 'getfields', array('cache_clear' => 1));
1289 $updateParams = array(
1290 'id' => $entity['id'],
1291 $field => isset($entity[$field]) ?
$entity[$field] : NULL,
1293 if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
1294 //api has special handling on these 2 fields for backward compatibility reasons
1295 $entity['contribution_type_id'] = $updateParams['financial_type_id'];
1298 if (!empty($specs['uniqueName'])) {
1299 $entity[$specs['uniqueName']] = $entity[$specs['name']];
1302 $update = $this->callAPISuccess($entityName, 'create', $updateParams);
1303 $checkParams = array(
1304 'id' => $entity['id'],
1306 'return' => $return,
1308 'sort' => 'id DESC',
1313 $checkEntity = $this->callAPISuccess($entityName, 'getsingle', $checkParams);
1315 $this->assertAPIArrayComparison($entity, $checkEntity, array(), "checking if $fieldName was correctly updated\n" . print_r(array(
1316 'update-params' => $updateParams,
1317 'update-result' => $update,
1318 'getsingle-params' => $checkParams,
1319 'getsingle-result' => $checkEntity,
1320 'expected entity' => $entity,
1323 //reset the foreign key fields because otherwise our cleanup routine fails & some other unexpected stuff can kick in
1324 $entity = array_merge($entity, $resetFKTo);
1325 $updateParams = array_merge($updateParams, $resetFKTo);
1326 $this->callAPISuccess($entityName, 'create', $updateParams);
1327 if (isset($updateParams['financial_type_id']) && in_array($entityName, array('Grant'))) {
1328 //api has special handling on these 2 fields for backward compatibility reasons
1329 $entity['contribution_type_id'] = $updateParams['financial_type_id'];
1336 /* ---- testing the _getFields ---- */
1338 /* ---- testing the _delete ---- */
1341 * @dataProvider toBeSkipped_delete
1342 entities that don't need a delete action
1345 public function testNotImplemented_delete($Entity) {
1346 $nonExistantID = 151416349;
1347 $result = civicrm_api($Entity, 'Delete', array('version' => 3, 'id' => $nonExistantID));
1348 $this->assertEquals(1, $result['is_error']);
1349 $this->assertContains(strtolower("API ($Entity, Delete) does not exist"), strtolower($result['error_message']));
1353 * @dataProvider entities
1354 * @expectedException PHPUnit_Framework_Error
1357 public function testWithoutParam_delete($Entity) {
1358 // should delete php complaining that a param is missing
1359 $result = civicrm_api($Entity, 'Delete');
1363 * @dataProvider entities_delete
1366 public function testEmptyParam_delete($Entity) {
1367 if (in_array($Entity, $this->toBeImplemented
['delete'])) {
1368 // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
1371 $result = civicrm_api($Entity, 'Delete', array());
1372 $this->assertEquals(1, $result['is_error']);
1373 $this->assertContains("Mandatory key(s) missing from params array", $result['error_message']);
1377 * @dataProvider entities_delete
1379 * @throws \PHPUnit_Framework_IncompleteTestError
1381 public function testInvalidID_delete($Entity) {
1382 // turn test off for now
1383 $this->markTestIncomplete("Entity [ $Entity ] cannot be mocked - no known DAO");
1385 if (in_array($Entity, $this->toBeImplemented
['delete'])) {
1386 // $this->markTestIncomplete("civicrm_api3_{$Entity}_delete to be implemented");
1389 $result = $this->callAPIFailure($Entity, 'Delete', array('id' => 999));
1393 * @dataProvider entities
1395 public function testDeleteWrongTypeParamTag_delete() {
1396 $result = civicrm_api("Tag", 'Delete', 'this is not a string');
1397 $this->assertEquals(1, $result['is_error']);
1398 $this->assertEquals("Input variable `params` is not an array", $result['error_message']);
1402 * Create two entities and make sure delete action only deletes one!
1404 * @dataProvider entities_delete
1406 * limitations include the problem with avoiding loops when creating test objects -
1407 * hence FKs only set by createTestObject when required. e.g parent_id on campaign is not being followed through
1408 * Currency - only seems to support US
1409 * @param $entityName
1410 * @throws \PHPUnit_Framework_IncompleteTestError
1412 public function testByID_delete($entityName) {
1413 // turn test off for noew
1414 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
1417 if (in_array($entityName, self
::toBeSkipped_automock(TRUE))) {
1418 // $this->markTestIncomplete("civicrm_api3_{$Entity}_create to be implemented");
1421 $startCount = $this->callAPISuccess($entityName, 'getcount', array());
1423 $baos = $this->getMockableBAOObjects($entityName, $createcount);
1424 list($baoObj1, $baoObj2) = $baos;
1426 // make sure exactly 2 exist
1427 $result = $this->callAPISuccess($entityName, 'getcount', array(),
1428 $createcount +
$startCount
1431 $this->callAPISuccess($entityName, 'delete', array('id' => $baoObj2->id
));
1432 //make sure 1 less exists now
1433 $result = $this->callAPISuccess($entityName, 'getcount', array(),
1434 ($createcount +
$startCount) - 1
1437 //make sure id #1 exists
1438 $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj1->id
),
1441 //make sure id #2 desn't exist
1442 $result = $this->callAPISuccess($entityName, 'getcount', array('id' => $baoObj2->id
),
1448 * Create two entities and make sure delete action only deletes one!
1450 * @dataProvider entities_getfields
1453 public function testGetfieldsHasTitle($entity) {
1454 $entities = $this->getEntitiesSupportingCustomFields();
1455 if (in_array($entity, $entities)) {
1456 $ids = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__
, $entity . 'Test.php');
1458 $actions = $this->callAPISuccess($entity, 'getactions', array());
1459 foreach ($actions['values'] as $action) {
1460 if (substr($action, -7) == '_create' ||
substr($action, -4) == '_get' ||
substr($action, -7) == '_delete') {
1461 //getactions can't distinguish between contribution_page.create & contribution_page.create
1464 $fields = $this->callAPISuccess($entity, 'getfields', array('action' => $action));
1465 if (!empty($ids) && in_array($action, array('create', 'get'))) {
1466 $this->assertArrayHasKey('custom_' . $ids['custom_field_id'], $fields['values']);
1469 foreach ($fields['values'] as $fieldName => $fieldSpec) {
1470 $this->assertArrayHasKey('title', $fieldSpec, "no title for $entity - $fieldName on action $action");
1471 $this->assertNotEmpty($fieldSpec['title'], "empty title for $entity - $fieldName");
1475 $this->customFieldDelete($ids['custom_field_id']);
1476 $this->customGroupDelete($ids['custom_group_id']);
1483 public function getEntitiesSupportingCustomFields() {
1484 $entities = self
::custom_data_entities_get();
1485 $returnEntities = array();
1486 foreach ($entities as $entityArray) {
1487 $returnEntities[] = $entityArray[0];
1489 return $returnEntities;
1493 * @param string $entityName
1498 private function getMockableBAOObjects($entityName, $count = 2) {
1499 $baoString = _civicrm_api3_get_BAO($entityName);
1500 if (empty($baoString)) {
1501 $this->markTestIncomplete("Entity [$entityName] cannot be mocked - no known DAO");
1506 while ($i < $count) {
1508 $baoObj = CRM_Core_DAO
::createTestObject($baoString, array('currency' => 'USD'));
1509 $this->assertTrue(is_int($baoObj->id
), 'check first id');
1510 $this->deletableTestObjects
[$baoString][] = $baoObj->id
;
1519 * Verify that HTML metacharacters provided as inputs appear consistently.
1522 * At time of writing, the encoding scheme requires (for example) that an
1523 * event title be partially-HTML-escaped before writing to DB. To provide
1524 * consistency, the API must perform extra encoding and decoding on some
1527 * In this example, the event 'title' is subject to encoding, but the
1528 * event 'description' is not.
1530 public function testEncodeDecodeConsistency() {
1532 $createResult = civicrm_api('Event', 'Create', array(
1534 'title' => 'CiviCRM <> TheRest',
1535 'description' => 'TheRest <> CiviCRM',
1536 'event_type_id' => 1,
1538 'start_date' => 20081021,
1540 $this->assertAPISuccess($createResult);
1541 $eventId = $createResult['id'];
1542 $this->assertEquals('CiviCRM <> TheRest', $createResult['values'][$eventId]['title']);
1543 $this->assertEquals('TheRest <> CiviCRM', $createResult['values'][$eventId]['description']);
1545 // Verify "get" handles decoding in result value
1546 $getByIdResult = civicrm_api('Event', 'Get', array(
1550 $this->assertAPISuccess($getByIdResult);
1551 $this->assertEquals('CiviCRM <> TheRest', $getByIdResult['values'][$eventId]['title']);
1552 $this->assertEquals('TheRest <> CiviCRM', $getByIdResult['values'][$eventId]['description']);
1554 // Verify "get" handles encoding in search value
1555 $getByTitleResult = civicrm_api('Event', 'Get', array(
1557 'title' => 'CiviCRM <> TheRest',
1559 $this->assertAPISuccess($getByTitleResult);
1560 $this->assertEquals('CiviCRM <> TheRest', $getByTitleResult['values'][$eventId]['title']);
1561 $this->assertEquals('TheRest <> CiviCRM', $getByTitleResult['values'][$eventId]['description']);
1563 // Verify that "getSingle" handles decoding
1564 $getSingleResult = $this->callAPISuccess('Event', 'GetSingle', array(
1568 $this->assertEquals('CiviCRM <> TheRest', $getSingleResult['title']);
1569 $this->assertEquals('TheRest <> CiviCRM', $getSingleResult['description']);
1571 // Verify that chaining handles decoding
1572 $chainResult = $this->callAPISuccess('Event', 'Get', array(
1574 'api.event.get' => array(),
1576 $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['title']);
1577 $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['description']);
1578 $this->assertEquals('CiviCRM <> TheRest', $chainResult['values'][$eventId]['api.event.get']['values'][0]['title']);
1579 $this->assertEquals('TheRest <> CiviCRM', $chainResult['values'][$eventId]['api.event.get']['values'][0]['description']);
1581 // Verify that "setvalue" handles encoding for updates
1582 $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
1586 'value' => 'setValueTitle: CiviCRM <> TheRest',
1588 $this->assertAPISuccess($setValueTitleResult);
1589 $this->assertEquals('setValueTitle: CiviCRM <> TheRest', $setValueTitleResult['values']['title']);
1590 $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
1593 'field' => 'description',
1594 'value' => 'setValueDescription: TheRest <> CiviCRM',
1596 //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
1597 $this->assertEquals('setValueDescription: TheRest <> CiviCRM', $setValueDescriptionResult['values']['description']);
1601 * Verify that write operations (create/update) use partial HTML-encoding
1603 * In this example, the event 'title' is subject to encoding, but the
1604 * event 'description' is not.
1606 public function testEncodeWrite() {
1608 $createResult = civicrm_api('Event', 'Create', array(
1610 'title' => 'createNew: CiviCRM <> TheRest',
1611 'description' => 'createNew: TheRest <> CiviCRM',
1612 'event_type_id' => 1,
1614 'start_date' => 20081021,
1616 $this->assertAPISuccess($createResult);
1617 $eventId = $createResult['id'];
1618 $this->assertDBQuery('createNew: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1619 1 => array($eventId, 'Integer'),
1621 $this->assertDBQuery('createNew: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1622 1 => array($eventId, 'Integer'),
1625 // Verify that "create" handles encoding for updates
1626 $createWithIdResult = civicrm_api('Event', 'Create', array(
1629 'title' => 'createWithId: CiviCRM <> TheRest',
1630 'description' => 'createWithId: TheRest <> CiviCRM',
1632 $this->assertAPISuccess($createWithIdResult);
1633 $this->assertDBQuery('createWithId: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1634 1 => array($eventId, 'Integer'),
1636 $this->assertDBQuery('createWithId: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1637 1 => array($eventId, 'Integer'),
1640 // Verify that "setvalue" handles encoding for updates
1641 $setValueTitleResult = civicrm_api('Event', 'setvalue', array(
1645 'value' => 'setValueTitle: CiviCRM <> TheRest',
1647 $this->assertAPISuccess($setValueTitleResult);
1648 $this->assertDBQuery('setValueTitle: CiviCRM <> TheRest', 'SELECT title FROM civicrm_event WHERE id = %1', array(
1649 1 => array($eventId, 'Integer'),
1651 $setValueDescriptionResult = civicrm_api('Event', 'setvalue', array(
1654 'field' => 'description',
1655 'value' => 'setValueDescription: TheRest <> CiviCRM',
1657 //$this->assertTrue((bool)$setValueDescriptionResult['is_error']); // not supported by setValue
1658 $this->assertAPISuccess($setValueDescriptionResult);
1659 $this->assertDBQuery('setValueDescription: TheRest <> CiviCRM', 'SELECT description FROM civicrm_event WHERE id = %1', array(
1660 1 => array($eventId, 'Integer'),