Merge pull request #4809 from totten/master-cs2
[civicrm-core.git] / tests / phpunit / CRM / Contribute / BAO / ManagePremiumsTest.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 require_once 'CiviTest/CiviUnitTestCase.php';
29
30 /**
31 * Class CRM_Contribute_BAO_ManagePremiumsTest
32 */
33 class CRM_Contribute_BAO_ManagePremiumsTest extends CiviUnitTestCase {
34
35 public function setUp() {
36 parent::setUp();
37 }
38
39 /**
40 * Check method add()
41 */
42 public function testAdd() {
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 /**
65 * Check method retrieve( )
66 */
67 public function testRetrieve() {
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 /**
87 * Check method setIsActive( )
88 */
89 public function testSetIsActive() {
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 /**
113 * Check method del( )
114 */
115 public function testDel() {
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 }