3b7e8eda2e587f7cc3470fd225cfcf43a0a9ab6d
[civicrm-core.git] / tests / phpunit / CRM / Contribute / BAO / ProductTest.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_Contribute_BAO_ProductTest
30 * @group headless
31 */
32 class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase {
33
34 public function setUp() {
35 parent::setUp();
36 }
37
38 /**
39 * Check method add()
40 */
41 public function testAdd() {
42 $params = array(
43 'name' => 'Test Product',
44 'sku' => 'TP-10',
45 'imageOption' => 'noImage',
46 'price' => 12,
47 'cost' => 5,
48 'min_contribution' => 5,
49 'is_active' => 1,
50 );
51
52 $product = CRM_Contribute_BAO_Product::add($params);
53
54 $result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id,
55 'sku', 'id',
56 'Database check on updated product record.'
57 );
58
59 $this->assertEquals($result, 'TP-10', 'Verify products sku.');
60 }
61
62 /**
63 * Check method retrieve( )
64 */
65 public function testRetrieve() {
66 $params = array(
67 'name' => 'Test Product',
68 'sku' => 'TP-10',
69 'imageOption' => 'noImage',
70 'price' => 12,
71 'cost' => 5,
72 'min_contribution' => 5,
73 'is_active' => 1,
74 );
75
76 $product = CRM_Contribute_BAO_Product::add($params);
77 $params = array('id' => $product->id);
78 $default = array();
79 $result = CRM_Contribute_BAO_Product::retrieve($params, $default);
80 $this->assertEquals(empty($result), FALSE, 'Verify products record.');
81 }
82
83 /**
84 * Check method setIsActive( )
85 */
86 public function testSetIsActive() {
87 $params = array(
88 'name' => 'Test Product',
89 'sku' => 'TP-10',
90 'imageOption' => 'noImage',
91 'price' => 12,
92 'cost' => 5,
93 'min_contribution' => 5,
94 'is_active' => 1,
95 );
96
97 $product = CRM_Contribute_BAO_Product::add($params);
98 CRM_Contribute_BAO_Product::setIsActive($product->id, 0);
99
100 $isActive = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id,
101 'is_active', 'id',
102 'Database check on updated for product records is_active.'
103 );
104
105 $this->assertEquals($isActive, 0, 'Verify product records is_active.');
106 }
107
108 /**
109 * Check method del( )
110 */
111 public function testDel() {
112 $params = array(
113 'name' => 'Test Product',
114 'sku' => 'TP-10',
115 'imageOption' => 'noImage',
116 'price' => 12,
117 'cost' => 5,
118 'min_contribution' => 5,
119 'is_active' => 1,
120 );
121
122 $product = CRM_Contribute_BAO_Product::add($params);
123
124 CRM_Contribute_BAO_Product::del($product->id);
125
126 $params = array('id' => $product->id);
127 $default = array();
128 $result = CRM_Contribute_BAO_Product::retrieve($params, $defaults);
129
130 $this->assertEquals(empty($result), TRUE, 'Verify product record deletion.');
131 }
132
133 }