Merge pull request #6289 from yashodha/CRM-16879
[civicrm-core.git] / tests / phpunit / api / v3 / PriceFieldValueTest.php
index 00ea139c18b31a69bf08544b74d1128c8e2e1a4a..7f99784e3f324f6e70ec50fef8fb839e3a543bdf 100644 (file)
@@ -1,10 +1,9 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
 | CiviCRM version 4.6                                                |
 +--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2014                                |
+| Copyright CiviCRM LLC (c) 2004-2015                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
@@ -24,7 +23,7 @@
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
-*/
+ */
 
 require_once 'CiviTest/CiviUnitTestCase.php';
 
@@ -40,13 +39,20 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
 
   public $DBResetRequired = TRUE;
 
+  /**
+   * @var int
+   */
+  protected $priceFieldID;
+
+  /**
+   * Setup function.
+   */
   public function setUp() {
     parent::setUp();
-    // put stuff here that should happen before all tests in this unit
-    $priceSetparams = array(
-      #     [domain_id] =>
+    // Put stuff here that should happen before all tests in this unit.
+    $priceSetParams = array(
       'name' => 'default_goat_priceset',
-      'title' => 'Goat accomodation',
+      'title' => 'Goat accommodation',
       'is_active' => 1,
       'help_pre' => "Where does your goat sleep",
       'help_post' => "thank you for your time",
@@ -56,10 +62,10 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_reserved' => 1,
     );
 
-    $price_set = $this->callAPISuccess('price_set', 'create', $priceSetparams);
+    $price_set = $this->callAPISuccess('price_set', 'create', $priceSetParams);
     $this->priceSetID = $price_set['id'];
 
-    $priceFieldparams = array(
+    $priceFieldParams = array(
       'price_set_id' => $this->priceSetID,
       'name' => 'grassvariety',
       'label' => 'Grass Variety',
@@ -67,18 +73,18 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_enter_qty' => 1,
       'is_active' => 1,
     );
-    $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldparams);
+    $priceField = $this->callAPISuccess('price_field', 'create', $priceFieldParams);
     $this->priceFieldID = $priceField['id'];
     $this->_params = array(
       'price_field_id' => $this->priceFieldID,
-      'name' => 'ryegrass',
+      'name' => 'rye grass',
       'label' => 'juicy and healthy',
       'amount' => 1,
-     );
+    );
 
     $membershipOrgId = $this->organizationCreate(NULL);
     $this->_membershipTypeID = $this->membershipTypeCreate(array('member_of_contact_id' => $membershipOrgId));
-    $priceSetparams1 = array(
+    $priceSetParams1 = array(
       'name' => 'priceset',
       'title' => 'Priceset with Multiple Terms',
       'is_active' => 1,
@@ -87,9 +93,9 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_quick_config' => 1,
       'is_reserved' => 1,
     );
-    $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetparams1);
+    $price_set1 = $this->callAPISuccess('price_set', 'create', $priceSetParams1);
     $this->priceSetID1 = $price_set1['id'];
-    $priceFieldparams1 = array(
+    $priceFieldParams1 = array(
       'price_set_id' => $this->priceSetID1,
       'name' => 'memtype',
       'label' => 'memtype',
@@ -97,25 +103,30 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'is_enter_qty' => 1,
       'is_active' => 1,
     );
-    $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldparams1);
+    $priceField1 = $this->callAPISuccess('price_field', 'create', $priceFieldParams1);
     $this->priceFieldID1 = $priceField1['id'];
   }
 
+  /**
+   * Tear down function.
+   *
+   * @throws \Exception
+   */
   public function tearDown() {
     $tablesToTruncate = array(
-        'civicrm_contact',
-        'civicrm_contribution',
+      'civicrm_contact',
+      'civicrm_contribution',
     );
     $this->quickCleanup($tablesToTruncate);
     $this->membershipTypeDelete(array('id' => $this->_membershipTypeID));
     $this->callAPISuccess('PriceField', 'delete', array(
-        'id' => $this->priceFieldID1,
+      'id' => $this->priceFieldID1,
     ));
     $this->callAPISuccess('PriceSet', 'delete', array(
       'id' => $this->priceSetID1,
     ));
     $this->callAPISuccess('PriceField', 'delete', array(
-        'id' => $this->priceFieldID,
+      'id' => $this->priceFieldID,
     ));
     $delete = $this->callAPISuccess('PriceSet', 'delete', array(
       'id' => $this->priceSetID,
@@ -169,12 +180,13 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'membership_num_terms' => 2,
       'is_active' => 1,
       'financial_type_id' => 2,
-     );
+    );
     $result = $this->callAPIAndDocument($this->_entity, 'create', $params, __FUNCTION__, __FILE__);
     $this->assertEquals($result['values'][$result['id']]['membership_num_terms'], 2);
     $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
     $this->callAPISuccess($this->_entity, 'delete', array('id' => $result['id']));
   }
+
   public function testGetPriceFieldValuewithMultipleTerms() {
     $params1 = array(
       'price_field_id' => $this->priceFieldID1,
@@ -185,7 +197,7 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'membership_num_terms' => 2,
       'is_active' => 1,
       'financial_type_id' => 2,
-     );
+    );
     $params2 = array(
       'price_field_id' => $this->priceFieldID1,
       'membership_type_id' => $this->_membershipTypeID,
@@ -195,7 +207,7 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
       'membership_num_terms' => 3,
       'is_active' => 1,
       'financial_type_id' => 2,
-     );
+    );
     $result1 = $this->callAPISuccess($this->_entity, 'create', $params1);
     $result2 = $this->callAPISuccess($this->_entity, 'create', $params2);
     $result = $this->callAPISuccess($this->_entity, 'get', array('price_field_id' => $this->priceFieldID1));
@@ -203,4 +215,5 @@ class api_v3_PriceFieldValueTest extends CiviUnitTestCase {
     $this->callAPISuccess($this->_entity, 'delete', array('id' => $result1['id']));
     $this->callAPISuccess($this->_entity, 'delete', array('id' => $result2['id']));
   }
+
 }