Skip to content

Commit adda280

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #18876: [Backport] Fix Useless use of Cat (by @gelanivishal) - #18835: [Backport] Added Unit Test for WindowsSmtpConfig Plugin (by @vasilii-b) - #18834: [Backport] Cover \Magento\Email\Model\Template\SenderResolver class with Unit test (by @vasilii-b) - #18833: [Backport] Cover \Magento\GiftMessage\Observer\SalesEventQuoteMerge with Unit test (by @vasilii-b) - #17971: Don't format Special Price value for Bundle Product (by @magently) - #18681: [Backport] Set fallback values for email and _website columns to avoid 'undefined index' error in CustomerComposite.php (by @TomashKhamlai) Fixed GitHub Issues: - #17638: Bundle Special Prices not correctly rounded (reported by @Stassy) has been fixed in #17971 by @magently in 2.2-develop branch Related commits: 1. c63d1e6 2. 36570de 3. 1944299
2 parents 4421098 + e84dfd5 commit adda280

File tree

6 files changed

+324
-4
lines changed

6 files changed

+324
-4
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Magento\Ui\DataProvider\Mapper\FormElement as FormElementMapper;
3333
use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper;
3434
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory as AttributeCollectionFactory;
35+
use \Magento\Catalog\Model\Product\Type as ProductType;
3536

3637
/**
3738
* Class Eav
@@ -398,7 +399,7 @@ public function modifyData(array $data)
398399

399400
foreach ($attributes as $attribute) {
400401
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
401-
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
402+
if ($this->isPriceAttribute($attribute, $attributeValue)) {
402403
$attributeValue = $this->formatPrice($attributeValue);
403404
}
404405
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
@@ -409,6 +410,32 @@ public function modifyData(array $data)
409410
return $data;
410411
}
411412

413+
/**
414+
* Obtain if given attribute is a price
415+
*
416+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
417+
* @param string|integer $attributeValue
418+
* @return bool
419+
*/
420+
private function isPriceAttribute(ProductAttributeInterface $attribute, $attributeValue)
421+
{
422+
return $attribute->getFrontendInput() === 'price'
423+
&& is_scalar($attributeValue)
424+
&& !$this->isBundleSpecialPrice($attribute);
425+
}
426+
427+
/**
428+
* Obtain if current product is bundle and given attribute is special_price
429+
*
430+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
431+
* @return bool
432+
*/
433+
private function isBundleSpecialPrice(ProductAttributeInterface $attribute)
434+
{
435+
return $this->locator->getProduct()->getTypeId() === ProductType::TYPE_BUNDLE
436+
&& $attribute->getAttributeCode() === ProductAttributeInterface::CODE_SPECIAL_PRICE;
437+
}
438+
412439
/**
413440
* Resolve data persistence
414441
*

app/code/Magento/CustomerImportExport/Model/Import/CustomerComposite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ public function validateData()
299299
$rows = [];
300300
foreach ($source as $row) {
301301
$rows[] = [
302-
Address::COLUMN_EMAIL => $row[Customer::COLUMN_EMAIL],
303-
Address::COLUMN_WEBSITE => $row[Customer::COLUMN_WEBSITE]
302+
Address::COLUMN_EMAIL => $row[Customer::COLUMN_EMAIL] ?? null,
303+
Address::COLUMN_WEBSITE => $row[Customer::COLUMN_WEBSITE] ?? null
304304
];
305305
}
306306
$source->rewind();
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Email\Test\Unit\Model\Plugin;
9+
10+
use Magento\Email\Model\Plugin\WindowsSmtpConfig;
11+
use Magento\Framework\App\Config\ReinitableConfigInterface;
12+
use Magento\Framework\Mail\TransportInterface;
13+
use Magento\Framework\OsInfo;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
16+
/**
17+
* WindowsSmtpConfigTest
18+
*/
19+
class WindowsSmtpConfigTest extends \PHPUnit\Framework\TestCase
20+
{
21+
/**
22+
* @var WindowsSmtpConfig
23+
*/
24+
private $windowsSmtpConfig;
25+
26+
/**
27+
* @var OsInfo|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $osInfoMock;
30+
31+
/**
32+
* @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $configMock;
35+
36+
/**
37+
* @var TransportInterface
38+
*/
39+
private $transportMock;
40+
41+
/**
42+
* setUp
43+
*
44+
* @return void
45+
*/
46+
public function setUp()
47+
{
48+
$objectManager = new ObjectManager($this);
49+
50+
$this->osInfoMock = $this->createMock(OsInfo::class);
51+
$this->configMock = $this->createMock(ReinitableConfigInterface::class);
52+
$this->transportMock = $this->createMock(TransportInterface::class);
53+
54+
$this->windowsSmtpConfig = $objectManager->getObject(
55+
WindowsSmtpConfig::class,
56+
[
57+
'config' => $this->configMock,
58+
'osInfo' => $this->osInfoMock
59+
]
60+
);
61+
}
62+
63+
/**
64+
* Test if SMTP settings if windows server
65+
*
66+
* @return void
67+
*/
68+
public function testBeforeSendMessageOsWindows()
69+
{
70+
$this->osInfoMock->expects($this->once())
71+
->method('isWindows')
72+
->willReturn(true);
73+
74+
$this->configMock->expects($this->exactly(2))
75+
->method('getValue')
76+
->willReturnMap([
77+
[WindowsSmtpConfig::XML_SMTP_HOST, '127.0.0.1'],
78+
[WindowsSmtpConfig::XML_SMTP_PORT, '80']
79+
]);
80+
81+
$this->windowsSmtpConfig->beforeSendMessage($this->transportMock);
82+
}
83+
84+
/**
85+
* Test if SMTP settings if not windows server
86+
*
87+
* @return void
88+
*/
89+
public function testBeforeSendMessageOsIsWindows()
90+
{
91+
$this->osInfoMock->expects($this->once())
92+
->method('isWindows')
93+
->willReturn(false);
94+
95+
$this->configMock->expects($this->never())
96+
->method('getValue');
97+
98+
$this->windowsSmtpConfig->beforeSendMessage($this->transportMock);
99+
}
100+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Email\Test\Unit\Model\Template;
9+
10+
use Magento\Email\Model\Template\SenderResolver;
11+
use Magento\Framework\Exception\MailException;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
15+
/**
16+
* SenderResolverTest
17+
*/
18+
class SenderResolverTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var SenderResolver
22+
*/
23+
private $senderResolver;
24+
25+
/**
26+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $scopeConfig;
29+
30+
/**
31+
* @return void
32+
*/
33+
public function setUp()
34+
{
35+
$objectManager = new ObjectManager($this);
36+
37+
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
38+
39+
$this->senderResolver = $objectManager->getObject(
40+
SenderResolver::class,
41+
[
42+
'scopeConfig' => $this->scopeConfig
43+
]
44+
);
45+
}
46+
47+
/**
48+
* Test returned information for given sender's name and email
49+
*
50+
* @return void
51+
*/
52+
public function testResolve()
53+
{
54+
$sender = 'general';
55+
$scopeId = null;
56+
57+
$this->scopeConfig->expects($this->exactly(2))
58+
->method('getValue')
59+
->willReturnMap([
60+
[
61+
'trans_email/ident_' . $sender . '/name',
62+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
63+
$scopeId,
64+
'Test Name'
65+
],
66+
[
67+
'trans_email/ident_' . $sender . '/email',
68+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
69+
$scopeId,
70+
'test@email.com'
71+
]
72+
]);
73+
74+
$result = $this->senderResolver->resolve($sender);
75+
76+
$this->assertTrue(isset($result['name']));
77+
$this->assertEquals('Test Name', $result['name']);
78+
79+
$this->assertTrue(isset($result['email']));
80+
$this->assertEquals('test@email.com', $result['email']);
81+
}
82+
83+
/**
84+
* Test if exception is thrown in case there is no name or email in result
85+
*
86+
* @dataProvider dataProvidedSenderArray
87+
* @param array $sender
88+
*
89+
* @return void
90+
*/
91+
public function testResolveThrowException(array $sender)
92+
{
93+
$this->expectExceptionMessage('Invalid sender data');
94+
$this->expectException(MailException::class);
95+
$this->senderResolver->resolve($sender);
96+
}
97+
98+
/**
99+
* @return array
100+
*/
101+
public function dataProvidedSenderArray()
102+
{
103+
return [
104+
[
105+
['name' => 'Name']
106+
],
107+
[
108+
['email' => 'test@email.com']
109+
]
110+
];
111+
}
112+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\GiftMessage\Test\Unit\Observer;
10+
11+
use Magento\GiftMessage\Observer\SalesEventQuoteMerge;
12+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\Event\Observer;
14+
use Magento\Quote\Model\Quote;
15+
16+
/**
17+
* SalesEventQuoteMergeTest
18+
*/
19+
class SalesEventQuoteMergeTest extends \PHPUnit\Framework\TestCase
20+
{
21+
22+
/**
23+
* @var SalesEventQuoteMerge
24+
*/
25+
private $salesEventQuoteMerge;
26+
27+
/**
28+
* @return void
29+
*/
30+
public function setUp()
31+
{
32+
$objectManger = new ObjectManager($this);
33+
$this->salesEventQuoteMerge = $objectManger->getObject(SalesEventQuoteMerge::class);
34+
}
35+
36+
/**
37+
* @dataProvider dataProviderGiftMessageId
38+
*
39+
* @param null|int $giftMessageId
40+
*
41+
* @return void
42+
*/
43+
public function testExecute($giftMessageId)
44+
{
45+
$sourceQuoteMock = $this->createPartialMock(Quote::class, ['getGiftMessageId']);
46+
$sourceQuoteMock->expects($this->once())
47+
->method('getGiftMessageId')
48+
->willReturn($giftMessageId);
49+
50+
$targetQuoteMock = $this->createPartialMock(Quote::class, ['setGiftMessageId']);
51+
52+
if ($giftMessageId) {
53+
$targetQuoteMock->expects($this->once())
54+
->method('setGiftMessageId');
55+
} else {
56+
$targetQuoteMock->expects($this->never())
57+
->method('setGiftMessageId');
58+
}
59+
60+
$observer = $this->createMock(Observer::class);
61+
$observer->expects($this->exactly(2))
62+
->method('getData')
63+
->willReturnMap([
64+
['quote', null, $targetQuoteMock],
65+
['source', null, $sourceQuoteMock]
66+
]);
67+
68+
$this->salesEventQuoteMerge->execute($observer);
69+
}
70+
71+
/**
72+
* @return array
73+
*/
74+
public function dataProviderGiftMessageId(): array
75+
{
76+
return [
77+
[null],
78+
[1]
79+
];
80+
}
81+
}

dev/travis/before_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ case $TEST_SUITE in
7272
--base-path="$TRAVIS_BUILD_DIR" \
7373
--repo='https://github.com/magento/magento2.git' \
7474
--branch="$TRAVIS_BRANCH"
75-
cat "$changed_files_ce" | sed 's/^/ + including /'
75+
sed 's/^/ + including /' "$changed_files_ce"
7676

7777
cd ../../..
7878
;;

0 commit comments

Comments
 (0)