CRM-13120 - Reproduce 'null' problem with a core API
authorTim Otten <totten@civicrm.org>
Thu, 1 Aug 2013 22:41:01 +0000 (15:41 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 1 Aug 2013 22:45:15 +0000 (15:45 -0700)
----------------------------------------
* CRM-13120:
  http://issues.civicrm.org/jira/browse/CRM-13120

CRM/Contribute/BAO/ContributionPage.php
tests/phpunit/api/v3/APITest.php

index 51a9eacef399659f9a406dd8cba6ba25584685fb..d0b402970488487e18c0ce82638273f9744fb625 100644 (file)
@@ -49,7 +49,7 @@ class CRM_Contribute_BAO_ContributionPage extends CRM_Contribute_DAO_Contributio
    */
   public static function &create(&$params) {
     $financialTypeId = NULL;
-    if (CRM_Utils_Array::value('id', $params) && !CRM_Price_BAO_Set::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
+    if (CRM_Utils_Array::value('id', $params) && !CRM_Price_BAO_PriceSet::getFor('civicrm_contribution_page', $params['id'], NULL, 1)) {
       $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $params['id'], 'financial_type_id');
     }
     $dao = new CRM_Contribute_DAO_ContributionPage();
index 05eda06641f2c21498d43dcde479dab0d666860e..826bd4ecbc617c7a1abd938702c4fc3a0e31f689 100644 (file)
@@ -182,5 +182,37 @@ class api_v3_APITest extends CiviUnitTestCase {
     $this->fail('Exception was expected');
   }
 
+  public function testCreate_NoStringNullResult() {
+    // create an example contact
+    // $contact = CRM_Core_DAO::createTestObject('CRM_Contribute_DAO_ContributionPage')->toArray();
+    $result = $this->callAPISuccess('ContributionPage', 'create', array(
+      'title' => "Test Contribution Page",
+      'financial_type_id' => 1,
+      'currency' => 'USD',
+      'goal_amount' => 100,
+    ));
+    $contact = array_shift($result['values']);
+
+    $this->assertTrue(is_numeric($contact['id']));
+    $this->assertNotEmpty($contact['title']);
+    // preferred_mail_format preferred_communication_method preferred_language gender_id
+    // currency
+    $this->assertNotEmpty($contact['currency']);
+
+    // update the contact
+    $result = $this->callAPISuccess('ContributionPage', 'create', array(
+      'id' => $contact['id'],
+      'title' => 'New title',
+      'currency' => '',
+    ));
+
+    // check return format
+    $this->assertEquals(1, $result['count']);
+    foreach ($result['values'] as $resultValue) {
+      $this->assertEquals('New title', $resultValue['title']);
+      $this->assertEquals('', $resultValue['currency']); // BUG: $resultValue['location'] === 'null'
+    }
+  }
+
 }