Skip to content

Commit b56df96

Browse files
author
Alexander Akimov
authored
Merge pull request #581 from magento-folks/bugfix
[Folks] Bugs
2 parents e643a67 + c67d8de commit b56df96

File tree

31 files changed

+642
-52
lines changed

31 files changed

+642
-52
lines changed

app/code/Magento/Checkout/Controller/Cart/CouponPost.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,26 +90,17 @@ public function execute()
9090

9191
if ($codeLength) {
9292
$escaper = $this->_objectManager->get(\Magento\Framework\Escaper::class);
93+
$coupon = $this->couponFactory->create();
94+
$coupon->load($couponCode, 'code');
9395
if (!$itemsCount) {
94-
if ($isCodeLengthValid) {
95-
$coupon = $this->couponFactory->create();
96-
$coupon->load($couponCode, 'code');
97-
if ($coupon->getId()) {
98-
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
99-
$this->messageManager->addSuccess(
100-
__(
101-
'You used coupon code "%1".',
102-
$escaper->escapeHtml($couponCode)
103-
)
104-
);
105-
} else {
106-
$this->messageManager->addError(
107-
__(
108-
'The coupon code "%1" is not valid.',
109-
$escaper->escapeHtml($couponCode)
110-
)
111-
);
112-
}
96+
if ($isCodeLengthValid && $coupon->getId()) {
97+
$this->_checkoutSession->getQuote()->setCouponCode($couponCode)->save();
98+
$this->messageManager->addSuccess(
99+
__(
100+
'You used coupon code "%1".',
101+
$escaper->escapeHtml($couponCode)
102+
)
103+
);
113104
} else {
114105
$this->messageManager->addError(
115106
__(
@@ -119,7 +110,7 @@ public function execute()
119110
);
120111
}
121112
} else {
122-
if ($isCodeLengthValid && $couponCode == $cartQuote->getCouponCode()) {
113+
if ($isCodeLengthValid && $coupon->getId() && $couponCode == $cartQuote->getCouponCode()) {
123114
$this->messageManager->addSuccess(
124115
__(
125116
'You used coupon code "%1".',

app/code/Magento/Checkout/Test/Unit/Controller/Cart/CouponPostTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class CouponPostTest extends \PHPUnit_Framework_TestCase
6969
*/
7070
protected $quoteRepository;
7171

72+
/**
73+
* @var \PHPUnit_Framework_MockObject_MockObject
74+
*/
75+
private $redirect;
76+
77+
/**
78+
* @var \PHPUnit_Framework_MockObject_MockObject
79+
*/
80+
private $redirectFactory;
81+
7282
/**
7383
* @return void
7484
*/
@@ -204,6 +214,12 @@ public function testExecuteWithGoodCouponAndItems()
204214
->method('getCouponCode')
205215
->willReturn('OLDCODE');
206216

217+
$coupon = $this->getMock(\Magento\SalesRule\Model\Coupon::class, [], [], '', false);
218+
$this->couponFactory->expects($this->once())
219+
->method('create')
220+
->willReturn($coupon);
221+
$coupon->expects($this->once())->method('load')->willReturnSelf();
222+
$coupon->expects($this->once())->method('getId')->willReturn(1);
207223
$this->quote->expects($this->any())
208224
->method('getItemsCount')
209225
->willReturn(1);

app/code/Magento/Eav/Model/AttributeManagement.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
*/
77
namespace Magento\Eav\Model;
88

9+
use Magento\Framework\App\ObjectManager;
910
use Magento\Framework\Exception\InputException;
1011
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Framework\Exception\StateException;
1213

14+
/**
15+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16+
*/
1317
class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterface
1418
{
1519
/**
@@ -19,6 +23,7 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
1923

2024
/**
2125
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
26+
* @deprecated please use instead \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
2227
*/
2328
protected $attributeCollection;
2429

@@ -47,6 +52,11 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
4752
*/
4853
protected $attributeResource;
4954

55+
/**
56+
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
57+
*/
58+
private $attributeCollectionFactory;
59+
5060
/**
5161
* @param \Magento\Eav\Api\AttributeSetRepositoryInterface $setRepository
5262
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection
@@ -154,11 +164,26 @@ public function getAttributes($entityType, $attributeSetId)
154164
if (!$attributeSet->getAttributeSetId() || $attributeSet->getEntityTypeId() != $requiredEntityTypeId) {
155165
throw NoSuchEntityException::singleField('attributeSetId', $attributeSetId);
156166
}
157-
158-
$attributeCollection = $this->attributeCollection
159-
->setAttributeSetFilter($attributeSet->getAttributeSetId())
160-
->load();
167+
/** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection */
168+
$attributeCollection = $this->getCollectionFactory()->create();
169+
$attributeCollection->setAttributeSetFilter($attributeSet->getAttributeSetId())->load();
161170

162171
return $attributeCollection->getItems();
163172
}
173+
174+
/**
175+
* Retrieve collection factory
176+
*
177+
* @deprecated
178+
* @return \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
179+
*/
180+
private function getCollectionFactory()
181+
{
182+
if ($this->attributeCollectionFactory === null) {
183+
$this->attributeCollectionFactory = ObjectManager::getInstance()->create(
184+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory::class
185+
);
186+
}
187+
return $this->attributeCollectionFactory;
188+
}
164189
}

app/code/Magento/Eav/Test/Unit/Model/AttributeManagementTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ public function testGetAttributes()
371371
$entityType = 'type';
372372
$attributeSetId = 148;
373373

374+
$attributeCollectionFactoryMock = $this->getMock(
375+
\Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory::class,
376+
['create'],
377+
[],
378+
'',
379+
false
380+
);
381+
$attributeCollectionFactoryMock->expects($this->once())
382+
->method('create')
383+
->willReturn($this->attributeCollectionMock);
384+
385+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
386+
$objectManager->setBackwardCompatibleProperty(
387+
$this->model,
388+
'attributeCollectionFactory',
389+
$attributeCollectionFactoryMock
390+
);
391+
374392
$attributeSetMock = $this->getMock(\Magento\Eav\Api\Data\AttributeSetInterface::class, [], [], '', false);
375393
$this->setRepositoryMock->expects($this->once())
376394
->method('get')

app/code/Magento/Sales/Model/Order/Payment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ public function getAuthorizationTransaction()
12891289
*/
12901290
public function isCaptureFinal($amountToCapture)
12911291
{
1292-
$total = $this->getOrder()->getTotalDue();
1292+
$total = $this->getOrder()->getBaseTotalDue();
12931293
return $this->formatAmount($total, true) == $this->formatAmount($amountToCapture, true);
12941294
}
12951295

app/code/Magento/Sales/Test/Unit/Model/Order/PaymentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ public function testIsCaptureFinal()
15481548
$partialAmount = 12.00;
15491549

15501550
$this->orderMock->expects(static::exactly(2))
1551-
->method('getTotalDue')
1551+
->method('getBaseTotalDue')
15521552
->willReturn($amount);
15531553

15541554
static::assertFalse($this->payment->isCaptureFinal($partialAmount));

app/code/Magento/Swatches/Helper/Data.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class Data
6363
*/
6464
protected $imageHelper;
6565

66+
/**
67+
* Product metadata pool
68+
*
69+
* @var \Magento\Framework\EntityManager\MetadataPool
70+
*/
71+
private $metadataPool;
72+
6673
/**
6774
* Data key which should populated to Attribute entity from "additional_data" field
6875
*
@@ -196,7 +203,13 @@ public function loadVariationByFallback(Product $parentProduct, array $attribute
196203
}
197204

198205
$productCollection = $this->productCollectionFactory->create();
199-
$this->addFilterByParent($productCollection, $parentProduct->getId());
206+
207+
$productLinkedFiled = $this->getMetadataPool()
208+
->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
209+
->getLinkField();
210+
$parentId = $parentProduct->getData($productLinkedFiled);
211+
212+
$this->addFilterByParent($productCollection, $parentId);
200213

201214
$configurableAttributes = $this->getAttributesFromConfigurable($parentProduct);
202215
$allAttributesArray = [];
@@ -491,4 +504,19 @@ public function isTextSwatch(Attribute $attribute)
491504
}
492505
return $attribute->getData(Swatch::SWATCH_INPUT_TYPE_KEY) == Swatch::SWATCH_INPUT_TYPE_TEXT;
493506
}
507+
508+
/**
509+
* Get product metadata pool.
510+
*
511+
* @return \Magento\Framework\EntityManager\MetadataPool
512+
* @deprecared
513+
*/
514+
protected function getMetadataPool()
515+
{
516+
if (!$this->metadataPool) {
517+
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
518+
->get(\Magento\Framework\EntityManager\MetadataPool::class);
519+
}
520+
return $this->metadataPool;
521+
}
494522
}

app/code/Magento/Swatches/Test/Unit/Helper/DataTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class DataTest extends \PHPUnit_Framework_TestCase
4646
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Api\ProductRepositoryInterface */
4747
protected $productRepoMock;
4848

49+
/** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\EntityManager\MetadataPool*/
50+
private $metaDataPoolMock;
51+
4952
protected function setUp()
5053
{
5154
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
@@ -108,7 +111,13 @@ protected function setUp()
108111
'',
109112
false
110113
);
111-
114+
$this->metaDataPoolMock = $this->getMock(
115+
\Magento\Framework\EntityManager\MetadataPool::class,
116+
[],
117+
[],
118+
'',
119+
false
120+
);
112121
$this->swatchHelperObject = $this->objectManager->getObject(
113122
\Magento\Swatches\Helper\Data::class,
114123
[
@@ -120,6 +129,11 @@ protected function setUp()
120129
'imageHelper' => $this->imageHelperMock,
121130
]
122131
);
132+
$this->objectManager->setBackwardCompatibleProperty(
133+
$this->swatchHelperObject,
134+
'metadataPool',
135+
$this->metaDataPoolMock
136+
);
123137
}
124138

125139
public function dataForAdditionalData()
@@ -246,12 +260,16 @@ public function dataForVariationWithSwatchImage()
246260
*/
247261
public function testLoadVariationByFallback($product)
248262
{
263+
$metadataMock = $this->getMock(\Magento\Framework\EntityManager\EntityMetadataInterface::class);
264+
$this->metaDataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadataMock);
265+
$metadataMock->expects($this->once())->method('getLinkField')->willReturn('id');
266+
249267
$this->getSwatchAttributes($product);
250268

251269
$this->prepareVariationCollection();
252270

253271
$this->productCollectionMock->method('getFirstItem')->willReturn($this->productMock);
254-
$this->productMock->method('getId')->willReturn(95);
272+
$this->productMock->method('getData')->with('id')->willReturn(95);
255273
$this->productModelFactoryMock->method('create')->willReturn($this->productMock);
256274
$this->productMock->method('load')->with(95)->will($this->returnSelf());
257275

app/code/Magento/Widget/Model/ResourceModel/Widget/Instance/Options/ThemeId.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*/
1111
namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;
1212

13+
/**
14+
* @deprecated created new class that correctly loads theme options and whose name follows naming convention
15+
* @see \Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes
16+
*/
1317
class ThemeId implements \Magento\Framework\Option\ArrayInterface
1418
{
1519
/**
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Widget\Model\ResourceModel\Widget\Instance\Options;
7+
8+
use Magento\Framework\Data\OptionSourceInterface;
9+
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
10+
11+
/**
12+
* Option source of the widget theme property.
13+
*
14+
* Can be used as a data provider for UI components that shows possible themes as a list.
15+
*/
16+
class Themes implements OptionSourceInterface
17+
{
18+
/**
19+
* @var ThemeCollectionFactory
20+
*/
21+
private $themeCollectionFactory;
22+
23+
/**
24+
* @param ThemeCollectionFactory $themeCollectionFactory
25+
*/
26+
public function __construct(ThemeCollectionFactory $themeCollectionFactory)
27+
{
28+
$this->themeCollectionFactory = $themeCollectionFactory;
29+
}
30+
31+
/**
32+
* Return array of options as value-label pairs
33+
*
34+
* @return array Format: array('<theme ID>' => '<theme label>', ...)
35+
*/
36+
public function toOptionArray()
37+
{
38+
// Load only visible themes that are used in frontend area
39+
return $this->themeCollectionFactory->create()->loadRegisteredThemes()->toOptionHash();
40+
}
41+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Widget\Test\Unit\Model\ResourceModel\Widget\Instance\Options;
7+
8+
use Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes;
9+
use Magento\Theme\Model\ResourceModel\Theme\Collection as ThemeCollection;
10+
use Magento\Theme\Model\ResourceModel\Theme\CollectionFactory as ThemeCollectionFactory;
11+
12+
/**
13+
* Test class for \Magento\Widget\Model\ResourceModel\Widget\Instance\Options\Themes
14+
*/
15+
class ThemesTest extends \PHPUnit_Framework_TestCase
16+
{
17+
/**
18+
* @var Themes
19+
*/
20+
private $model;
21+
22+
/**
23+
* @var \PHPUnit_Framework_MockObject_MockObject
24+
*/
25+
private $themeCollectionFactoryMock;
26+
27+
/**
28+
* @var \PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $themeCollectionMock;
31+
32+
protected function setUp()
33+
{
34+
$this->themeCollectionMock = $this->getMock(ThemeCollection::class, [], [], '', false);
35+
$this->themeCollectionFactoryMock = $this->getMock(ThemeCollectionFactory::class, ['create'], [], '', false);
36+
$this->model = new Themes(
37+
$this->themeCollectionFactoryMock
38+
);
39+
}
40+
41+
public function testToOptionArray()
42+
{
43+
$expectedResult = [
44+
1 => 'Theme Label',
45+
];
46+
$this->themeCollectionFactoryMock->expects($this->once())
47+
->method('create')
48+
->willReturn($this->themeCollectionMock);
49+
50+
$this->themeCollectionMock->expects($this->once())->method('loadRegisteredThemes')->willReturnSelf();
51+
$this->themeCollectionMock->expects($this->once())->method('toOptionHash')->willReturn($expectedResult);
52+
53+
$this->assertEquals($expectedResult, $this->model->toOptionArray());
54+
}
55+
}

0 commit comments

Comments
 (0)