Merge pull request #12969 from christianwach/issue-460
[civicrm-core.git] / tests / phpunit / CRM / Event / BAO / ParticipantStatusTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 * Test class for CRM_Event_BAO_ParticipantStatus BAO
30 *
31 * @package CiviCRM
32 * @group headless
33 */
34 class CRM_Event_BAO_ParticipantStatusTest extends CiviUnitTestCase {
35
36 /**
37 * Sets up the fixture, for example, opens a network connection.
38 * This method is called before a test is executed.
39 */
40 protected function setUp() {
41 parent::setUp();
42 }
43
44 /**
45 * Tears down the fixture, for example, closes a network connection.
46 * This method is called after a test is executed.
47 */
48 protected function tearDown() {
49 }
50
51 /**
52 * create() and deleteParticipantStatusType() method
53 */
54 public function testCreateAndDelete() {
55
56 // create using required params
57 $params = array(
58 'name' => 'testStatus',
59 'label' => 'testParticipant',
60 'class' => 'Positive',
61 'weight' => 13,
62 'visibility_id' => 1,
63 );
64
65 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
66 // Checking for participant status type id in db.
67 $statusTypeId = $this->assertDBNotNull('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'id',
68 'id', 'Check DB for status type id'
69 );
70
71 CRM_Event_BAO_ParticipantStatusType::deleteParticipantStatusType($statusType->id);
72 // Checking for participant status type id after delete.
73 $statusTypeId = $this->assertDBNull('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'id',
74 'id', 'Check DB for status type id'
75 );
76 }
77
78 /**
79 * add() method (add and edit modes of participant status type)
80 */
81 public function testAddStatusType() {
82
83 $params = array(
84 'name' => 'testStatus',
85 'label' => 'testParticipant',
86 'class' => 'Positive',
87 'is_active' => 1,
88 'is_counted' => 1,
89 'weight' => 13,
90 'visibility_id' => 1,
91 );
92
93 // check for add participant status type
94 $statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
95 foreach ($params as $param => $value) {
96 $this->assertEquals($value, $statusType->$param);
97 }
98
99 $params = array(
100 'id' => $statusType->id,
101 'name' => 'testStatus',
102 'label' => 'testAlterParticipant',
103 'class' => 'Pending',
104 'is_active' => 0,
105 'is_counted' => 0,
106 'weight' => 14,
107 'visibility_id' => 2,
108 );
109
110 // check for add participant status type
111 $statusType = CRM_Event_BAO_ParticipantStatusType::add($params);
112 foreach ($params as $param => $value) {
113 $this->assertEquals($value, $statusType->$param);
114 }
115 }
116
117 /**
118 * Retrieve() method of participant status type
119 */
120 public function testRetrieveStatusType() {
121
122 $params = array(
123 'name' => 'testStatus',
124 'label' => 'testParticipant',
125 'class' => 'Positive',
126 'is_active' => 1,
127 'is_counted' => 1,
128 'weight' => 13,
129 'visibility_id' => 1,
130 );
131
132 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
133
134 // retrieve status type
135 $retrieveParams = array('id' => $statusType->id);
136 $default = array();
137 $retrieveStatusType = CRM_Event_BAO_ParticipantStatusType::retrieve($retrieveParams, $default);
138
139 // check on retrieve values
140 foreach ($params as $param => $value) {
141 $this->assertEquals($value, $retrieveStatusType->$param);
142 }
143 }
144
145 /**
146 * SetIsActive() method of participant status type
147 */
148 public function testSetIsActiveStatusType() {
149
150 $params = array(
151 'name' => 'testStatus',
152 'label' => 'testParticipant',
153 'class' => 'Positive',
154 'is_active' => 0,
155 'is_counted' => 1,
156 'weight' => 15,
157 'visibility_id' => 1,
158 );
159
160 $statusType = CRM_Event_BAO_ParticipantStatusType::create($params);
161 $isActive = 1;
162
163 // set participant status type active
164 CRM_Event_BAO_ParticipantStatusType::setIsActive($statusType->id, $isActive);
165
166 // compare expected value in db
167 $this->assertDBCompareValue('CRM_Event_DAO_ParticipantStatusType', $statusType->id, 'is_Active',
168 'id', $isActive, 'Check DB for is_Active value'
169 );
170 }
171
172 }