Merge pull request #6140 from colemanw/CRM-16643
authorcolemanw <coleman@civicrm.org>
Sun, 5 Jul 2015 15:58:09 +0000 (11:58 -0400)
committercolemanw <coleman@civicrm.org>
Sun, 5 Jul 2015 15:58:09 +0000 (11:58 -0400)
CRM-16643 - Deprecate 'setvalue' api action & switch editable default to 'create'

CRM/Contribute/Form/AbstractEditPayment.php
CRM/Core/PseudoConstant.php
CRM/Member/Form/Membership.php
api/v3/Contribution.php
tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionTest.php

index f02446abe752046d440de2f0f469ab2fd861f2af..d8a99b1925a3aa6b90d151c8c438d868bf28dab9 100644 (file)
@@ -52,7 +52,7 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task {
 
   public $_bltID;
 
-  public $_fields;
+  public $_fields = array();
 
   /**
    * @var array current payment processor including a copy of the object in 'object' key
@@ -624,7 +624,6 @@ LEFT JOIN  civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co
 
         $this->assignBillingType();
 
-        $this->_fields = array();
         CRM_Core_Payment_Form::setPaymentFieldsByProcessor($this, $this->_paymentProcessor, FALSE, TRUE);
       }
     }
index c042f436c22f9ed840fdcb9d61285e080ab8d31b..352e9e89e465bb99c6bf8540c4deff4ce0c44752 100644 (file)
@@ -756,7 +756,7 @@ class CRM_Core_PseudoConstant {
    * @return array
    *   array reference of all State/Province abbreviations.
    */
-  public static function &stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
+  public static function stateProvinceAbbreviation($id = FALSE, $limit = TRUE) {
     if ($id > 1) {
       $query = "
 SELECT abbreviation
index 77758ddd7b0140e33a9ad0c41febe0f84d0a4fe5..fe5af580408a1c61b6a05cd0bf05e2c4b5a34945 100644 (file)
@@ -1296,7 +1296,6 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
         }
 
         $membershipTypeValues[$memType][$d] = CRM_Utils_Date::processDate($date);
-        //$params[$d] = CRM_Utils_Date::processDate( $date );
       }
     }
 
@@ -1464,11 +1463,12 @@ class CRM_Member_Form_Membership extends CRM_Member_Form {
       }
 
       // add all the additional payment params we need
-      $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($this->_params["billing_state_province_id-{$this->_bltID}"]);
-      $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($this->_params["billing_country_id-{$this->_bltID}"]);
+      $this->_params["state_province-{$this->_bltID}"] = $this->_params["billing_state_province-{$this->_bltID}"]
+        = CRM_Core_PseudoConstant::stateProvinceAbbreviation($formValues["billing_state_province_id-{$this->_bltID}"]);
+      $this->_params["country-{$this->_bltID}"] = $this->_params["billing_country-{$this->_bltID}"] = CRM_Core_PseudoConstant::countryIsoCode($formValues["billing_country_id-{$this->_bltID}"]);
 
-      $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($this->_params);
-      $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($this->_params);
+      $this->_params['year'] = CRM_Core_Payment_Form::getCreditCardExpirationYear($formValues);
+      $this->_params['month'] = CRM_Core_Payment_Form::getCreditCardExpirationMonth($formValues);
       $this->_params['ip_address'] = CRM_Utils_System::ipAddress();
       $this->_params['amount'] = $params['total_amount'];
       $this->_params['currencyID'] = $config->defaultCurrency;
index b19302837e08137739c1af25341a03fa272f1b6f..9d4f3d2825a8ea99c2b35ad268c28d112bd4d727 100644 (file)
@@ -256,6 +256,7 @@ function _civicrm_api3_contribution_get_spec(&$params) {
     'api.default' => 0,
     'type' => CRM_Utils_Type::T_BOOLEAN,
     'title' => 'Get Test Contributions?',
+    'api.aliases' => array('is_test'),
   );
   $params['financial_type_id']['api.aliases'] = array('contribution_type_id');
   $params['payment_instrument_id']['api.aliases'] = array('contribution_payment_instrument', 'payment_instrument');
index 91f875101c5d7e4fea8ac5560e536700424473ce..e0b30cb080bec55c8aa6f26b08d1456ac9e689fd 100644 (file)
@@ -91,7 +91,8 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     parent::setUp();
 
     $this->_individualId = $this->individualCreate();
-    $this->_paymentProcessorID = $this->processorCreate();
+    $processor = $this->processorCreate();
+    $this->_paymentProcessorID = $processor->id;
     // Insert test data.
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn,
@@ -114,6 +115,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
         'civicrm_relationship',
         'civicrm_membership_type',
         'civicrm_membership',
+        'civicrm_uf_match',
       )
     );
     $this->callAPISuccess('contact', 'delete', array('id' => 17, 'skip_undelete' => TRUE));
@@ -457,4 +459,88 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
     $this->callAPISuccessGetCount('Membership', array('contact_id' => $this->_individualId), 1);
   }
 
+  /**
+   * Test the submit function of the membership form.
+   */
+  public function testSubmitRecur() {
+    $form = $this->getForm();
+
+    $this->callAPISuccess('MembershipType', 'create', array(
+      'id' => 25,
+      'duration_unit' => 'month',
+      'duration_interval' => 1,
+      'auto_renew' => TRUE,
+    ));
+    $form->preProcess();
+    $this->createLoggedInUser();
+    $params = array(
+      'cid' => $this->_individualId,
+      'price_set_id' => 0,
+      'join_date' => date('m/d/Y', time()),
+      'start_date' => '',
+      'end_date' => '',
+      'campaign_id' => '',
+      // This format reflects the 1 being the organisation & the 25 being the type.
+      'membership_type_id' => array(1, 25),
+      'auto_renew' => '1',
+      'is_recur' => 1,
+      'max_related' => 0,
+      'num_terms' => '1',
+      'source' => '',
+      'total_amount' => '77.00',
+      'financial_type_id' => '2', //Member dues, see data.xml
+      'soft_credit_type_id' => 11,
+      'soft_credit_contact_id' => '',
+      'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
+      'receipt_text' => 'Thank you text',
+      'payment_processor_id' => $this->_paymentProcessorID,
+      'credit_card_number' => '4111111111111111',
+      'cvv2' => '123',
+      'credit_card_exp_date' => array(
+        'M' => '9',
+        'Y' => '2019', // TODO: Future proof
+      ),
+      'credit_card_type' => 'Visa',
+      'billing_first_name' => 'Test',
+      'billing_middlename' => 'Last',
+      'billing_street_address-5' => '10 Test St',
+      'billing_city-5' => 'Test',
+      'billing_state_province_id-5' => '1003',
+      'billing_postal_code-5' => '90210',
+      'billing_country_id-5' => '1228',
+    );
+    $form->_mode = 'test';
+
+    $form->submit($params);
+    $membership = $this->callAPISuccessGetSingle('Membership', array('contact_id' => $this->_individualId));
+    $this->callAPISuccessGetCount('ContributionRecur', array('contact_id' => $this->_individualId), 1);
+
+    $contribution = $this->callAPISuccess('Contribution', 'get', array(
+      'contact_id' => $this->_individualId,
+      'is_test' => TRUE,
+    ));
+    // Not currently passing.
+    //  $this->callAPISuccessGetCount('LineItem', array(
+    //  'entity_id' => $membership['id'],
+    //  'entity_table' => 'civicrm_membership',
+    //  'contribution_id' => $contribution['id'],
+    //), 1);
+    //
+  }
+
+  /**
+   * Get a membership form object.
+   *
+   * We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
+   *
+   * @return \CRM_Member_Form_Membership
+   */
+  protected function getForm() {
+    $form = new CRM_Member_Form_Membership();
+    $_SERVER['REQUEST_METHOD'] = 'GET';
+    $form->controller = new CRM_Core_Controller();
+    $form->_bltID = 5;
+    return $form;
+  }
+
 }
index 1b2c24f0bb0deaf38a32320a9c956c2e8fac2ba2..adde913aca06c5266462604fd65625b20480d0cd 100755 (executable)
@@ -1482,6 +1482,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
       'name' => 'Dummy',
       'payment_processor_type_id' => 10,
       'financial_account_id' => 12,
+      'is_test' => TRUE,
       'is_active' => 1,
       'user_name' => '',
       'url_site' => 'http://dummy.com',
index e34a99e15e1066e8bb74e4161fd8730233ba57ed..3aa0e3592147b222117cc5a026fae53583575d4c 100644 (file)
@@ -197,6 +197,14 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     ));
   }
 
+  /**
+   * Test that test contributions can be retrieved.
+   */
+  public function testGetTestContribution() {
+    $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('is_test' => 1)));
+    $this->callAPISuccessGetSingle('Contribution', array('is_test' => 1));
+  }
+
   /**
    * We need to ensure previous tested behaviour still works as part of the api contract.
    */
@@ -214,7 +222,7 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
       'source' => 'SSF',
       'contribution_status_id' => 1,
     );
-    $this->_contribution = $this->callAPISuccess('contribution', 'create', $p);
+    $this->_contribution = $this->callAPISuccess('Contribution', 'create', $p);
 
     $params = array(
       'contribution_id' => $this->_contribution['id'],