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
|
|
|
|
34
|
|
|
$this->giftCard = $this->getModelMock('ebayenterprise_giftcard/giftcard', ['setPin']); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->helper = $this->getHelperMock('ebayenterprise_giftcard', ['addGiftCardToOrder', '__']); |
37
|
|
|
$this->helper->method('__')->willReturnArgument(0); |
38
|
|
|
|
39
|
|
|
$this->session = $this->getModelMockBuilder('adminhtml/session_quote') |
|
|
|
|
40
|
|
|
->setMethods(null) |
41
|
|
|
->disableOriginalConstructor() |
42
|
|
|
->getMock(); |
43
|
|
|
|
44
|
|
|
$logContext = $this->getHelperMock('ebayenterprise_magelog/context', ['getMetaData']); |
45
|
|
|
$logContext->method('getMetaData')->willReturn([]); |
46
|
|
|
|
47
|
|
|
$this->observer = Mage::getModel( |
48
|
|
|
'ebayenterprise_giftcard/adminhtml_observer', |
49
|
|
|
[ |
50
|
|
|
'container' => $this->container, |
51
|
|
|
'helper' => $this->helper, |
52
|
|
|
'log_context' => $logContext, |
53
|
|
|
'session' => $this->session |
54
|
|
|
] |
55
|
|
|
); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* When adding a gift card to the order, the card should be retrieved from |
60
|
|
|
* the container by card number, have the PIN set on the card and finally |
61
|
|
|
* be added to the order. |
62
|
|
|
* |
63
|
|
|
* @param bool |
64
|
|
|
* @dataProvider provideTrueFalse |
65
|
|
|
*/ |
66
|
|
|
public function testAddGiftCard($success) |
67
|
|
|
{ |
68
|
|
|
$cardNumber = '1111111111111111'; |
69
|
|
|
$pin = '1234'; |
70
|
|
|
|
71
|
|
|
$this->container |
|
|
|
|
72
|
|
|
->method('getGiftCard') |
73
|
|
|
->with($cardNumber) |
74
|
|
|
->willReturn($this->giftCard); |
75
|
|
|
// Pin must be set on the gift card to be added. |
76
|
|
|
$this->giftCard->expects($this->once()) |
|
|
|
|
77
|
|
|
->method('setPin') |
78
|
|
|
->with($this->identicalTo($pin)) |
79
|
|
|
->willReturnSelf(); |
80
|
|
|
|
81
|
|
|
// Helper should be used to add the gift card to the order. When gift |
82
|
|
|
// card is successfully added, it should return self. Otherwise, it will |
83
|
|
|
// thrown an exception. |
84
|
|
|
$addGiftCardInvoker = $this->helper->expects($this->once()) |
85
|
|
|
->method('addGiftCardToOrder') |
86
|
|
|
->with($this->identicalTo($this->giftCard), $this->identicalTo($this->container)); |
87
|
|
|
|
88
|
|
|
if ($success) { |
89
|
|
|
$addGiftCardInvoker->willReturnSelf(); |
90
|
|
|
} else { |
91
|
|
|
$addGiftCardInvoker->willThrowException(new EbayEnterprise_GiftCard_Exception('TEST EXCEPTION: ' . __METHOD__)); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$this->assertSame( |
95
|
|
|
$this->observer, |
96
|
|
|
EcomDev_Utils_Reflection::invokeRestrictedMethod($this->observer, 'addGiftCard', [$cardNumber, $pin]) |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
// When gift card added successfully, expect a success message to have |
100
|
|
|
// been added to the session. When unsuccessful, should add an error |
101
|
|
|
// message to the session. |
102
|
|
|
$expectMessageType = $success ? Mage_Core_Model_Message::SUCCESS : Mage_Core_Model_Message::ERROR; |
103
|
|
|
$this->assertCount(1, $this->session->getMessages()->getItemsByType($expectMessageType)); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
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..