|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* NOTICE OF LICENSE |
|
6
|
|
|
* |
|
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
|
9
|
|
|
* It is also available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
|
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
class EbayEnterprise_Multishipping_Test_Model_ObserverTest extends EcomDev_PHPUnit_Test_Case |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* When handling a sales order before save event, ensure that any shipment |
|
20
|
|
|
* amounts for that order have been collected before the order is saved. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testHandleSalesOrderBeforeSave() |
|
23
|
|
|
{ |
|
24
|
|
|
$order = $this->getModelMock('sales/order', ['collectShipmentAmounts']); |
|
25
|
|
|
$order->expects($this->once()) |
|
26
|
|
|
->method('collectShipmentAmounts') |
|
27
|
|
|
->will($this->returnSelf()); |
|
28
|
|
|
$event = new Varien_Event(['order' => $order]); |
|
29
|
|
|
$eventObserver = new Varien_Event_Observer(['event' => $event]); |
|
30
|
|
|
|
|
31
|
|
|
$observer = Mage::getModel('ebayenterprise_multishipping/observer'); |
|
32
|
|
|
$observer->handleSalesOrderSaveBefore($eventObserver); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* When converting a quote to an order, discount data from quote addresses |
|
37
|
|
|
* needs to bubble up to the order. |
|
38
|
|
|
*/ |
|
39
|
|
|
public function testHandleSalesConvertQuoteToOrder() |
|
40
|
|
|
{ |
|
41
|
|
|
$shipAddressDiscountAmt = 5.00; |
|
42
|
|
|
$shipAddressBaseDiscountAmt = 7.00; |
|
43
|
|
|
$altShipAddressDiscountAmt = 3.00; |
|
44
|
|
|
$altShipAddressBaseDiscountAmt = 5.00; |
|
45
|
|
|
$discountTotal = 8.00; |
|
46
|
|
|
$discountBaseTotal = 12.00; |
|
47
|
|
|
$discountDescription = 'Discount Description'; |
|
48
|
|
|
$altDiscountDescription = 'Alt Discount Description'; |
|
49
|
|
|
|
|
50
|
|
|
$order = Mage::getModel('sales/order'); |
|
51
|
|
|
$quote = $this->getModelMock('sales/quote', ['getAllAddresses']); |
|
52
|
|
|
$shippingAddress = Mage::getModel( |
|
53
|
|
|
'sales/quote_address', |
|
54
|
|
|
['discount_amount' => $shipAddressDiscountAmt, 'base_discount_amount' => $shipAddressBaseDiscountAmt, 'discount_description' => $discountDescription] |
|
55
|
|
|
); |
|
56
|
|
|
$altShippingAddress = Mage::getModel( |
|
57
|
|
|
'sales/quote_address', |
|
58
|
|
|
['discount_amount' => $altShipAddressDiscountAmt, 'base_discount_amount' => $altShipAddressBaseDiscountAmt, 'discount_description' => $altDiscountDescription] |
|
59
|
|
|
); |
|
60
|
|
|
$billingAddress = Mage::getModel('sales/quote_address', []); |
|
61
|
|
|
|
|
62
|
|
|
$quote->method('getAllAddresses')->willReturn([$shippingAddress, $altShippingAddress, $billingAddress]); |
|
63
|
|
|
|
|
64
|
|
|
$event = new Varien_Event(['order' => $order, 'quote' => $quote]); |
|
65
|
|
|
$eventObserver = new Varien_Event_Observer(['event' => $event]); |
|
66
|
|
|
|
|
67
|
|
|
$observer = Mage::getModel('ebayenterprise_multishipping/observer'); |
|
68
|
|
|
$observer->handleSalesConvertQuoteToOrder($eventObserver); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame($discountTotal, $order->getDiscountAmount()); |
|
71
|
|
|
$this->assertSame($discountBaseTotal, $order->getBaseDiscountAmount()); |
|
72
|
|
|
// Only the first discount description encountered should be used for the |
|
73
|
|
|
// order. If there are multiple discount descriptions, in OOTB Magento, |
|
74
|
|
|
// they will always be the same (here "discount" really only means coupons). |
|
75
|
|
|
// In the case that they are, for some reason, different on different addresses, |
|
76
|
|
|
// the order still only takes a single discount description so only |
|
77
|
|
|
// the first should be used. |
|
78
|
|
|
$this->assertSame($discountDescription, $order->getDiscountDescription()); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|