Swap out some additional assigns for tokens, improve tests
[civicrm-core.git] / tests / phpunit / CRM / Event / BAO / ParticipantStatusTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
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 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * Test class for CRM_Event_BAO_ParticipantStatus BAO
14 *
15 * @package CiviCRM
16 * @group headless
17 */
18 class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase {
19
20 /**
21 * create() and deleteParticipantStatusType() method
22 */
23 public function testCreateAndDelete() {
24
25 // create using required params
26 $params = [
27 'name' => 'testStatus',
28 'label' => 'testParticipant',
29 'class' => 'Positive',
30 'weight' => 13,
31 'visibility_id' => 1,
32 ];
33
34 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
35 // Checking for participant status type id in db.
36 $statusTypeId = $this->assertDBNotNull('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'id',
37 'id', 'Check DB for status type id'
38 );
39
40 CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($statusType->id);
41 // Checking for participant status type id after delete.
42 $statusTypeId = $this->assertDBNull('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'id',
43 'id', 'Check DB for status type id'
44 );
45 }
46
47 /**
48 * add() method (add and edit modes of participant status type)
49 */
50 public function testAddStatusType() {
51
52 $params = [
53 'name' => 'testStatus',
54 'label' => 'testParticipant',
55 'class' => 'Positive',
56 'is_active' => 1,
57 'is_counted' => 1,
58 'weight' => 13,
59 'visibility_id' => 1,
60 ];
61
62 // check for add participant status type
63 $statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
64 foreach ($params as $param => $value) {
65 $this->assertEquals($value, $statusType->$param);
66 }
67
68 $params = [
69 'id' => $statusType->id,
70 'name' => 'testStatus',
71 'label' => 'testAlterParticipant',
72 'class' => 'Pending',
73 'is_active' => 0,
74 'is_counted' => 0,
75 'weight' => 14,
76 'visibility_id' => 2,
77 ];
78
79 // check for add participant status type
80 $statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
81 foreach ($params as $param => $value) {
82 $this->assertEquals($value, $statusType->$param);
83 }
84 }
85
86 /**
87 * Retrieve() method of participant status type
88 */
89 public function testRetrieveStatusType() {
90
91 $params = [
92 'name' => 'testStatus',
93 'label' => 'testParticipant',
94 'class' => 'Positive',
95 'is_active' => 1,
96 'is_counted' => 1,
97 'weight' => 13,
98 'visibility_id' => 1,
99 ];
100
101 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
102
103 // retrieve status type
104 $retrieveParams = ['id' => $statusType->id];
105 $default = [];
106 $retrieveStatusType = CRM_Event_BAO_ParticipantStatusType::retrieve($retrieveParams, $default);
107
108 // check on retrieve values
109 foreach ($params as $param => $value) {
110 $this->assertEquals($value, $retrieveStatusType->$param);
111 }
112 }
113
114 /**
115 * SetIsActive() method of participant status type
116 */
117 public function testSetIsActiveStatusType() {
118
119 $params = [
120 'name' => 'testStatus',
121 'label' => 'testParticipant',
122 'class' => 'Positive',
123 'is_active' => 0,
124 'is_counted' => 1,
125 'weight' => 15,
126 'visibility_id' => 1,
127 ];
128
129 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
130 $isActive = 1;
131
132 // set participant status type active
133 CRM_Event_BAO_ParticipantStatusType::setIsActive($statusType->id, $isActive);
134
135 // compare expected value in db
136 $this->assertDBCompareValue('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'is_Active',
137 'id', $isActive, 'Check DB for is_Active value'
138 );
139 }
140
141 }