CRM-15855 - Allow mailings to be saved (but not sent) without name+subject.
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
index 99e7a1315a67a547069bbbfcee180b46c3a00821..804235483c7a566070317569eae3866083f4e2af 100644 (file)
@@ -1,8 +1,7 @@
 <?php
-
 /*
  +--------------------------------------------------------------------+
-| CiviCRM version 4.5                                                |
+| CiviCRM version 4.6                                                |
 +--------------------------------------------------------------------+
 | Copyright CiviCRM LLC (c) 2004-2014                                |
 +--------------------------------------------------------------------+
@@ -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';
 
@@ -39,10 +38,11 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
   protected $_entity = 'price_set';
 
   public $DBResetRequired = TRUE;
+
   public function setUp() {
     parent::setUp();
     $this->_params = array(
-#     [domain_id] =>
+      #     [domain_id] =>
       'name' => 'default_goat_priceset',
       'title' => 'Goat accessories',
       'is_active' => 1,
@@ -55,22 +55,58 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
     );
   }
 
-  function tearDown() {
+  public function tearDown() {
   }
 
+  /**
+   */
   public function testCreatePriceSet() {
     $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__);
-    $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
-    $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $result['count']);
+    $this->assertNotNull($result['values'][$result['id']]['id']);
     $this->getAndCheck($this->_params, $result['id'], $this->_entity);
   }
 
+  /**
+   * Test for creating price sets used for both events and contributions.
+   */
+  public function testCreatePriceSetForEventAndContribution() {
+    // Create the price set
+    $createParams = array(
+      'name' => 'some_price_set',
+      'title' => 'Some Price Set',
+      'is_active' => 1,
+      'financial_type_id' => 1,
+      'extends' => array(1, 2),
+    );
+    $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__);
+
+    // Get priceset we just created.
+    $result = $this->callAPISuccess($this->_entity, 'getSingle', array(
+      'id' => $createResult['id'],
+    ));
+
+    // Count the number of items in 'extends'.
+    $this->assertEquals(2, count($result['extends']));
+  }
+
+  /**
+   * Check that no name doesn't cause failure
+   */
+  public function testCreatePriceSetNoName() {
+    $params = $this->_params;
+    unset($params['name']);
+    $result = $this->callAPISuccess($this->_entity, 'create', $params);
+  }
+
+  /**
+   */
   public function testGetBasicPriceSet() {
     $getParams = array(
       'name' => 'default_contribution_amount',
     );
     $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__);
-    $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
+    $this->assertEquals(1, $getResult['count']);
   }
 
   public function testEventPriceSet() {
@@ -93,16 +129,16 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
     $result = $this->callAPISuccess($this->_entity, 'get', array(
       'id' => $createResult['id'],
     ));
-    $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity'], 'In line ' . __LINE__);
+    $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity']);
   }
 
   public function testDeletePriceSet() {
     $startCount = $this->callAPISuccess($this->_entity, 'getcount', array());
     $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params);
     $deleteParams = array('id' => $createResult['id']);
-    $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
+    $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__);
     $endCount = $this->callAPISuccess($this->_entity, 'getcount', array());
-    $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__);
+    $this->assertEquals($startCount, $endCount);
   }
 
   public function testGetFieldsPriceSet() {
@@ -111,10 +147,10 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
   }
 
   public static function setUpBeforeClass() {
-      // put stuff here that should happen before all tests in this unit
+    // put stuff here that should happen before all tests in this unit
   }
 
-  public static function tearDownAfterClass(){
+  public static function tearDownAfterClass() {
     $tablesToTruncate = array(
       'civicrm_contact',
       'civicrm_contribution',
@@ -122,5 +158,5 @@ class api_v3_PriceSetTest extends CiviUnitTestCase {
     $unitTest = new CiviUnitTestCase();
     $unitTest->quickCleanup($tablesToTruncate);
   }
-}
 
+}