Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
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 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
e9479dcf EM |
29 | |
30 | /** | |
31 | * Class CRM_Contribute_BAO_ManagePremiumsTest | |
32 | */ | |
6a488035 | 33 | class CRM_Contribute_BAO_ManagePremiumsTest extends CiviUnitTestCase { |
6a488035 | 34 | |
00be9182 | 35 | public function setUp() { |
6a488035 TO |
36 | parent::setUp(); |
37 | } | |
38 | ||
39 | /** | |
100fef9d | 40 | * Check method add() |
6a488035 | 41 | */ |
00be9182 | 42 | public function testAdd() { |
6a488035 TO |
43 | $ids = array(); |
44 | $params = array( | |
45 | 'name' => 'Test Product', | |
46 | 'sku' => 'TP-10', | |
47 | 'imageOption' => 'noImage', | |
48 | 'price' => 12, | |
49 | 'cost' => 5, | |
50 | 'min_contribution' => 5, | |
51 | 'is_active' => 1, | |
52 | ); | |
53 | ||
54 | $product = CRM_Contribute_BAO_ManagePremiums::add($params, $ids); | |
55 | ||
56 | $result = $this->assertDBNotNull('CRM_Contribute_BAO_ManagePremiums', $product->id, | |
57 | 'sku', 'id', | |
58 | 'Database check on updated product record.' | |
59 | ); | |
60 | ||
61 | $this->assertEquals($result, 'TP-10', 'Verify products sku.'); | |
62 | } | |
63 | ||
64 | /** | |
100fef9d | 65 | * Check method retrieve( ) |
6a488035 | 66 | */ |
00be9182 | 67 | public function testRetrieve() { |
6a488035 TO |
68 | $ids = array(); |
69 | $params = array( | |
70 | 'name' => 'Test Product', | |
71 | 'sku' => 'TP-10', | |
72 | 'imageOption' => 'noImage', | |
73 | 'price' => 12, | |
74 | 'cost' => 5, | |
75 | 'min_contribution' => 5, | |
76 | 'is_active' => 1, | |
77 | ); | |
78 | ||
79 | $product = CRM_Contribute_BAO_ManagePremiums::add($params, $ids); | |
80 | $params = array('id' => $product->id); | |
81 | $default = array(); | |
82 | $result = CRM_Contribute_BAO_ManagePremiums::retrieve($params, $default); | |
83 | $this->assertEquals(empty($result), FALSE, 'Verify products record.'); | |
84 | } | |
85 | ||
86 | /** | |
100fef9d | 87 | * Check method setIsActive( ) |
6a488035 | 88 | */ |
00be9182 | 89 | public function testSetIsActive() { |
6a488035 TO |
90 | $ids = array(); |
91 | $params = array( | |
92 | 'name' => 'Test Product', | |
93 | 'sku' => 'TP-10', | |
94 | 'imageOption' => 'noImage', | |
95 | 'price' => 12, | |
96 | 'cost' => 5, | |
97 | 'min_contribution' => 5, | |
98 | 'is_active' => 1, | |
99 | ); | |
100 | ||
101 | $product = CRM_Contribute_BAO_ManagePremiums::add($params, $ids); | |
102 | CRM_Contribute_BAO_ManagePremiums::setIsActive($product->id, 0); | |
103 | ||
104 | $isActive = $this->assertDBNotNull('CRM_Contribute_BAO_ManagePremiums', $product->id, | |
105 | 'is_active', 'id', | |
106 | 'Database check on updated for product records is_active.' | |
107 | ); | |
108 | ||
109 | $this->assertEquals($isActive, 0, 'Verify product records is_active.'); | |
110 | } | |
111 | ||
112 | /** | |
100fef9d | 113 | * Check method del( ) |
6a488035 | 114 | */ |
00be9182 | 115 | public function testDel() { |
6a488035 TO |
116 | $ids = array(); |
117 | $params = array( | |
118 | 'name' => 'Test Product', | |
119 | 'sku' => 'TP-10', | |
120 | 'imageOption' => 'noImage', | |
121 | 'price' => 12, | |
122 | 'cost' => 5, | |
123 | 'min_contribution' => 5, | |
124 | 'is_active' => 1, | |
125 | ); | |
126 | ||
127 | $product = CRM_Contribute_BAO_ManagePremiums::add($params, $ids); | |
128 | ||
129 | CRM_Contribute_BAO_ManagePremiums::del($product->id); | |
130 | ||
131 | $params = array('id' => $product->id); | |
132 | $default = array(); | |
133 | $result = CRM_Contribute_BAO_ManagePremiums::retrieve($params, $defaults); | |
134 | ||
135 | $this->assertEquals(empty($result), TRUE, 'Verify product record deletion.'); | |
136 | } | |
137 | } |