Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 | 27 | |
e9479dcf | 28 | /** |
37828d4f | 29 | * Class CRM_Contribute_BAO_ProductTest |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
37828d4f | 32 | class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { |
6a488035 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 TO |
35 | parent::setUp(); |
36 | } | |
37 | ||
38 | /** | |
100fef9d | 39 | * Check method add() |
6a488035 | 40 | */ |
00be9182 | 41 | public function testAdd() { |
9099cab3 | 42 | $params = [ |
6a488035 TO |
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, | |
9099cab3 | 50 | ]; |
6a488035 | 51 | |
32f27499 | 52 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 53 | $result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id, |
6a488035 TO |
54 | 'sku', 'id', |
55 | 'Database check on updated product record.' | |
56 | ); | |
57 | ||
58 | $this->assertEquals($result, 'TP-10', 'Verify products sku.'); | |
59 | } | |
60 | ||
61 | /** | |
100fef9d | 62 | * Check method retrieve( ) |
6a488035 | 63 | */ |
00be9182 | 64 | public function testRetrieve() { |
9099cab3 | 65 | $params = [ |
6a488035 TO |
66 | 'name' => 'Test Product', |
67 | 'sku' => 'TP-10', | |
68 | 'imageOption' => 'noImage', | |
69 | 'price' => 12, | |
70 | 'cost' => 5, | |
71 | 'min_contribution' => 5, | |
72 | 'is_active' => 1, | |
9099cab3 | 73 | ]; |
6a488035 | 74 | |
32f27499 | 75 | $product = CRM_Contribute_BAO_Product::create($params); |
9099cab3 CW |
76 | $params = ['id' => $product->id]; |
77 | $default = []; | |
37828d4f | 78 | $result = CRM_Contribute_BAO_Product::retrieve($params, $default); |
6a488035 TO |
79 | $this->assertEquals(empty($result), FALSE, 'Verify products record.'); |
80 | } | |
81 | ||
82 | /** | |
100fef9d | 83 | * Check method setIsActive( ) |
6a488035 | 84 | */ |
00be9182 | 85 | public function testSetIsActive() { |
9099cab3 | 86 | $params = [ |
6a488035 TO |
87 | 'name' => 'Test Product', |
88 | 'sku' => 'TP-10', | |
89 | 'imageOption' => 'noImage', | |
90 | 'price' => 12, | |
91 | 'cost' => 5, | |
92 | 'min_contribution' => 5, | |
93 | 'is_active' => 1, | |
9099cab3 | 94 | ]; |
6a488035 | 95 | |
32f27499 | 96 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 97 | CRM_Contribute_BAO_Product::setIsActive($product->id, 0); |
6a488035 | 98 | |
37828d4f | 99 | $isActive = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id, |
6a488035 TO |
100 | 'is_active', 'id', |
101 | 'Database check on updated for product records is_active.' | |
102 | ); | |
103 | ||
104 | $this->assertEquals($isActive, 0, 'Verify product records is_active.'); | |
105 | } | |
106 | ||
107 | /** | |
100fef9d | 108 | * Check method del( ) |
6a488035 | 109 | */ |
00be9182 | 110 | public function testDel() { |
9099cab3 | 111 | $params = [ |
6a488035 TO |
112 | 'name' => 'Test Product', |
113 | 'sku' => 'TP-10', | |
114 | 'imageOption' => 'noImage', | |
115 | 'price' => 12, | |
116 | 'cost' => 5, | |
117 | 'min_contribution' => 5, | |
118 | 'is_active' => 1, | |
9099cab3 | 119 | ]; |
6a488035 | 120 | |
32f27499 | 121 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 122 | CRM_Contribute_BAO_Product::del($product->id); |
6a488035 | 123 | |
9099cab3 CW |
124 | $params = ['id' => $product->id]; |
125 | $defaults = []; | |
a275d4b6 | 126 | $retrievedProduct = CRM_Contribute_BAO_Product::retrieve($params, $defaults); |
6a488035 | 127 | |
a275d4b6 | 128 | $this->assertEquals(empty($retrievedProduct), TRUE, 'Verify product record deletion.'); |
6a488035 | 129 | } |
96025800 | 130 | |
6a488035 | 131 | } |