Skip to content

Commit f2ddf34

Browse files
author
Cari Spruiell
committed
Merge remote-tracking branch 'origin/MAGETWO-35023-Code-Coverage-Guest-Sales-And-Checkout-APIs' into MAGETWO-35023-Code-Coverage-Guest-Sales-And-Checkout-APIs
2 parents ede3748 + 98c56cf commit f2ddf34

File tree

4 files changed

+91
-268
lines changed

4 files changed

+91
-268
lines changed

app/code/Magento/Quote/Model/GuestCart/GuestCouponManagement.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,30 @@
1515
/**
1616
* Coupon management class for guest carts.
1717
*/
18-
class GuestCouponManagement extends CouponManagement implements GuestCouponManagementInterface
18+
class GuestCouponManagement implements GuestCouponManagementInterface
1919
{
2020
/**
2121
* @var QuoteIdMaskFactory
2222
*/
2323
private $quoteIdMaskFactory;
2424

25+
/**
26+
* @var CouponManagement
27+
*/
28+
private $couponManagement;
29+
2530
/**
2631
* Constructs a coupon read service object.
2732
*
28-
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository Quote repository.
33+
* @param CouponManagement $couponManagement
2934
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3035
*/
3136
public function __construct(
32-
\Magento\Quote\Model\QuoteRepository $quoteRepository,
37+
CouponManagement $couponManagement,
3338
QuoteIdMaskFactory $quoteIdMaskFactory
3439
) {
3540
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
36-
parent::__construct($quoteRepository);
41+
$this->couponManagement = $couponManagement;
3742
}
3843

3944
/**
@@ -43,7 +48,7 @@ public function get($cartId)
4348
{
4449
/** @var $quoteIdMask QuoteIdMask */
4550
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
46-
return parent::get($quoteIdMask->getId());
51+
return $this->couponManagement->get($quoteIdMask->getId());
4752
}
4853

4954
/**
@@ -53,7 +58,7 @@ public function set($cartId, $couponCode)
5358
{
5459
/** @var $quoteIdMask QuoteIdMask */
5560
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
56-
return parent::set($quoteIdMask->getId(), $couponCode);
61+
return $this->couponManagement->set($quoteIdMask->getId(), $couponCode);
5762
}
5863

5964
/**
@@ -63,6 +68,6 @@ public function remove($cartId)
6368
{
6469
/** @var $quoteIdMask QuoteIdMask */
6570
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
66-
return parent::remove($quoteIdMask->getId());
71+
return $this->couponManagement->remove($quoteIdMask->getId());
6772
}
6873
}

app/code/Magento/Quote/Model/GuestCart/GuestPaymentMethodManagement.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,30 @@
1313
/**
1414
* Payment method management class for guest carts.
1515
*/
16-
class GuestPaymentMethodManagement extends PaymentMethodManagement implements GuestPaymentMethodManagementInterface
16+
class GuestPaymentMethodManagement implements GuestPaymentMethodManagementInterface
1717
{
1818
/**
1919
* @var QuoteIdMaskFactory
2020
*/
2121
protected $quoteIdMaskFactory;
2222

23+
/**
24+
* @var PaymentMethodManagement
25+
*/
26+
protected $paymentMethodManagement;
27+
2328
/**
2429
* Initialize dependencies.
2530
*
26-
* @param \Magento\Quote\Model\QuoteRepository $quoteRepository
27-
* @param \Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator
28-
* @param \Magento\Payment\Model\MethodList $methodList
31+
* @param PaymentMethodManagement $paymentMethodManagement
2932
* @param QuoteIdMaskFactory $quoteIdMaskFactory
3033
*/
3134
public function __construct(
32-
\Magento\Quote\Model\QuoteRepository $quoteRepository,
33-
\Magento\Payment\Model\Checks\ZeroTotal $zeroTotalValidator,
34-
\Magento\Payment\Model\MethodList $methodList,
35+
PaymentMethodManagement $paymentMethodManagement,
3536
QuoteIdMaskFactory $quoteIdMaskFactory
3637
) {
37-
parent::__construct($quoteRepository, $zeroTotalValidator, $methodList);
3838
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
39+
$this->paymentMethodManagement = $paymentMethodManagement;
3940
}
4041

4142
/**
@@ -45,7 +46,7 @@ public function set($cartId, \Magento\Quote\Api\Data\PaymentInterface $method)
4546
{
4647
/** @var $quoteIdMask QuoteIdMask */
4748
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
48-
return parent::set($quoteIdMask->getId(), $method);
49+
return $this->paymentMethodManagement->set($quoteIdMask->getId(), $method);
4950
}
5051

5152
/**
@@ -55,7 +56,7 @@ public function get($cartId)
5556
{
5657
/** @var $quoteIdMask QuoteIdMask */
5758
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
58-
return parent::get($quoteIdMask->getId());
59+
return $this->paymentMethodManagement->get($quoteIdMask->getId());
5960
}
6061

6162
/**
@@ -65,6 +66,6 @@ public function getList($cartId)
6566
{
6667
/** @var $quoteIdMask QuoteIdMask */
6768
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
68-
return parent::getList($quoteIdMask->getId());
69+
return $this->paymentMethodManagement->getList($quoteIdMask->getId());
6970
}
7071
}

app/code/Magento/Quote/Test/Unit/Model/GuestCart/GuestCouponManagementTest.php

Lines changed: 30 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -17,149 +17,72 @@ class GuestCouponManagementTest extends \PHPUnit_Framework_TestCase
1717
/**
1818
* @var \PHPUnit_Framework_MockObject_MockObject
1919
*/
20-
protected $quoteRepositoryMock;
20+
protected $quoteIdMaskFactoryMock;
2121

2222
/**
2323
* @var \PHPUnit_Framework_MockObject_MockObject
2424
*/
25-
protected $quoteMock;
25+
protected $quoteIdMaskMock;
2626

2727
/**
2828
* @var \PHPUnit_Framework_MockObject_MockObject
2929
*/
30-
protected $quoteAddressMock;
30+
protected $couponManagementMock;
3131

3232
/**
33-
* @var \PHPUnit_Framework_MockObject_MockObject
33+
* @var string
3434
*/
35-
protected $quoteIdMaskFactoryMock;
35+
protected $maskedCartId;
3636

3737
/**
38-
* @var \PHPUnit_Framework_MockObject_MockObject
38+
* @var int
3939
*/
40-
protected $quoteIdMaskMock;
40+
protected $cartId;
41+
42+
/**
43+
* @var string
44+
*/
45+
protected $couponCode;
4146

4247
protected function setUp()
4348
{
4449
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
50+
$this->couponManagementMock = $this->getMock( 'Magento\Quote\Model\CouponManagement', [], [], '', false);
4551

46-
$this->quoteRepositoryMock = $this->getMock('Magento\Quote\Model\QuoteRepository', [], [], '', false);
47-
$this->quoteMock = $this->getMock(
48-
'Magento\Quote\Model\Quote',
49-
[
50-
'getItemsCount',
51-
'setCouponCode',
52-
'collectTotals',
53-
'save',
54-
'getShippingAddress',
55-
'getCouponCode'
56-
],
57-
[],
58-
'',
59-
false
60-
);
61-
$this->quoteAddressMock = $this->getMock(
62-
'Magento\Quote\Model\Quote\Address',
63-
[
64-
'setCollectShippingRates'
65-
],
66-
[],
67-
'',
68-
false);
52+
$this->couponCode = 'test_coupon_code';
53+
$this->maskedCartId = 'f216207248d65c789b17be8545e0aa73';
54+
$this->cartId = 123;
6955

70-
$this->quoteIdMaskFactoryMock = $this->getMock('Magento\Quote\Model\QuoteIdMaskFactory', [], [], '', false);
71-
$this->quoteIdMaskMock = $this->getMock('Magento\Quote\Model\QuoteIdMask', [], [], '', false);
56+
$guestCartTestHelper = new GuestCartTestHelper($this);
57+
list($this->quoteIdMaskFactoryMock, $this->quoteIdMaskMock) = $guestCartTestHelper->mockQuoteIdMask(
58+
$this->maskedCartId,
59+
$this->cartId
60+
);
7261

7362
$this->model = $objectManager->getObject(
7463
'Magento\Quote\Model\GuestCart\GuestCouponManagement',
7564
[
76-
'quoteRepository' => $this->quoteRepositoryMock,
65+
'couponManagement' => $this->couponManagementMock,
7766
'quoteIdMaskFactory' => $this->quoteIdMaskFactoryMock
7867
]
7968
);
8069
}
8170

82-
public function testGetCoupon()
71+
public function testGet()
8372
{
84-
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
85-
$cartId = 11;
86-
$couponCode = 'test_coupon_code';
87-
88-
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
89-
$this->quoteIdMaskMock->expects($this->once())
90-
->method('load')
91-
->with($maskedCartId, 'masked_id')
92-
->willReturn($this->quoteIdMaskMock);
93-
$this->quoteIdMaskMock->expects($this->once())
94-
->method('getId')
95-
->willReturn($cartId);
96-
97-
$quoteMock = $this->getMock('Magento\Quote\Model\Quote', ['getCouponCode', '__wakeup'], [], '', false);
98-
$quoteMock->expects($this->any())->method('getCouponCode')->will($this->returnValue($couponCode));
99-
100-
$this->quoteRepositoryMock->expects($this->once())
101-
->method('getActive')
102-
->with($cartId)
103-
->will($this->returnValue($quoteMock));
104-
105-
$this->assertEquals($couponCode, $this->model->get($maskedCartId));
73+
$this->couponManagementMock->expects($this->once())->method('get')->willReturn($this->couponCode);
74+
$this->assertEquals($this->couponCode, $this->model->get($this->maskedCartId));
10675
}
10776

10877
public function testSet()
10978
{
110-
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
111-
$cartId = 33;
112-
$couponCode = '153a-ABC';
113-
114-
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
115-
$this->quoteIdMaskMock->expects($this->once())
116-
->method('load')
117-
->with($maskedCartId, 'masked_id')
118-
->willReturn($this->quoteIdMaskMock);
119-
$this->quoteIdMaskMock->expects($this->once())
120-
->method('getId')
121-
->willReturn($cartId);
122-
123-
$this->quoteRepositoryMock->expects($this->once())
124-
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
125-
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
126-
$this->quoteMock->expects($this->once())
127-
->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
128-
$this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true);
129-
$this->quoteMock->expects($this->once())->method('setCouponCode')->with($couponCode);
130-
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
131-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
132-
$this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue($couponCode));
133-
134-
$this->assertTrue($this->model->set($maskedCartId, $couponCode));
79+
$this->couponManagementMock->expects($this->once())->method('set')->willReturn(true);
80+
$this->assertTrue($this->model->set($this->maskedCartId, $this->couponCode));
13581
}
13682

137-
public function testDelete()
83+
public function testRemove()
13884
{
139-
$maskedCartId = 'f216207248d65c789b17be8545e0aa73';
140-
$cartId = 65;
141-
142-
$this->quoteIdMaskFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteIdMaskMock);
143-
$this->quoteIdMaskMock->expects($this->once())
144-
->method('load')
145-
->with($maskedCartId, 'masked_id')
146-
->willReturn($this->quoteIdMaskMock);
147-
$this->quoteIdMaskMock->expects($this->once())
148-
->method('getId')
149-
->willReturn($cartId);
150-
151-
$this->quoteRepositoryMock->expects($this->once())
152-
->method('getActive')->with($cartId)->will($this->returnValue($this->quoteMock));
153-
$this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(12));
154-
$this->quoteMock->expects($this->once())
155-
->method('getShippingAddress')->will($this->returnValue($this->quoteAddressMock));
156-
$this->quoteAddressMock->expects($this->once())->method('setCollectShippingRates')->with(true);
157-
$this->quoteMock->expects($this->once())->method('setCouponCode')->with('');
158-
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
159-
$this->quoteMock->expects($this->once())->method('collectTotals')->will($this->returnValue($this->quoteMock));
160-
$this->quoteRepositoryMock->expects($this->once())->method('save')->with($this->quoteMock);
161-
$this->quoteMock->expects($this->once())->method('getCouponCode')->will($this->returnValue(''));
162-
163-
$this->assertTrue($this->model->remove($maskedCartId));
85+
$this->couponManagementMock->expects($this->once())->method('remove')->willReturn(true);
86+
$this->assertTrue($this->model->remove($this->maskedCartId));
16487
}
16588
}

0 commit comments

Comments
 (0)