Merge pull request #12020 from yashodha/inv_report
[civicrm-core.git] / tests / phpunit / CRM / Member / BAO / MembershipStatusTest.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 * Class CRM_Member_BAO_MembershipStatusTest
30 * @group headless
31 */
32 class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase {
33
34 public function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Check function add()
40 */
41 public function testAdd() {
42 $params = array(
43 'name' => 'pending',
44 'is_active' => 1,
45 );
46
47 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
48
49 $result = $this->assertDBNotNull('CRM_Member_BAO_MembershipStatus', $membershipStatus->id,
50 'name', 'id',
51 'Database check on updated membership status record.'
52 );
53 $this->assertEquals($result, 'pending', 'Verify membership status is_active.');
54 }
55
56 public function testRetrieve() {
57
58 $params = array(
59 'name' => 'testStatus',
60 'is_active' => 1,
61 );
62
63 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
64 $defaults = array();
65 $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
66 $this->assertEquals($result->name, 'testStatus', 'Verify membership status name.');
67 CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
68 }
69
70 public function testPseudoConstantflush() {
71 $params = array(
72 'name' => 'testStatus',
73 'is_active' => 1,
74 );
75 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
76 $defaults = array();
77 $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
78 $this->assertEquals($result->name, 'testStatus', 'Verify membership status name.');
79 $updateParams = array(
80 'id' => $membershipStatus->id,
81 'name' => 'testStatus',
82 'label' => 'Changed Status',
83 'is_active' => 1,
84 );
85 $membershipStatus2 = CRM_Member_BAO_MembershipStatus::add($updateParams);
86 $result = CRM_Member_PseudoConstant::membershipStatus($membershipStatus->id, NULL, 'label', FALSE, FALSE);
87 $this->assertEquals($result, 'Changed Status', 'Verify updated membership status label From PseudoConstant.');
88 CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
89 }
90
91 public function testSetIsActive() {
92
93 $params = array(
94 'name' => 'pending',
95 'is_active' => 1,
96 );
97
98 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
99 $result = CRM_Member_BAO_MembershipStatus::setIsActive($membershipStatus->id, 0);
100 $this->assertEquals($result, TRUE, 'Verify membership status record updation.');
101
102 $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipStatus', $membershipStatus->id,
103 'is_active', 'id',
104 'Database check on updated membership status record.'
105 );
106 $this->assertEquals($isActive, 0, 'Verify membership status is_active.');
107 }
108
109 public function testGetMembershipStatus() {
110 $params = array(
111 'name' => 'pending',
112 'is_active' => 1,
113 );
114
115 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
116 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatus($membershipStatus->id);
117 $this->assertEquals($result['name'], 'pending', 'Verify membership status name.');
118 }
119
120 public function testDel() {
121 $params = array(
122 'name' => 'testStatus',
123 'is_active' => 1,
124 );
125
126 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
127 CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
128 $defaults = array();
129 $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
130 $this->assertEquals(empty($result), TRUE, 'Verify membership status record deletion.');
131 }
132
133 public function testGetMembershipStatusByDate() {
134 $params = array(
135 'name' => 'Current',
136 'is_active' => 1,
137 'start_event' => 'start_date',
138 'end_event' => 'end_date',
139 );
140
141 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
142 $toDate = date('Ymd');
143
144 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($toDate, $toDate, $toDate, 'today', TRUE, NULL, $params);
145 $this->assertEquals($result['name'], 'Current', 'Verify membership status record.');
146 }
147
148 public function testgetMembershipStatusCurrent() {
149 $params = array(
150 'name' => 'Current',
151 'is_active' => 1,
152 'is_current_member' => 1,
153 );
154
155 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
156 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
157
158 $this->assertEquals(empty($result), FALSE, 'Verify membership status records is_current_member.');
159 }
160
161 }