Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-09-11-44-07
[civicrm-core.git] / tests / phpunit / CRM / Member / BAO / MembershipStatusTest.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 require_once 'CiviTest/CiviUnitTestCase.php';
30
31 /**
32 * Class CRM_Member_BAO_MembershipStatusTest
33 */
34 class CRM_Member_BAO_MembershipStatusTest extends CiviUnitTestCase {
35
36 public function setUp() {
37 parent::setUp();
38 }
39
40 /**
41 * Check function add()
42 */
43 public function testAdd() {
44 $params = array(
45 'name' => 'pending',
46 'is_active' => 1,
47 );
48
49 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
50
51 $result = $this->assertDBNotNull('CRM_Member_BAO_MembershipStatus', $membershipStatus->id,
52 'name', 'id',
53 'Database check on updated membership status record.'
54 );
55 $this->assertEquals($result, 'pending', 'Verify membership status is_active.');
56 }
57
58 public function testRetrieve() {
59
60 $params = array(
61 'name' => 'testStatus',
62 'is_active' => 1,
63 );
64
65 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
66 $defaults = array();
67 $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
68 $this->assertEquals($result->name, 'testStatus', 'Verify membership status name.');
69 CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
70 }
71
72 public function testSetIsActive() {
73
74 $params = array(
75 'name' => 'pending',
76 'is_active' => 1,
77 );
78
79 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
80 $result = CRM_Member_BAO_MembershipStatus::setIsActive($membershipStatus->id, 0);
81 $this->assertEquals($result, TRUE, 'Verify membership status record updation.');
82
83 $isActive = $this->assertDBNotNull('CRM_Member_BAO_MembershipStatus', $membershipStatus->id,
84 'is_active', 'id',
85 'Database check on updated membership status record.'
86 );
87 $this->assertEquals($isActive, 0, 'Verify membership status is_active.');
88 }
89
90 public function testGetMembershipStatus() {
91 $params = array(
92 'name' => 'pending',
93 'is_active' => 1,
94 );
95
96 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
97 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatus($membershipStatus->id);
98 $this->assertEquals($result['name'], 'pending', 'Verify membership status name.');
99 }
100
101 public function testDel() {
102 $params = array(
103 'name' => 'testStatus',
104 'is_active' => 1,
105 );
106
107 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
108 CRM_Member_BAO_MembershipStatus::del($membershipStatus->id);
109 $defaults = array();
110 $result = CRM_Member_BAO_MembershipStatus::retrieve($params, $defaults);
111 $this->assertEquals(empty($result), TRUE, 'Verify membership status record deletion.');
112 }
113
114 public function testGetMembershipStatusByDate() {
115 $params = array(
116 'name' => 'Current',
117 'is_active' => 1,
118 'start_event' => 'start_date',
119 'end_event' => 'end_date',
120 );
121
122 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
123 $toDate = date('Ymd');
124
125 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($toDate, $toDate, $toDate, 'today', TRUE, NULL, $params);
126 $this->assertEquals($result['name'], 'Current', 'Verify membership status record.');
127 }
128
129 public function testgetMembershipStatusCurrent() {
130 $params = array(
131 'name' => 'Current',
132 'is_active' => 1,
133 'is_current_member' => 1,
134 );
135
136 $membershipStatus = CRM_Member_BAO_MembershipStatus::add($params);
137 $result = CRM_Member_BAO_MembershipStatus::getMembershipStatusCurrent();
138
139 $this->assertEquals(empty($result), FALSE, 'Verify membership status records is_current_member.');
140 }
141
142 }