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