Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
7d61e75f TO |
4 | | Copyright CiviCRM LLC. All rights reserved. | |
5 | | | | |
6 | | This work is published under the GNU AGPLv3 license with some | | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
9 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 10 | */ |
6a488035 | 11 | |
e9479dcf EM |
12 | /** |
13 | * Class api_v3_PriceSetTest | |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
6a488035 TO |
16 | class api_v3_PriceSetTest extends CiviUnitTestCase { |
17 | protected $_apiversion = 3; | |
18 | protected $_params; | |
19 | protected $id = 0; | |
9099cab3 | 20 | protected $contactIds = []; |
6a488035 | 21 | protected $_entity = 'price_set'; |
b7c9bc4c | 22 | |
6a488035 | 23 | public $DBResetRequired = TRUE; |
92915c55 | 24 | |
fe482240 EM |
25 | /** |
26 | * Set up for class. | |
27 | */ | |
6a488035 TO |
28 | public function setUp() { |
29 | parent::setUp(); | |
9099cab3 | 30 | $this->_params = [ |
6a488035 TO |
31 | 'name' => 'default_goat_priceset', |
32 | 'title' => 'Goat accessories', | |
33 | 'is_active' => 1, | |
34 | 'help_pre' => "Please describe your goat in detail", | |
35 | 'help_post' => "thank you for your time", | |
36 | 'extends' => 2, | |
37 | 'financial_type_id' => 1, | |
38 | 'is_quick_config' => 1, | |
39 | 'is_reserved' => 1, | |
9099cab3 | 40 | ]; |
6a488035 TO |
41 | } |
42 | ||
e0c1764e | 43 | /** |
fe482240 | 44 | * Test create price set. |
e0c1764e | 45 | */ |
6a488035 | 46 | public function testCreatePriceSet() { |
ca985406 | 47 | $result = $this->callAPIAndDocument($this->_entity, 'create', $this->_params, __FUNCTION__, __FILE__); |
7aed59c0 EM |
48 | $this->assertEquals(1, $result['count']); |
49 | $this->assertNotNull($result['values'][$result['id']]['id']); | |
6a488035 TO |
50 | $this->getAndCheck($this->_params, $result['id'], $this->_entity); |
51 | } | |
52 | ||
a72f0e58 JV |
53 | /** |
54 | * Test for creating price sets used for both events and contributions. | |
55 | */ | |
56 | public function testCreatePriceSetForEventAndContribution() { | |
57 | // Create the price set | |
9099cab3 | 58 | $createParams = [ |
a72f0e58 JV |
59 | 'name' => 'some_price_set', |
60 | 'title' => 'Some Price Set', | |
61 | 'is_active' => 1, | |
62 | 'financial_type_id' => 1, | |
9099cab3 CW |
63 | 'extends' => [1, 2], |
64 | ]; | |
a72f0e58 JV |
65 | $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); |
66 | ||
67 | // Get priceset we just created. | |
9099cab3 | 68 | $result = $this->callAPISuccess($this->_entity, 'getSingle', [ |
a72f0e58 | 69 | 'id' => $createResult['id'], |
9099cab3 | 70 | ]); |
a72f0e58 JV |
71 | |
72 | // Count the number of items in 'extends'. | |
73 | $this->assertEquals(2, count($result['extends'])); | |
74 | } | |
75 | ||
e0c1764e | 76 | /** |
fe482240 | 77 | * Check that no name doesn't cause failure. |
e0c1764e EM |
78 | */ |
79 | public function testCreatePriceSetNoName() { | |
80 | $params = $this->_params; | |
81 | unset($params['name']); | |
fe482240 | 82 | $this->callAPISuccess($this->_entity, 'create', $params); |
e0c1764e EM |
83 | } |
84 | ||
85 | /** | |
e0c1764e | 86 | */ |
6a488035 | 87 | public function testGetBasicPriceSet() { |
9099cab3 | 88 | $getParams = [ |
6a488035 | 89 | 'name' => 'default_contribution_amount', |
9099cab3 | 90 | ]; |
ca985406 | 91 | $getResult = $this->callAPIAndDocument($this->_entity, 'get', $getParams, __FUNCTION__, __FILE__); |
7aed59c0 | 92 | $this->assertEquals(1, $getResult['count']); |
6a488035 TO |
93 | } |
94 | ||
95 | public function testEventPriceSet() { | |
9099cab3 | 96 | $event = $this->callAPISuccess('event', 'create', [ |
6a488035 TO |
97 | 'title' => 'Event with Price Set', |
98 | 'event_type_id' => 1, | |
99 | 'is_public' => 1, | |
100 | 'start_date' => 20151021, | |
101 | 'end_date' => 20151023, | |
102 | 'is_active' => 1, | |
9099cab3 CW |
103 | ]); |
104 | $createParams = [ | |
6a488035 TO |
105 | 'entity_table' => 'civicrm_event', |
106 | 'entity_id' => $event['id'], | |
107 | 'name' => 'event price', | |
108 | 'title' => 'event price', | |
109 | 'extends' => 1, | |
9099cab3 | 110 | ]; |
ca985406 | 111 | $createResult = $this->callAPIAndDocument($this->_entity, 'create', $createParams, __FUNCTION__, __FILE__); |
9099cab3 | 112 | $result = $this->callAPISuccess($this->_entity, 'get', [ |
ca985406 | 113 | 'id' => $createResult['id'], |
9099cab3 CW |
114 | ]); |
115 | $this->assertEquals(['civicrm_event' => [$event['id']]], $result['values'][$createResult['id']]['entity']); | |
6a488035 TO |
116 | } |
117 | ||
118 | public function testDeletePriceSet() { | |
9099cab3 | 119 | $startCount = $this->callAPISuccess($this->_entity, 'getcount', []); |
ca985406 | 120 | $createResult = $this->callAPISuccess($this->_entity, 'create', $this->_params); |
9099cab3 | 121 | $deleteParams = ['id' => $createResult['id']]; |
7aed59c0 | 122 | $this->callAPIAndDocument($this->_entity, 'delete', $deleteParams, __FUNCTION__, __FILE__); |
9099cab3 | 123 | $endCount = $this->callAPISuccess($this->_entity, 'getcount', []); |
7aed59c0 | 124 | $this->assertEquals($startCount, $endCount); |
6a488035 TO |
125 | } |
126 | ||
127 | public function testGetFieldsPriceSet() { | |
9099cab3 | 128 | $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']); |
6a488035 TO |
129 | $this->assertEquals(16, $result['values']['is_quick_config']['type']); |
130 | } | |
131 | ||
132 | public static function setUpBeforeClass() { | |
6c6e6187 | 133 | // put stuff here that should happen before all tests in this unit |
6a488035 TO |
134 | } |
135 | ||
9b873358 | 136 | public static function tearDownAfterClass() { |
9099cab3 | 137 | $tablesToTruncate = [ |
6a488035 TO |
138 | 'civicrm_contact', |
139 | 'civicrm_contribution', | |
9099cab3 | 140 | ]; |
6a488035 TO |
141 | $unitTest = new CiviUnitTestCase(); |
142 | $unitTest->quickCleanup($tablesToTruncate); | |
143 | } | |
96025800 | 144 | |
6a488035 | 145 | } |