Skip to content

Commit

Permalink
Fix signature on BAO_Product::add to make ids optional
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire authored and eileenmcnaughton committed Jul 20, 2018
1 parent a74efcf commit ff93a82
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static function setIsActive($id, $is_active) {
*
* @return CRM_Contribute_DAO_Product
*/
public static function add(&$params, $ids) {
public static function add(&$params, $ids = []) {
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('premium', $ids));
if (empty($id)) {
$defaultParams = [
Expand Down
5 changes: 2 additions & 3 deletions CRM/Contribute/Form/ManagePremiums.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,14 @@ public function postProcess() {
$params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
}

$ids = array();
if ($this->_action & CRM_Core_Action::UPDATE) {
$ids['premium'] = $this->_id;
$params['id'] = $this->_id;
}

$this->_processImages($params);

// Save to database
$premium = CRM_Contribute_BAO_Product::add($params, $ids);
$premium = CRM_Contribute_BAO_Product::add($params);

CRM_Core_Session::setStatus(
ts("The Premium '%1' has been saved.", array(1 => $premium->name)),
Expand Down
6 changes: 1 addition & 5 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,6 @@ public function testsortName() {
public function testAddPremium() {
$contactId = $this->individualCreate();

$ids = array(
'premium' => NULL,
);

$params = array(
'name' => 'TEST Premium',
'sku' => 111,
Expand All @@ -376,7 +372,7 @@ public function testAddPremium() {
'min_contribution' => 100,
'is_active' => 1,
);
$premium = CRM_Contribute_BAO_Product::add($params, $ids);
$premium = CRM_Contribute_BAO_Product::add($params);

$this->assertEquals('TEST Premium', $premium->name, 'Check for premium name.');

Expand Down
12 changes: 4 additions & 8 deletions tests/phpunit/CRM/Contribute/BAO/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function setUp() {
* Check method add()
*/
public function testAdd() {
$ids = array();
$params = array(
'name' => 'Test Product',
'sku' => 'TP-10',
Expand All @@ -50,7 +49,7 @@ public function testAdd() {
'is_active' => 1,
);

$product = CRM_Contribute_BAO_Product::add($params, $ids);
$product = CRM_Contribute_BAO_Product::add($params);

$result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id,
'sku', 'id',
Expand All @@ -64,7 +63,6 @@ public function testAdd() {
* Check method retrieve( )
*/
public function testRetrieve() {
$ids = array();
$params = array(
'name' => 'Test Product',
'sku' => 'TP-10',
Expand All @@ -75,7 +73,7 @@ public function testRetrieve() {
'is_active' => 1,
);

$product = CRM_Contribute_BAO_Product::add($params, $ids);
$product = CRM_Contribute_BAO_Product::add($params);
$params = array('id' => $product->id);
$default = array();
$result = CRM_Contribute_BAO_Product::retrieve($params, $default);
Expand All @@ -86,7 +84,6 @@ public function testRetrieve() {
* Check method setIsActive( )
*/
public function testSetIsActive() {
$ids = array();
$params = array(
'name' => 'Test Product',
'sku' => 'TP-10',
Expand All @@ -97,7 +94,7 @@ public function testSetIsActive() {
'is_active' => 1,
);

$product = CRM_Contribute_BAO_Product::add($params, $ids);
$product = CRM_Contribute_BAO_Product::add($params);
CRM_Contribute_BAO_Product::setIsActive($product->id, 0);

$isActive = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id,
Expand All @@ -112,7 +109,6 @@ public function testSetIsActive() {
* Check method del( )
*/
public function testDel() {
$ids = array();
$params = array(
'name' => 'Test Product',
'sku' => 'TP-10',
Expand All @@ -123,7 +119,7 @@ public function testDel() {
'is_active' => 1,
);

$product = CRM_Contribute_BAO_Product::add($params, $ids);
$product = CRM_Contribute_BAO_Product::add($params);

CRM_Contribute_BAO_Product::del($product->id);

Expand Down

0 comments on commit ff93a82

Please sign in to comment.