Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7d61e75f | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
7d61e75f TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 | 11 | |
e9479dcf | 12 | /** |
37828d4f | 13 | * Class CRM_Contribute_BAO_ProductTest |
acb109b7 | 14 | * @group headless |
e9479dcf | 15 | */ |
37828d4f | 16 | class CRM_Contribute_BAO_ProductTest extends CiviUnitTestCase { |
6a488035 | 17 | |
6a488035 | 18 | /** |
100fef9d | 19 | * Check method add() |
6a488035 | 20 | */ |
00be9182 | 21 | public function testAdd() { |
9099cab3 | 22 | $params = [ |
6a488035 TO |
23 | 'name' => 'Test Product', |
24 | 'sku' => 'TP-10', | |
25 | 'imageOption' => 'noImage', | |
26 | 'price' => 12, | |
27 | 'cost' => 5, | |
28 | 'min_contribution' => 5, | |
29 | 'is_active' => 1, | |
9099cab3 | 30 | ]; |
6a488035 | 31 | |
32f27499 | 32 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 33 | $result = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id, |
6a488035 TO |
34 | 'sku', 'id', |
35 | 'Database check on updated product record.' | |
36 | ); | |
37 | ||
38 | $this->assertEquals($result, 'TP-10', 'Verify products sku.'); | |
39 | } | |
40 | ||
41 | /** | |
100fef9d | 42 | * Check method retrieve( ) |
6a488035 | 43 | */ |
00be9182 | 44 | public function testRetrieve() { |
9099cab3 | 45 | $params = [ |
6a488035 TO |
46 | 'name' => 'Test Product', |
47 | 'sku' => 'TP-10', | |
48 | 'imageOption' => 'noImage', | |
49 | 'price' => 12, | |
50 | 'cost' => 5, | |
51 | 'min_contribution' => 5, | |
52 | 'is_active' => 1, | |
9099cab3 | 53 | ]; |
6a488035 | 54 | |
32f27499 | 55 | $product = CRM_Contribute_BAO_Product::create($params); |
9099cab3 CW |
56 | $params = ['id' => $product->id]; |
57 | $default = []; | |
37828d4f | 58 | $result = CRM_Contribute_BAO_Product::retrieve($params, $default); |
6a488035 TO |
59 | $this->assertEquals(empty($result), FALSE, 'Verify products record.'); |
60 | } | |
61 | ||
62 | /** | |
100fef9d | 63 | * Check method setIsActive( ) |
6a488035 | 64 | */ |
00be9182 | 65 | public function testSetIsActive() { |
9099cab3 | 66 | $params = [ |
6a488035 TO |
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, | |
9099cab3 | 74 | ]; |
6a488035 | 75 | |
32f27499 | 76 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 77 | CRM_Contribute_BAO_Product::setIsActive($product->id, 0); |
6a488035 | 78 | |
37828d4f | 79 | $isActive = $this->assertDBNotNull('CRM_Contribute_BAO_Product', $product->id, |
6a488035 TO |
80 | 'is_active', 'id', |
81 | 'Database check on updated for product records is_active.' | |
82 | ); | |
83 | ||
84 | $this->assertEquals($isActive, 0, 'Verify product records is_active.'); | |
85 | } | |
86 | ||
87 | /** | |
100fef9d | 88 | * Check method del( ) |
6a488035 | 89 | */ |
00be9182 | 90 | public function testDel() { |
9099cab3 | 91 | $params = [ |
6a488035 TO |
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, | |
9099cab3 | 99 | ]; |
6a488035 | 100 | |
32f27499 | 101 | $product = CRM_Contribute_BAO_Product::create($params); |
37828d4f | 102 | CRM_Contribute_BAO_Product::del($product->id); |
6a488035 | 103 | |
9099cab3 CW |
104 | $params = ['id' => $product->id]; |
105 | $defaults = []; | |
a275d4b6 | 106 | $retrievedProduct = CRM_Contribute_BAO_Product::retrieve($params, $defaults); |
6a488035 | 107 | |
a275d4b6 | 108 | $this->assertEquals(empty($retrievedProduct), TRUE, 'Verify product record deletion.'); |
6a488035 | 109 | } |
96025800 | 110 | |
6a488035 | 111 | } |