| 1 |
<?php
|
| 2 |
|
| 3 |
class UCAffiliateUnitTest extends DrupalWebTestCase {
|
| 4 |
function getInfo() {
|
| 5 |
return array(
|
| 6 |
'name' => t('Various unit tests'),
|
| 7 |
'description' => t('Assure that affiliate program works fine.'),
|
| 8 |
'group' => t('UC Affiliate Tests'),
|
| 9 |
);
|
| 10 |
}
|
| 11 |
/**
|
| 12 |
* Implementation of setUp().
|
| 13 |
*/
|
| 14 |
function setUp() {
|
| 15 |
parent::setUp('uc_store', 'uc_cart', 'uc_product', 'uc_order', 'uc_affiliate', 'uc_affiliate_payments');
|
| 16 |
}
|
| 17 |
|
| 18 |
/**
|
| 19 |
* Implementation of tearDown().
|
| 20 |
*/
|
| 21 |
function tearDown() {
|
| 22 |
parent::tearDown();
|
| 23 |
}
|
| 24 |
|
| 25 |
function testParseCommission() {
|
| 26 |
$parsed = uc_affiliate_parse_commission($this->randomName());
|
| 27 |
$this->assertEqual($parsed, ERROR_COMMISSION_NOT_NUMBER, t('Random value'), t('Commission parsing.'));
|
| 28 |
$parsed = uc_affiliate_parse_commission('4;5%;'. $this->randomName());
|
| 29 |
$this->assertEqual($parsed, ERROR_COMMISSION_NOT_NUMBER, t('Partial random value'), t('Commission parsing.'));
|
| 30 |
|
| 31 |
$parsed = uc_affiliate_parse_commission('-101');
|
| 32 |
$this->assertEqual($parsed, ERROR_COMMISSION_CANT_BE_NEGATIVE, t('Commission percent out of borders (-101)'), t('Commission parsing.'));
|
| 33 |
$parsed = uc_affiliate_parse_commission('-101%');
|
| 34 |
$this->assertEqual($parsed, ERROR_COMMISSION_CANT_BE_NEGATIVE, t('Commission percent out of borders (-101%)'), t('Commission parsing.'));
|
| 35 |
$parsed = uc_affiliate_parse_commission('2220%');
|
| 36 |
$this->assertEqual($parsed, ERROR_COMMISSION_PERCENT_OUT_OF_BORDERS, t('Commission percent out of borders (2220%)'), t('Commission parsing.'));
|
| 37 |
|
| 38 |
$parsed = uc_affiliate_parse_commission('');
|
| 39 |
$this->assertTrue(is_array($parsed) && empty($parsed), t('Blank commission'), t('Commission parsing.'));
|
| 40 |
$parsed = uc_affiliate_parse_commission('0');
|
| 41 |
$this->assertTrue(is_array($parsed) && is_numeric($parsed[0]['value']) && $parsed[0]['value'] == 0, t('Zero commission parsng.'), t('Commission parsing.'));
|
| 42 |
|
| 43 |
$parsed = uc_affiliate_parse_commission('5;10;43');
|
| 44 |
$this->assertTrue(is_array($parsed), t('Is array "5;10;43"'), t('Commission parsing.'));
|
| 45 |
$parsed = uc_affiliate_parse_commission('5; 10; 43');
|
| 46 |
$this->assertTrue(is_array($parsed), t('Is array "5; 10; 43"'), t('Commission parsing.'));
|
| 47 |
$parsed = uc_affiliate_parse_commission('5; 10%;43%');
|
| 48 |
$this->assertTrue(is_array($parsed), t('Is array "5; 10%;43%"'), t('Commission parsing.'));
|
| 49 |
$parsed = uc_affiliate_parse_commission('5.55; 10.6%;43');
|
| 50 |
$this->assertTrue(is_array($parsed), t('Is array "5.55; 10.6%;43"'), t('Commission parsing.'));
|
| 51 |
|
| 52 |
$parsed = uc_affiliate_parse_commission('4;20.5%;500');
|
| 53 |
$this->assertEqual(count($parsed), 3, t('"4;20.5%;500": Wrong commissions array count'), t('Commission parsing.'));
|
| 54 |
|
| 55 |
$this->assertTrue(is_numeric($parsed[0]['value']), t('"4;20.5%;500": First value is numeric'), t('Commission parsing.'));
|
| 56 |
$this->assertEqual($parsed[0]['value'], 4, t('"4;20.5%;500": First value is 4'), t('Commission parsing.'));
|
| 57 |
$this->assertEqual($parsed[0]['type'], 'currency', t('"4;20.5%;500": First type is currency'), t('Commission parsing.'));
|
| 58 |
$this->assertTrue(is_numeric($parsed[1]['value']), t('"4;20.5%;500": Second value is numeric'), t('Commission parsing.'));
|
| 59 |
$this->assertEqual($parsed[1]['value'], 20.5, t('"4;20.5%;500": Second value is 22.5'), t('Commission parsing.'));
|
| 60 |
$this->assertEqual($parsed[1]['type'], 'percent',t( '"4;20.5%;500": Second value is percent'), t('Commission parsing.'));
|
| 61 |
$this->assertTrue(is_numeric($parsed[2]['value']), t('"4;20.5%;500": Third value is numeric'), t('Commission parsing.'));
|
| 62 |
$this->assertEqual($parsed[2]['value'], 500, t('"4;20.5%;500": Third value is 500'), t('Commission parsing.'));
|
| 63 |
$this->assertEqual($parsed[2]['type'], 'currency', t('"4;20.5%;500": Third type is currency'), t('Commission parsing.'));
|
| 64 |
}
|
| 65 |
|
| 66 |
function testCommission2Str() {
|
| 67 |
$this->assertEqual(uc_affiliate_commission2str(array()), '', t('Blank commission string.'), t('Commission to string.'));
|
| 68 |
|
| 69 |
$commission = array('value' => 20.554, 'type' => 'percent');
|
| 70 |
$this->assertEqual(uc_affiliate_commission2str($commission), '20.554%', t('Single commission item.'), t('Commission to string.'));
|
| 71 |
|
| 72 |
$commission = array(
|
| 73 |
0 => array('value' => 50, 'type' => 'percent'),
|
| 74 |
1 => array('value' => 20.554, 'type' => 'currency'),
|
| 75 |
2 => array('value' => 99990.1, 'type' => 'currency'),
|
| 76 |
);
|
| 77 |
$this->assertEqual(uc_affiliate_commission2str($commission), '50%; 20.554; 99990.1', t('Basic commission convertion.'), t('Commission to string.'));
|
| 78 |
$this->assertEqual(uc_affiliate_commission2str($commission, TRUE), '50%; $20.55; $99,990.10', t('Commission convertion with currency formatting.'), t('Commission to string.'));
|
| 79 |
}
|
| 80 |
|
| 81 |
function test_product_commissions_data_CRUD() {
|
| 82 |
$settings = array(
|
| 83 |
'type' => 'product',
|
| 84 |
'sell_price' => 100,
|
| 85 |
'list_price' => '',
|
| 86 |
'cost' => '',
|
| 87 |
'model' => '',
|
| 88 |
'weight' => '',
|
| 89 |
'weight_units' => '',
|
| 90 |
'length' => '',
|
| 91 |
'width' => '',
|
| 92 |
'height' => '',
|
| 93 |
'length_units' => '',
|
| 94 |
'default_qty' => '',
|
| 95 |
'pkg_qty' => '',
|
| 96 |
'shippable' => 0,
|
| 97 |
'ordering' => '',
|
| 98 |
);
|
| 99 |
$node1 = $this->drupalCreateNode($settings);
|
| 100 |
$node2 = $this->drupalCreateNode($settings);
|
| 101 |
$node3 = $this->drupalCreateNode($settings);
|
| 102 |
$node4 = $this->drupalCreateNode($settings);
|
| 103 |
$node5 = $this->drupalCreateNode($settings);
|
| 104 |
|
| 105 |
$uid3 = $this->drupalCreateUser(array('act as affiliate')); // UID == 3
|
| 106 |
$uid4 = $this->drupalCreateUser(array('act as affiliate')); // UID == 4
|
| 107 |
|
| 108 |
variable_set('uc_affiliate_commission', uc_affiliate_parse_commission('200'));
|
| 109 |
variable_set('uc_affiliate_allow_products_by_default', FALSE);
|
| 110 |
|
| 111 |
$data = array(
|
| 112 |
$node1->nid => array(
|
| 113 |
0 => array(
|
| 114 |
'commission' => uc_affiliate_parse_commission('10; 20'),
|
| 115 |
'allowed' => TRUE,
|
| 116 |
),
|
| 117 |
$uid3->uid => array(
|
| 118 |
'commission' => uc_affiliate_parse_commission('50%; 80'),
|
| 119 |
'allowed' => TRUE,
|
| 120 |
),
|
| 121 |
$uid4->uid => array(
|
| 122 |
'commission' => uc_affiliate_parse_commission('45%; 80'),
|
| 123 |
'allowed' => FALSE,
|
| 124 |
),
|
| 125 |
),
|
| 126 |
$node2->nid => array(
|
| 127 |
0 => array(
|
| 128 |
'commission' => uc_affiliate_parse_commission('10; 20%'),
|
| 129 |
'allowed' => FALSE,
|
| 130 |
),
|
| 131 |
$uid3->uid => array(
|
| 132 |
'commission' => uc_affiliate_parse_commission(''),
|
| 133 |
'allowed' => TRUE,
|
| 134 |
),
|
| 135 |
),
|
| 136 |
$node3->nid => array(
|
| 137 |
0 => array(
|
| 138 |
'commission' => uc_affiliate_parse_commission(''),
|
| 139 |
'allowed' => TRUE,
|
| 140 |
),
|
| 141 |
),
|
| 142 |
$node4->nid => array(
|
| 143 |
0 => array(
|
| 144 |
'commission' => uc_affiliate_parse_commission(''),
|
| 145 |
'allowed' => FALSE,
|
| 146 |
),
|
| 147 |
),
|
| 148 |
);
|
| 149 |
uc_affiliate_set_product_commissions_data($data);
|
| 150 |
|
| 151 |
// Test availability.
|
| 152 |
$products = uc_affiliate_get_affiliate_available_products();
|
| 153 |
$this->assertTrue(is_array($products) && count($products) == 2 && isset($products[$node1->nid]) && isset($products[$node3->nid]), t('Test availability [0]'), t('Commission data CRUD'));
|
| 154 |
$products = uc_affiliate_get_affiliate_available_products($uid3->uid);
|
| 155 |
$this->assertTrue(is_array($products) && count($products) == 3 && isset($products[$node1->nid]) && isset($products[$node2->nid]) && isset($products[$node3->nid]) && !isset($products[$node4->nid]), t('Test availability [1]'), t('Commission data CRUD'));
|
| 156 |
$products = uc_affiliate_get_affiliate_available_products($uid4->uid);
|
| 157 |
$this->assertTrue(is_array($products) && count($products) == 1 && isset($products[$node3->nid]), t('Test availability [2]'), t('Commission data CRUD'));
|
| 158 |
variable_set('uc_affiliate_allow_products_by_default', TRUE);
|
| 159 |
$products = uc_affiliate_get_affiliate_available_products($uid4->uid);
|
| 160 |
$this->assertTrue(is_array($products) && count($products) == 2 && isset($products[$node3->nid])&& isset($products[$node5->nid]), t('Test availability [3]'), t('Commission data CRUD'));
|
| 161 |
variable_set('uc_affiliate_allow_products_by_default', FALSE);
|
| 162 |
|
| 163 |
// Test basic storage.
|
| 164 |
$stored = uc_affiliate_get_product_commissions_data($node1->nid);
|
| 165 |
$this->assertEqual(uc_affiliate_commission2str($stored[0]['commission']), uc_affiliate_commission2str($data[$node1->nid][0]['commission']), t('Saved == Stored'), t('Commission data CRUD'));
|
| 166 |
$stored = uc_affiliate_get_product_commissions_data($node1->nid, $uid3->uid);
|
| 167 |
$this->assertEqual(uc_affiliate_commission2str($stored['commission']), uc_affiliate_commission2str($data[$node1->nid][$uid3->uid]['commission']), t('Saved == Stored'), t('Commission data CRUD'));
|
| 168 |
|
| 169 |
// This should test filling default values.
|
| 170 |
$stored = uc_affiliate_get_product_commissions_data($node3->nid);
|
| 171 |
$this->assertEqual(uc_affiliate_commission2str($stored[0]['commission']), '200', t('Fill defaults [Global -> product]'), t('Commission data CRUD'));
|
| 172 |
$stored = uc_affiliate_get_product_commissions_data($node2->nid, $uid3->uid);
|
| 173 |
$this->assertEqual(uc_affiliate_commission2str($stored['commission']), uc_affiliate_commission2str($data[$node2->nid][0]['commission']), t('Fill defaults [Product -> affid]'), t('Commission data CRUD'));
|
| 174 |
|
| 175 |
// Test actual commission.
|
| 176 |
$commission = uc_affiliate_get_commission($node1->nid, $uid3->uid);
|
| 177 |
$this->assertTrue($commission == 50, t('Test real commission'), t('Commission data CRUD'));
|
| 178 |
$commission = uc_affiliate_get_commission($node1->nid, $uid3->uid, NULL, 1);
|
| 179 |
$this->assertTrue($commission == 80, t('Test real commission [level]'), t('Commission data CRUD'));
|
| 180 |
|
| 181 |
$total = array(
|
| 182 |
'count' => 2,
|
| 183 |
'price' => 1000,
|
| 184 |
);
|
| 185 |
$commission = uc_affiliate_get_commission($node1->nid, $uid3->uid, $total);
|
| 186 |
$this->assertTrue($commission == 500, t('Test real commission [percent] [with total]'), t('Commission data CRUD'));
|
| 187 |
$commission = uc_affiliate_get_commission($node1->nid, $uid3->uid, $total, 1);
|
| 188 |
$this->assertTrue($commission == 160, t('Test real commission [currency] [with total: level]'), t('Commission data CRUD'));
|
| 189 |
}
|
| 190 |
|
| 191 |
function test_sale() {
|
| 192 |
$user1 = $this->drupalCreateUser(array('act as affiliate'));
|
| 193 |
$user2 = $this->drupalCreateUser(array('act as affiliate'));
|
| 194 |
$settings = array(
|
| 195 |
'type' => 'product',
|
| 196 |
'title' => 'Mega product',
|
| 197 |
'sell_price' => 100,
|
| 198 |
'list_price' => 0,
|
| 199 |
'cost' => 0,
|
| 200 |
'model' => 'MODEL',
|
| 201 |
'weight' => '',
|
| 202 |
'weight_units' => '',
|
| 203 |
'length' => '',
|
| 204 |
'width' => '',
|
| 205 |
'height' => '',
|
| 206 |
'length_units' => '',
|
| 207 |
'default_qty' => '',
|
| 208 |
'pkg_qty' => '',
|
| 209 |
'shippable' => 0,
|
| 210 |
'ordering' => '',
|
| 211 |
);
|
| 212 |
$product = $this->drupalCreateNode($settings);
|
| 213 |
$product_data->nid = $product->nid;
|
| 214 |
$product_data->qty = 1;
|
| 215 |
$product_data->title = $prodcut->title;
|
| 216 |
$product_data->model = 'MODEL';
|
| 217 |
$product_data->cost = $product->cost;
|
| 218 |
$product_data->price = $product->sell_price;
|
| 219 |
|
| 220 |
$data = array(
|
| 221 |
$product->nid => array(
|
| 222 |
0 => array(
|
| 223 |
'commission' => uc_affiliate_parse_commission('50%; 20'),
|
| 224 |
'allowed' => TRUE,
|
| 225 |
),
|
| 226 |
$user2->uid => array(
|
| 227 |
'commission' => uc_affiliate_parse_commission('10; 5'),
|
| 228 |
'allowed' => TRUE,
|
| 229 |
),
|
| 230 |
),
|
| 231 |
);
|
| 232 |
uc_affiliate_set_product_commissions_data($data);
|
| 233 |
|
| 234 |
$order = uc_order_new($user1->uid);
|
| 235 |
$product_data->data = array('affid' => $user1->uid);
|
| 236 |
$order->products[] = $product_data;
|
| 237 |
uc_order_save($order);
|
| 238 |
uc_order_update_status($order->order_id, 'completed');
|
| 239 |
$this->assertEqual(uc_affiliate_balance($user1), 50, t('Sale commission [percent]'), t('Testing sale commission'));
|
| 240 |
$this->assertFalse(uc_affiliate_process_sale($order), t('Prevent double commission [check return value]'), t('Testing sale commission'));
|
| 241 |
$this->assertEqual(uc_affiliate_balance($user1), 50, t('Prevent double commission [check balance]'), t('Testing sale commission'));
|
| 242 |
|
| 243 |
$order = uc_order_new($user2->uid);
|
| 244 |
$product_data->data = array('affid' => $user2->uid);
|
| 245 |
$order->products[] = $product_data;
|
| 246 |
uc_order_save($order);
|
| 247 |
uc_order_update_status($order->order_id, 'completed');
|
| 248 |
$this->assertEqual(uc_affiliate_balance($user2), 10, t('Sale commission [currency]'), t('Testing sale commission'));
|
| 249 |
uc_order_update_status($order->order_id, 'canceled');
|
| 250 |
$this->assertEqual(uc_affiliate_balance($user2), 0, t('Rettun commission'), t('Testing sale commission'));
|
| 251 |
$this->assertFalse(uc_affiliate_process_return($order), t('Prevent double return commission [check return value]'), t('Testing sale commission'));
|
| 252 |
$this->assertEqual(uc_affiliate_balance($user2), 0, t('Prevent double return commission [check balance]'), t('Testing sale commission'));
|
| 253 |
uc_order_update_status($order->order_id, 'completed');
|
| 254 |
$this->assertFalse(uc_affiliate_process_return($order), t('Leave return even if sale reverted to "completed".'), t('Testing sale commission'));
|
| 255 |
}
|
| 256 |
}
|
| 257 |
|
| 258 |
class UCAffiliateFunctionalTest extends DrupalWebTestCase {
|
| 259 |
function getInfo() {
|
| 260 |
return array(
|
| 261 |
'name' => t('Various functional tests'),
|
| 262 |
'description' => t('Assure that affiliate program works fine.'),
|
| 263 |
'group' => t('UC Affiliate Tests'),
|
| 264 |
);
|
| 265 |
}
|
| 266 |
/**
|
| 267 |
* Implementation of setUp().
|
| 268 |
*/
|
| 269 |
function setUp() {
|
| 270 |
parent::setUp('uc_store', 'uc_cart', 'uc_product', 'uc_order', 'uc_affiliate');
|
| 271 |
}
|
| 272 |
|
| 273 |
/**
|
| 274 |
* Implementation of tearDown().
|
| 275 |
*/
|
| 276 |
function tearDown() {
|
| 277 |
parent::tearDown();
|
| 278 |
}
|
| 279 |
|
| 280 |
|
| 281 |
function testProductCommissionForm() {
|
| 282 |
$settings = array(
|
| 283 |
'type' => 'product',
|
| 284 |
'sell_price' => 100,
|
| 285 |
'list_price' => '',
|
| 286 |
'cost' => '',
|
| 287 |
'model' => '',
|
| 288 |
'weight' => '',
|
| 289 |
'weight_units' => '',
|
| 290 |
'length' => '',
|
| 291 |
'width' => '',
|
| 292 |
'height' => '',
|
| 293 |
'length_units' => '',
|
| 294 |
'default_qty' => '',
|
| 295 |
'pkg_qty' => '',
|
| 296 |
'shippable' => 0,
|
| 297 |
'ordering' => '',
|
| 298 |
);
|
| 299 |
$node = $this->drupalCreateNode($settings);
|
| 300 |
|
| 301 |
$affiliate = $this->drupalCreateUser(array('act as affiliate'));
|
| 302 |
$this->drupalLogin($affiliate);
|
| 303 |
$this->drupalGet('node/'. $node->nid .'/edit/affiliate');
|
| 304 |
$this->assertResponse(403, t('Make sure access is denied on the product commission page.'));
|
| 305 |
|
| 306 |
$admin = $this->drupalCreateUser(array('administer affiliates', 'administer store', 'administer nodes'));
|
| 307 |
$this->drupalLogin($admin);
|
| 308 |
$this->drupalGet('node/'. $node->nid .'/edit/affiliate');
|
| 309 |
$this->assertResponse(200, t('Make sure access is not denied for admin.'));
|
| 310 |
|
| 311 |
// TEST global product availability
|
| 312 |
variable_set('uc_affiliate_allow_products_by_default', FALSE);
|
| 313 |
$products = uc_affiliate_get_affiliate_available_products();
|
| 314 |
$this->assertTrue(is_array($products) && empty($products), t('Product disabled for everyone when DEFAULT = FALSE and DEFAULT everywhere.'));
|
| 315 |
|
| 316 |
variable_set('uc_affiliate_allow_products_by_default', TRUE);
|
| 317 |
$products = uc_affiliate_get_affiliate_available_products();
|
| 318 |
$this->assertTrue(is_array($products) && count($products) == 1 && isset($products[$node->nid]), t('Product enabled for everyone when DEFAULT = TRUE and DEFAULT everywhere.'));
|
| 319 |
|
| 320 |
|
| 321 |
// TEST global and new commissions
|
| 322 |
$edit = array('global[amount]' => '-5');
|
| 323 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 324 |
$this->assertText(t('Commission can not be negative.'), t('Check product commission validation.'));
|
| 325 |
|
| 326 |
$edit = array('global[amount]' => '50%;20');
|
| 327 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 328 |
$this->assertRaw('value="50%; 20"', t('Set product global commission value.'));
|
| 329 |
|
| 330 |
$name = $this->randomName(8);
|
| 331 |
$edit = array('new[amount]' => '75%;50%;20', 'new[allowed]' => PRODUCT_DEFAULT_FOR_AFFILIATES, 'new[name]' => $name);
|
| 332 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 333 |
$this->assertRaw(t('User <em>@user</em> is not affiliate.', array('@user' => $name)), t('Fail to add commission for random user.'));
|
| 334 |
|
| 335 |
$edit = array('new[amount]' => '75%;50%;20', 'new[allowed]' => PRODUCT_DEFAULT_FOR_AFFILIATES, 'new[name]' => $affiliate->name);
|
| 336 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 337 |
$this->assertRaw('>'. $affiliate->name .'</a>', t('Create product×affiliate commission.'));
|
| 338 |
|
| 339 |
$edit = array('new[amount]' => '75%;50%;20', 'new[allowed]' => PRODUCT_DEFAULT_FOR_AFFILIATES, 'new[name]' => $affiliate->name);
|
| 340 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 341 |
$this->assertRaw(t('Commissions for <em>@user</em> is already present for this product.', array('@user' => $affiliate->name)), t('Fail to double create commission for same affiliate.'));
|
| 342 |
|
| 343 |
|
| 344 |
// TEST affiliate product availability
|
| 345 |
variable_set('uc_affiliate_allow_products_by_default', FALSE);
|
| 346 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 347 |
$this->assertTrue(is_array($products) && empty($products), t('Product disabled for user when DEFAULT = FALSE and DEFAULT everywhere.'));
|
| 348 |
|
| 349 |
variable_set('uc_affiliate_allow_products_by_default', TRUE);
|
| 350 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 351 |
$this->assertTrue(is_array($products) && count($products) == 1 && isset($products[$node->nid]), t('Product enabled for user when DEFAULT = TRUE and DEFAULT everywhere.'));
|
| 352 |
|
| 353 |
$edit = array('global[allowed]' => PRODUCT_DISABLED_FOR_AFFILIATES);
|
| 354 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 355 |
|
| 356 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 357 |
$this->assertTrue(is_array($products) && empty($products), t('Product disabled for user when DEFAULT = TRUE and GLOBAL = DISABLED and USER = DEFAULT.'));
|
| 358 |
|
| 359 |
$edit = array('users['. $affiliate->uid .'][amount]' => '75%;50%;20', 'users['. $affiliate->uid .'][allowed]' => PRODUCT_ENABLED_FOR_AFFILIATES);
|
| 360 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 361 |
|
| 362 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 363 |
$this->assertTrue(is_array($products) && count($products) == 1 && isset($products[$node->nid]), t('Product enabled for user when DEFAULT = TRUE and GLOBAL = DISABLED and USER = ENABLED.'));
|
| 364 |
|
| 365 |
variable_set('uc_affiliate_allow_products_by_default', FALSE);
|
| 366 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 367 |
$this->assertTrue(is_array($products) && count($products) == 1 && isset($products[$node->nid]), t('Product enabled for user when DEFAULT = FALSE and GLOBAL = DISABLED and USER = ENABLED.'));
|
| 368 |
|
| 369 |
variable_set('uc_affiliate_allow_products_by_default', TRUE);
|
| 370 |
$edit = array('global[allowed]' => PRODUCT_DEFAULT_FOR_AFFILIATES, 'users['. $affiliate->uid .'][amount]' => '75%;50%;20', 'users['. $affiliate->uid .'][allowed]' => PRODUCT_DISABLED_FOR_AFFILIATES);
|
| 371 |
$this->drupalPost('node/'. $node->nid .'/edit/affiliate', $edit, t('Save changes'));
|
| 372 |
$products = uc_affiliate_get_affiliate_available_products($affiliate->uid);
|
| 373 |
$this->assertTrue(is_array($products) && empty($products), t('Product disabled for user when DEFAULT = TRUE and GLOBAL = DEFAULT and USER = DISABLED.'));
|
| 374 |
}
|
| 375 |
|
| 376 |
|
| 377 |
// @TODO Affiliate signup, pair check and deletion.
|
| 378 |
// @TODO Sales and returns commission.
|
| 379 |
}
|