|
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
|
|
|
/** |
|
17
|
|
|
* Unit tests for @see EbayEnterprise_GiftCard_Model_Adminhtml_Observer |
|
18
|
|
|
*/ |
|
19
|
|
|
class EbayEnterprise_GiftCard_Test_Model_Adminhtml_ObserverTest extends EbayEnterprise_Eb2cCore_Test_Base |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var EbayEnterprise_GiftCard_Model_IContainer (mock) */ |
|
22
|
|
|
protected $container; |
|
23
|
|
|
/** @var EbayEnterprise_GiftCard_Model_Giftcard (mock) */ |
|
24
|
|
|
protected $giftCard; |
|
25
|
|
|
/** @var EbayEnterprise_GiftCard_Helper_Data (mock) */ |
|
26
|
|
|
protected $helper; |
|
27
|
|
|
/** @var EbayEnterprise_GiftCard_Model_Adminhtml_Observer */ |
|
28
|
|
|
protected $observer; |
|
29
|
|
|
|
|
30
|
|
|
public function setUp() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->container = $this->getMockForAbstractClass('EbayEnterprise_GiftCard_Model_IContainer'); |
|
|
|
|
|
|
33
|
|
|
$this->giftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', ['setPin']); |
|
|
|
|
|
|
34
|
|
|
$this->helper = $this->getHelperMock('ebayenterprise_giftcard', ['addGiftCardToOrder']); |
|
35
|
|
|
$logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); |
|
36
|
|
|
$logContext->method('getMetaData')->willReturn([]); |
|
37
|
|
|
|
|
38
|
|
|
$this->observer = Mage::getModel( |
|
39
|
|
|
'ebayenterprise_giftcard/adminhtml_observer', |
|
40
|
|
|
[ |
|
41
|
|
|
'container' => $this->container, |
|
42
|
|
|
'helper' => $this->helper, |
|
43
|
|
|
'log_context' => $logContext |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* When adding a gift card to the order, the card should be retrieved from |
|
50
|
|
|
* the container by card number, have the PIN set on the card and finally |
|
51
|
|
|
* be added to the order. |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
public function testAddGiftCard() |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
$cardNumber = '1111111111111111'; |
|
56
|
|
|
$pin = '1234'; |
|
57
|
|
|
|
|
58
|
|
|
$this->container |
|
|
|
|
|
|
59
|
|
|
->method('getGiftCard') |
|
60
|
|
|
->with($cardNumber) |
|
61
|
|
|
->willReturn($this->giftCard); |
|
62
|
|
|
// Pin must be set on the gift card to be added. |
|
63
|
|
|
$this->giftCard->expects($this->once()) |
|
|
|
|
|
|
64
|
|
|
->method('setPin') |
|
65
|
|
|
->with($this->identicalTo($pin)) |
|
66
|
|
|
->willReturnSelf(); |
|
67
|
|
|
// Helper should be used to add the gift card to the order. Expect |
|
68
|
|
|
// it to be successful in this case. |
|
69
|
|
|
$this->helper->expects($this->once()) |
|
70
|
|
|
->method('addGiftCardToOrder') |
|
71
|
|
|
->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container)) |
|
72
|
|
|
->willReturnSelf(); |
|
73
|
|
|
|
|
74
|
|
|
$this->assertSame( |
|
75
|
|
|
$this->observer, |
|
76
|
|
|
EcomDev_Utils_Reflection::invokeRestrictedMethod($this->observer, 'addGiftCard', [$cardNumber, $pin]) |
|
77
|
|
|
); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Failing to add a gift card to cart should fail silently. |
|
82
|
|
|
*/ |
|
83
|
|
View Code Duplication |
public function testAddGiftCardException() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$cardNumber = '1111111111111111'; |
|
86
|
|
|
$pin = '1234'; |
|
87
|
|
|
|
|
88
|
|
|
$this->container |
|
|
|
|
|
|
89
|
|
|
->method('getGiftCard') |
|
90
|
|
|
->with($cardNumber) |
|
91
|
|
|
->willReturn($this->giftCard); |
|
92
|
|
|
// Pin must be set on the gift card to be added. |
|
93
|
|
|
$this->giftCard->expects($this->once()) |
|
|
|
|
|
|
94
|
|
|
->method('setPin') |
|
95
|
|
|
->with($this->identicalTo($pin)) |
|
96
|
|
|
->willReturnSelf(); |
|
97
|
|
|
// When gift card cannot be added to cart, the helper will throw an |
|
98
|
|
|
// exception indicating the failure. |
|
99
|
|
|
$this->helper->expects($this->once()) |
|
100
|
|
|
->method('addGiftCardToOrder') |
|
101
|
|
|
->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container)) |
|
102
|
|
|
->willThrowException(new EbayEnterprise_GiftCard_Exception('TEST EXCEPTION: ' . __METHOD__)); |
|
103
|
|
|
|
|
104
|
|
|
$this->assertSame( |
|
105
|
|
|
$this->observer, |
|
106
|
|
|
EcomDev_Utils_Reflection::invokeRestrictedMethod($this->observer, 'addGiftCard', [$cardNumber, $pin]) |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..