Adamw has uploaded a new change for review. https://gerrit.wikimedia.org/r/133884
Change subject: update bootstrap.inc to use new API ...................................................................... update bootstrap.inc to use new API Change-Id: Id26fc65183de3ee6c3985100fbaf2c2bedb8fab8 --- M sites/all/modules/wmf_civicrm/bootstrap.inc A sites/all/modules/wmf_civicrm/tests/phpunit/BootstrapTest.php 2 files changed, 45 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/84/133884/1 diff --git a/sites/all/modules/wmf_civicrm/bootstrap.inc b/sites/all/modules/wmf_civicrm/bootstrap.inc index 9802178..e28fe4a 100644 --- a/sites/all/modules/wmf_civicrm/bootstrap.inc +++ b/sites/all/modules/wmf_civicrm/bootstrap.inc @@ -31,23 +31,27 @@ function wmf_civicrm_create_contribution_types($contribution_types) { + $api = wmf_civicrm_bootstrap_civi(); + foreach ($contribution_types as $type) { - $contribution_type_id = CRM_Utils_Array::key( - $type, - CRM_Contribute_PseudoConstant::contributionType() - ); - - if (!$contribution_type_id) + $success = $api->FinancialType->get( array( + 'name' => $type, + ) ); + if ( !$success ) { + throw new Exception( "Failed to use the Civi API: {$api->errorMsg()}" ); + } + if ( !$api->values ) { - $params = array( + $success = $api->FinancialType->create( array( + 'name' => $type, 'is_active' => 1, 'is_deductible' => 1, 'accounting_code' => strtoupper($type), - 'name' => $type, - ); - $ids = array(); - CRM_Contribute_BAO_ContributionType::add($params, $ids); + ) ); + if ( !$success ) { + throw new Exception( "Failed to create new contribution type: {$api->errorMsg()}" ); + } } } } diff --git a/sites/all/modules/wmf_civicrm/tests/phpunit/BootstrapTest.php b/sites/all/modules/wmf_civicrm/tests/phpunit/BootstrapTest.php new file mode 100644 index 0000000..61a7052 --- /dev/null +++ b/sites/all/modules/wmf_civicrm/tests/phpunit/BootstrapTest.php @@ -0,0 +1,30 @@ +<?php + +class BootstrapTest extends BaseWmfDrupalPhpUnitTestCase { + public static function getInfo() { + return array( + 'name' => 'Wmf CiviCRM bootstrap tests', + 'group' => 'Pipeline', + 'description' => 'Test utilities used during installation and migration', + ); + } + + public function setUp() { + parent::setUp(); + + civicrm_initialize(); + require_once __DIR__ . '/../../bootstrap.inc'; + } + + public function testCreateContributionTypes() { + $types = array( + 'Test type' . mt_rand(), + 'Test type' . mt_rand(), + ); + + wmf_civicrm_create_contribution_types( $types ); + + $this->assertNotNull( wmf_civicrm_get_civi_id( 'contribution_type_id', $types[0] ) ); + $this->assertNotNull( wmf_civicrm_get_civi_id( 'contribution_type_id', $types[1] ) ); + } +} -- To view, visit https://gerrit.wikimedia.org/r/133884 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id26fc65183de3ee6c3985100fbaf2c2bedb8fab8 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: civi-4.4 Gerrit-Owner: Adamw <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits