Skip to content

Commit

Permalink
CRM-15680 fix custom data on survey & campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 5, 2015
1 parent 5b37ca7 commit bf38705
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions api/v3/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @access public
*/
function civicrm_api3_campaign_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Campaign');
}

/**
Expand All @@ -74,7 +74,7 @@ function _civicrm_api3_campaign_create_spec(&$params) {
* {@getfields campaign_get}
*/
function civicrm_api3_campaign_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Campaign');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function civicrm_api3_case_get($params) {
}

//search by contacts
if ($contact = CRM_Utils_Array::value('contact_id', $params)) {
if (($contact = CRM_Utils_Array::value('contact_id', $params)) != FALSE) {
if (!is_numeric($contact)) {
throw new API_Exception('Invalid parameter: contact_id. Must provide a numeric value.');
}
Expand Down
3 changes: 1 addition & 2 deletions api/v3/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ function civicrm_api3_relationship_get($params) {
if(!empty($params['membership_type_id']) && empty($params['relationship_type_id'])) {
CRM_Contact_BAO_Relationship::membershipTypeToRelationshipTypes($params);
}
$relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE);
$relationships = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, FALSE, 'Relationship');
}
else {
$relationships = array();
$relationships = CRM_Contact_BAO_Relationship::getRelationship($params['contact_id'],
CRM_Utils_Array::value('status_id', $params),
0,
Expand Down
4 changes: 2 additions & 2 deletions api/v3/Survey.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @access public
*/
function civicrm_api3_survey_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Survey');
}

/**
Expand All @@ -72,7 +72,7 @@ function _civicrm_api3_survey_create_spec(&$params) {
* @access public
*/
function civicrm_api3_survey_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Survey');
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ protected function setUp() {
//flush component settings
CRM_Core_Component::getEnabledComponents(TRUE);


if ($this->_eNoticeCompliant) {
error_reporting(E_ALL);
}
Expand Down
23 changes: 9 additions & 14 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,15 @@ class api_v3_SyntaxConformanceTest extends CiviUnitTestCase {

/** Map custom group entities to civicrm components */
static $componentMap = array(
'Contact' => NULL,
'Individual' => NULL,
'Household' => NULL,
'Organization' => NULL,
'Contribution' => 'CiviContribute',
'Membership' => 'CiviMember',
'Participant' => 'CiviEvent',
'Group' => NULL,
'Relationship' => NULL,
'Event' => 'CiviEvent',
'Case' => 'CiviCase',
'Activity' => NULL,
'Pledge' => 'CiviPledge',
'Grant' => 'CiviGrant',
'Address' => NULL,
'Campaign' => 'CiviCampaign',
'Survey' => 'CiviCampaign',
);

/* they are two types of missing APIs:
Expand Down Expand Up @@ -183,17 +177,18 @@ public static function custom_data_entities_get() {
* @return array
*/
public static function custom_data_entities() {
$enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
$entities = CRM_Core_BAO_CustomQuery::$extendsMap;
$components = self::$componentMap;
$enabledComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
$customDataEntities = array();
$invalidEntities = array('Individual', 'Organization', 'Household');
$entitiesToFix = array('Case', 'Relationship');
$entitiesToFix = array('Relationship');
foreach ($entities as $entityName => $entity ) {
if(!in_array($entityName, $invalidEntities)
&& !in_array($entityName, $entitiesToFix)
&& (!empty($components[$entityName]) && in_array($components[$entityName], $enableComponents) || $components[$entityName] == NULL)) {
$customDataEntities[] = array($entityName );
&& !in_array($entityName, $entitiesToFix)) {
if(!empty(self::$componentMap[$entityName]) && empty($enabledComponents[self::$componentMap[$entityName]])) {
CRM_Core_BAO_ConfigSetting::enableComponent(self::$componentMap[$entityName]);
}
$customDataEntities[] = array($entityName);
}
}
return $customDataEntities;
Expand Down

1 comment on commit bf38705

@eileenmcnaughton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also able to fix the case API to work with custom data - but I couldn't make the test work due to enotices in the subscriber framework - one which CRM-15785 should fix but I gave up on this one. I'll try to make a record of the patch code somewhere as I don't really want to fix the bug if I can't get the test to work

  1. api_v3_SyntaxConformanceTest::testCustomDataGet with data set CRM-20780 - System::cmsRootPath() - Use the same override on all CMS's #6 ('Case')
    Failure in api call for Case create: Failed to parse CaseType XML: Line=1 Column=1 Code=4: Start tag expected, '<' not found
    #0 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/CRM/Case/XMLProcessor.php(69): CRM_Case_XMLRepository->retrieve('name_21')
    Fix Group Organization BAO not to error if the unique pairing up group_i... #1 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/CRM/Case/XMLProcessor/Process.php(626): CRM_Case_XMLProcessor->retrieve('name_21')
    Report api - temp internal PR for commentary #2 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/CCase/Events.php(92): CRM_Case_XMLProcessor_Process->getListeners('name_21')
    CRM-14159 API Add generic options['metadata'] = labels functionality #3 [internal function]: Civi\CCase\Events::delegateToXmlListeners(Object(Civi\CCase\Event\CaseChangeEvent))
    Crm 16555 4 #4 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatch

er.php(164): call_user_func(Array, Object(Civi\CCase\Event\CaseChangeEvent))
#5 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatch

er.php(53): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'hook_civicrm_ca...', Object(Civi\CCase\Event\CaseChangeEvent))
#6 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/CRM/Utils/Hook.php(1699): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('h

ook_civicrm_ca...', Object(Civi\CCase\Event\CaseChangeEvent))
#7 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/CCase/Events.php(79): CRM_Utils_Hook::caseChange(Object(Civi\CCase\Analyzer))
#8 [internal function]: Civi\CCase\Events::fireCaseChangeForRealz(1)
#9 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/Core/Transaction/Frame.php(185): call_user_func_array(Array, Array)
#10 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/Core/Transaction/Frame.php(138): Civi\Core\Transaction\Frame->invokeCallbacks(2)
#11 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/Core/Transaction/Manager.php(115): Civi\Core\Transaction\Frame->finish()
#12 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/CRM/Core/Transaction.php(140): Civi\Core\Transaction\Manager->dec()
#13 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/CRM/Core/Transaction.php(127): CRM_Core_Transaction->commit()
#14 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/API/Subscriber/TransactionSubscriber.php(157): CRM_Core_Transaction->__destruct()
#15 [internal function]: Civi\API\Subscriber\TransactionSubscriber->onApiRespond(Object(Civi\API\Event\RespondEvent))
#16 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatc

her.php(164): call_user_func(Array, Object(Civi\API\Event\RespondEvent))
civicrm#17 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/vendor/symfony/event-dispatcher/Symfony/Component/EventDispatcher/EventDispatc

her.php(53): Symfony\Component\EventDispatcher\EventDispatcher->doDispatch(Array, 'api.respond', Object(Civi\API\Event\RespondEvent))
civicrm#18 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/API/Kernel.php(221): Symfony\Component\EventDispatcher\EventDispatcher->dispatch('

api.respond', Object(Civi\API\Event\RespondEvent))
civicrm#19 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/Civi/API/Kernel.php(98): Civi\API\Kernel->respond(Object(Civi\API\Provider\MagicFunctio

nProvider), Array, Array)
civicrm#20 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/api/api.php(25): Civi\API\Kernel->run('Case', 'create', Array, NULL)
civicrm#21 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(850): civicrm_api('Case', 'create', Array)
civicrm#22 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(882): CiviUnitTestCase->civicrm_api('Case',

'create', Array)
civicrm#23 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/tests/phpunit/api/v3/SyntaxConformanceTest.php(596): CiviUnitTestCase->callAPISuccess('

Case', 'create', Array)
civicrm#24 [internal function]: api_v3_SyntaxConformanceTest->testCustomDataGet('Case')
civicrm#25 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(942): ReflectionMethod->invokeArgs(Object(api_v

3_SyntaxConformanceTest), Array)
civicrm#26 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/tests/phpunit/CiviTest/CiviUnitTestCase.php(182): PHPUnit_Framework_TestCase->runTest()
civicrm#27 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(804): CiviUnitTestCase->runTest()
civicrm#28 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestResult.php(649): PHPUnit_Framework_TestCase->runBare()
civicrm#29 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestCase.php(751): PHPUnit_Framework_TestResult->run(Object(

api_v3_SyntaxConformanceTest))
civicrm#30 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestSuite.php(772): PHPUnit_Framework_TestCase->run(Object(P

HPUnit_Framework_TestResult))
civicrm#31 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestSuite.php(745): PHPUnit_Framework_TestSuite->runTest(Obj

ect(api_v3_SyntaxConformanceTest), Object(PHPUnit_Framework_TestResult))
civicrm#32 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/Framework/TestSuite.php(705): PHPUnit_Framework_TestSuite->run(Object(

PHPUnit_Framework_TestResult), '/ustom/', Array, Array, false)
civicrm#33 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/TextUI/TestRunner.php(325): PHPUnit_Framework_TestSuite->run(Object(PH

PUnit_Framework_TestResult), '/ustom/', Array, Array, false)
civicrm#34 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/TextUI/Command.php(232): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUn

it_Framework_TestSuite), Array)
civicrm#35 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/packages/PHPUnit/TextUI/Command.php(139): PHPUnit_TextUI_Command->run(Array, true)
civicrm#36 /home/vagrant/civicrm-buildkit/build/drupal-demo/sites/all/modules/civicrm/tools/scripts/phpunit(80): PHPUnit_TextUI_Command::main()
civicrm#37 {main}

Failed asserting that 1 matches expected 0.

Please sign in to comment.