CRM-13072 upgrade Paritipant Payment test classes to pass
[civicrm-core.git] / tests / phpunit / api / v3 / PriceSetTest.php
CommitLineData
6a488035 1<?php
b6708aeb 2
3/*
4 +--------------------------------------------------------------------+
5| CiviCRM version 4.3 |
6+--------------------------------------------------------------------+
7| Copyright CiviCRM LLC (c) 2004-2013 |
8+--------------------------------------------------------------------+
9| This file is a part of CiviCRM. |
10| |
11| CiviCRM is free software; you can copy, modify, and distribute it |
12| under the terms of the GNU Affero General Public License |
13| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14| |
15| CiviCRM is distributed in the hope that it will be useful, but |
16| WITHOUT ANY WARRANTY; without even the implied warranty of |
17| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18| See the GNU Affero General Public License for more details. |
19| |
20| You should have received a copy of the GNU Affero General Public |
21| License and the CiviCRM Licensing Exception along |
22| with this program; if not, contact CiviCRM LLC |
23| at info[AT]civicrm[DOT]org. If you have questions about the |
24| GNU Affero General Public License or the licensing of CiviCRM, |
25| see the CiviCRM license FAQ at http://civicrm.org/licensing |
26+--------------------------------------------------------------------+
27*/
6a488035
TO
28
29require_once 'CiviTest/CiviUnitTestCase.php';
30class api_v3_PriceSetTest extends CiviUnitTestCase {
31 protected $_apiversion = 3;
32 protected $_params;
33 protected $id = 0;
34 protected $contactIds = array();
35 protected $_entity = 'price_set';
36 public $_eNoticeCompliant = TRUE;
37 public $DBResetRequired = TRUE;
38 public function setUp() {
39 parent::setUp();
40 $this->_params = array(
41 'version' => $this->_apiversion,
42# [domain_id] =>
43 'name' => 'default_goat_priceset',
44 'title' => 'Goat accessories',
45 'is_active' => 1,
46 'help_pre' => "Please describe your goat in detail",
47 'help_post' => "thank you for your time",
48 'extends' => 2,
49 'financial_type_id' => 1,
50 'is_quick_config' => 1,
51 'is_reserved' => 1,
52 );
53 }
54
55 function tearDown() {
56 }
57
58 public function testCreatePriceSet() {
59 $result = civicrm_api($this->_entity, 'create', $this->_params);
60 $this->id = $result['id'];
61 $this->documentMe($this->_params, $result, __FUNCTION__, __FILE__);
62 $this->assertAPISuccess($result, 'In line ' . __LINE__);
63 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
64 $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__);
65 $this->getAndCheck($this->_params, $result['id'], $this->_entity);
66 }
67
68 public function testGetBasicPriceSet() {
69 $getParams = array(
70 'version' => $this->_apiversion,
71 'name' => 'default_contribution_amount',
72 );
73 $getResult = civicrm_api($this->_entity, 'get', $getParams);
74 $this->documentMe($getParams, $getResult, __FUNCTION__, __FILE__);
75 $this->assertAPISuccess($getResult, 'In line ' . __LINE__);
76 $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__);
77 }
78
79 public function testEventPriceSet() {
80 $event = civicrm_api('event', 'create', array(
81 'version' => $this->_apiversion,
82 'title' => 'Event with Price Set',
83 'event_type_id' => 1,
84 'is_public' => 1,
85 'start_date' => 20151021,
86 'end_date' => 20151023,
87 'is_active' => 1,
88 ));
89 $this->assertAPISuccess($event);
90 $createParams = array(
91 'version' => $this->_apiversion,
92 'entity_table' => 'civicrm_event',
93 'entity_id' => $event['id'],
94 'name' => 'event price',
95 'title' => 'event price',
96 'extends' => 1,
97 );
98 $createResult = civicrm_api($this->_entity, 'create', $createParams);
99 $this->documentMe($createParams, $createResult, __FUNCTION__, __FILE__);
100 $this->assertAPISuccess($createResult, 'In line ' . __LINE__);
101 $id = $createResult['id'];
102 $result = civicrm_api($this->_entity, 'get', array(
103 'version' => $this->_apiversion,
104 'id' => $id,
105 ));
106 $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$id]['entity'], 'In line ' . __LINE__);
107 }
108
109 public function testDeletePriceSet() {
110 $startCount = civicrm_api($this->_entity, 'getcount', array(
111 'version' => $this->_apiversion,
112 ));
113 $createResult = civicrm_api($this->_entity, 'create', $this->_params);
114 $deleteParams = array('version' => $this->_apiversion, 'id' => $createResult['id']);
115 $deleteResult = civicrm_api($this->_entity, 'delete', $deleteParams);
116 $this->documentMe($deleteParams, $deleteResult, __FUNCTION__, __FILE__);
117 $this->assertAPISuccess($deleteResult, 'In line ' . __LINE__);
118 $endCount = civicrm_api($this->_entity, 'getcount', array(
119 'version' => $this->_apiversion,
120 ));
121 $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__);
122 }
123
124 public function testGetFieldsPriceSet() {
125 $result = civicrm_api($this->_entity, 'getfields', array('version' => $this->_apiversion, 'action' => 'create'));
126 $this->assertAPISuccess($result, 'In line ' . __LINE__);
127 $this->assertEquals(16, $result['values']['is_quick_config']['type']);
128 }
129
130 public static function setUpBeforeClass() {
131 // put stuff here that should happen before all tests in this unit
132 }
133
134 public static function tearDownAfterClass(){
135 $tablesToTruncate = array(
136 'civicrm_contact',
137 'civicrm_contribution',
138 );
139 $unitTest = new CiviUnitTestCase();
140 $unitTest->quickCleanup($tablesToTruncate);
141 }
142}
143