Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | |
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
06a1bc01 | 5 | | CiviCRM version 4.5 | |
b6708aeb | 6 | +--------------------------------------------------------------------+ |
06a1bc01 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
b6708aeb | 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 | |
29 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
30 | class 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'; | |
b7c9bc4c | 36 | |
6a488035 TO |
37 | public $DBResetRequired = TRUE; |
38 | public function setUp() { | |
39 | parent::setUp(); | |
40 | $this->_params = array( | |
6a488035 TO |
41 | # [domain_id] => |
42 | 'name' => 'default_goat_priceset', | |
43 | 'title' => 'Goat accessories', | |
44 | 'is_active' => 1, | |
45 | 'help_pre' => "Please describe your goat in detail", | |
46 | 'help_post' => "thank you for your time", | |
47 | 'extends' => 2, | |
48 | 'financial_type_id' => 1, | |
49 | 'is_quick_config' => 1, | |
50 | 'is_reserved' => 1, | |
51 | ); | |
52 | } | |
53 | ||
54 | function tearDown() { | |
55 | } | |
56 | ||
57 | public function testCreatePriceSet() { | |
ca985406 | 58 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
6a488035 TO |
59 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
60 | $this->assertNotNull($result['values'][$result['id']]['id'], 'In line ' . __LINE__); | |
61 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); | |
62 | } | |
63 | ||
64 | public function testGetBasicPriceSet() { | |
65 | $getParams = array( | |
6a488035 TO |
66 | 'name' => 'default_contribution_amount', |
67 | ); | |
ca985406 | 68 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
6a488035 TO |
69 | $this->assertEquals(1, $getResult['count'], 'In line ' . __LINE__); |
70 | } | |
71 | ||
72 | public function testEventPriceSet() { | |
ca985406 | 73 | $event = $this->callAPISuccess('event', 'create', array( |
6a488035 TO |
74 | 'title' => 'Event with Price Set', |
75 | 'event_type_id' => 1, | |
76 | 'is_public' => 1, | |
77 | 'start_date' => 20151021, | |
78 | 'end_date' => 20151023, | |
79 | 'is_active' => 1, | |
80 | )); | |
6a488035 | 81 | $createParams = array( |
6a488035 TO |
82 | 'entity_table' => 'civicrm_event', |
83 | 'entity_id' => $event['id'], | |
84 | 'name' => 'event price', | |
85 | 'title' => 'event price', | |
86 | 'extends' => 1, | |
87 | ); | |
ca985406 | 88 | $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); |
89 | $result = $this->callAPISuccess($this->_entity, 'get', array( | |
90 | 'id' => $createResult['id'], | |
6a488035 | 91 | )); |
ca985406 | 92 | $this->assertEquals(array('civicrm_event' => array($event['id'])), $result['values'][$createResult['id']]['entity'], 'In line ' . __LINE__); |
6a488035 TO |
93 | } |
94 | ||
95 | public function testDeletePriceSet() { | |
ca985406 | 96 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', array()); |
97 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); | |
98 | $deleteParams = array('id' => $createResult['id']); | |
99 | $deleteResult = $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); | |
100 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', array()); | |
6a488035 TO |
101 | $this->assertEquals($startCount, $endCount, 'In line ' . __LINE__); |
102 | } | |
103 | ||
104 | public function testGetFieldsPriceSet() { | |
ca985406 | 105 | $result = $this->callAPISuccess($this->_entity, 'getfields', array('action' => 'create')); |
6a488035 TO |
106 | $this->assertEquals(16, $result['values']['is_quick_config']['type']); |
107 | } | |
108 | ||
109 | public static function setUpBeforeClass() { | |
110 | // put stuff here that should happen before all tests in this unit | |
111 | } | |
112 | ||
113 | public static function tearDownAfterClass(){ | |
114 | $tablesToTruncate = array( | |
115 | 'civicrm_contact', | |
116 | 'civicrm_contribution', | |
117 | ); | |
118 | $unitTest = new CiviUnitTestCase(); | |
119 | $unitTest->quickCleanup($tablesToTruncate); | |
120 | } | |
121 | } | |
122 |