Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.3-develop' into project_pepe
Browse files Browse the repository at this point in the history
  • Loading branch information
lfolco committed Jul 4, 2019
2 parents 47a9ed7 + 5588999 commit b631f9d
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 74 deletions.
23 changes: 23 additions & 0 deletions app/code/Magento/Backend/Test/Mftf/Data/CookieConfigData.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="ChangedCookieDomainForMainWebsiteConfigData">
<data key="path">web/cookie/cookie_domain</data>
<data key="scope">website</data>
<data key="scope_code">base</data>
<data key="value">testDomain.com</data>
</entity>
<entity name="EmptyCookieDomainForMainWebsiteConfigData">
<data key="path">web/cookie/cookie_domain</data>
<data key="scope">website</data>
<data key="scope_code">base</data>
<data key="value">''</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminLoginAfterChangeCookieDomainTest">
<annotations>
<features value="Backend"/>
<stories value="Login on the Admin Backend"/>
<title value="Admin user can login after changing cookie domain on main website scope without changing cookie domain on default scope"/>
<description value="Admin user can login after changing cookie domain on main website scope without changing cookie domain on default scope"/>
<severity value="CRITICAL"/>
<testCaseId value="MC-17847"/>
<useCaseId value="MC-17275"/>
<group value="backend"/>
</annotations>
<before>
<magentoCLI command="config:set {{ChangedCookieDomainForMainWebsiteConfigData.path}} --scope={{ChangedCookieDomainForMainWebsiteConfigData.scope}} --scope-code={{ChangedCookieDomainForMainWebsiteConfigData.scope_code}} {{ChangedCookieDomainForMainWebsiteConfigData.value}}" stepKey="changeDomainForMainWebsiteBeforeTestRun"/>
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
</before>
<after>
<magentoCLI command="config:set {{EmptyCookieDomainForMainWebsiteConfigData.path}} --scope={{EmptyCookieDomainForMainWebsiteConfigData.scope}} --scope-code={{EmptyCookieDomainForMainWebsiteConfigData.scope_code}} {{EmptyCookieDomainForMainWebsiteConfigData.value}}" stepKey="changeDomainForMainWebsiteAfterTestComplete"/>
<magentoCLI command="cache:flush config" stepKey="flushCacheAfterTestComplete"/>
</after>
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
<actionGroup ref="AssertAdminDashboardPageIsVisibleActionGroup" stepKey="seeDashboardPage"/>
<actionGroup ref="logout" stepKey="logoutFromAdmin"/>
</test>
</tests>
1 change: 1 addition & 0 deletions app/code/Magento/Backend/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<arguments>
<argument name="lifetimePath" xsi:type="const">Magento\Backend\Model\Auth\Session::XML_PATH_SESSION_LIFETIME</argument>
<argument name="sessionName" xsi:type="const">Magento\Backend\Model\Session\AdminConfig::SESSION_NAME_ADMIN</argument>
<argument name="scopeType" xsi:type="const">Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT</argument>
</arguments>
</type>
<type name="Magento\Framework\View\Result\PageFactory">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use Magento\Store\Model\StoreManagerInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Test for Magento\OfflineShipping\Model\Quote\Address\FreeShipping class.
*/
class FreeShippingTest extends \PHPUnit\Framework\TestCase
{
private static $websiteId = 1;
Expand Down Expand Up @@ -77,12 +80,14 @@ public function testIsFreeShipping(int $addressFree, int $fItemFree, int $sItemF
[$fItem],
[$sItem]
)
->willReturnCallback(function () use ($fItem, $sItem, $addressFree, $fItemFree, $sItemFree) {
// emulate behavior of cart rule calculator
$fItem->getAddress()->setFreeShipping($addressFree);
$fItem->setFreeShipping($fItemFree);
$sItem->setFreeShipping($sItemFree);
});
->willReturnCallback(
function () use ($fItem, $sItem, $addressFree, $fItemFree, $sItemFree) {
// emulate behavior of cart rule calculator
$fItem->getAddress()->setFreeShipping($addressFree);
$fItem->setFreeShipping($fItemFree);
$sItem->setFreeShipping($sItemFree);
}
);

$actual = $this->model->isFreeShipping($quote, $items);
self::assertEquals($expected, $actual);
Expand Down Expand Up @@ -133,8 +138,11 @@ private function getQuote(Address $address): Quote
->disableOriginalConstructor()
->setMethods(
[
'getCouponCode', 'getCustomerGroupId', 'getShippingAddress', 'getStoreId', 'getItemsQty',
'getVirtualItemsQty'
'getCouponCode',
'getCustomerGroupId',
'getShippingAddress',
'getStoreId',
'isVirtual'
]
)
->getMock();
Expand All @@ -147,10 +155,8 @@ private function getQuote(Address $address): Quote
->willReturn(self::$couponCode);
$quote->method('getShippingAddress')
->willReturn($address);
$quote->method('getItemsQty')
->willReturn(2);
$quote->method('getVirtualItemsQty')
->willReturn(0);
$quote->method('isVirtual')
->willReturn(false);

return $quote;
}
Expand Down
41 changes: 22 additions & 19 deletions app/code/Magento/Quote/Model/Quote/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public function beforeSave()
*/
public function getAddress()
{
if ($this->getQuote()->getItemsQty() == $this->getQuote()->getVirtualItemsQty()) {
if ($this->getQuote()->isVirtual()) {
$address = $this->getQuote()->getBillingAddress();
} else {
$address = $this->getQuote()->getShippingAddress();
Expand All @@ -282,7 +282,7 @@ public function getAddress()
/**
* Declare quote model object
*
* @param \Magento\Quote\Model\Quote $quote
* @param \Magento\Quote\Model\Quote $quote
* @return $this
*/
public function setQuote(\Magento\Quote\Model\Quote $quote)
Expand Down Expand Up @@ -719,6 +719,7 @@ public function getOptionByCode($code)

/**
* Checks that item model has data changes.
*
* Call save item options if model isn't need to save in DB
*
* @return boolean
Expand Down Expand Up @@ -813,8 +814,9 @@ public function __clone()
}

/**
* Returns formatted buy request - object, holding request received from
* product view page with keys and options for configured product
* Get formatted buy request.
*
* Returns object, holding request received from product view page with keys and options for configured product.
*
* @return \Magento\Framework\DataObject
*/
Expand Down Expand Up @@ -863,6 +865,7 @@ public function setHasError($flag)

/**
* Clears list of errors, associated with this quote item.
*
* Also automatically removes error-flag from oneself.
*
* @return $this
Expand All @@ -876,6 +879,7 @@ protected function _clearErrorInfo()

/**
* Adds error information to the quote item.
*
* Automatically sets error flag.
*
* @param string|null $origin Usually a name of module, that embeds error
Expand Down Expand Up @@ -930,97 +934,96 @@ public function removeErrorInfosByParams($params)
}

/**
* @inheritdoc
* @codeCoverageIgnoreStart
*
* {@inheritdoc}
*/
public function getItemId()
{
return $this->getData(self::KEY_ITEM_ID);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setItemId($itemID)
{
return $this->setData(self::KEY_ITEM_ID, $itemID);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getSku()
{
return $this->getData(self::KEY_SKU);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setSku($sku)
{
return $this->setData(self::KEY_SKU, $sku);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getQty()
{
return $this->getData(self::KEY_QTY);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getName()
{
return $this->getData(self::KEY_NAME);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setName($name)
{
return $this->setData(self::KEY_NAME, $name);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getPrice()
{
return $this->getData(self::KEY_PRICE);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setPrice($price)
{
return $this->setData(self::KEY_PRICE, $price);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setProductType($productType)
{
return $this->setData(self::KEY_PRODUCT_TYPE, $productType);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getQuoteId()
{
return $this->getData(self::KEY_QUOTE_ID);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function setQuoteId($quoteId)
{
Expand Down Expand Up @@ -1051,7 +1054,7 @@ public function setProductOption(\Magento\Quote\Api\Data\ProductOptionInterface
//@codeCoverageIgnoreEnd

/**
* {@inheritdoc}
* @inheritdoc
*
* @return \Magento\Quote\Api\Data\CartItemExtensionInterface|null
*/
Expand All @@ -1061,7 +1064,7 @@ public function getExtensionAttributes()
}

/**
* {@inheritdoc}
* @inheritdoc
*
* @param \Magento\Quote\Api\Data\CartItemExtensionInterface $extensionAttributes
* @return $this
Expand Down
43 changes: 21 additions & 22 deletions app/code/Magento/Quote/Test/Unit/Model/Quote/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,24 @@ protected function setUp()
public function testGetAddress()
{
$quote = $this->getMockBuilder(\Magento\Quote\Model\Quote::class)
->setMethods(['getShippingAddress', 'getBillingAddress', 'getStoreId', '__wakeup'])
->setMethods(['getShippingAddress', 'getBillingAddress', 'getStoreId', '__wakeup', 'isVirtual'])
->disableOriginalConstructor()
->getMock();
$quote->expects($this->once())
->method('getShippingAddress')
->will($this->returnValue('shipping'));
->willReturn('shipping');
$quote->expects($this->once())
->method('getBillingAddress')
->will($this->returnValue('billing'));
->willReturn('billing');
$quote->expects($this->any())
->method('getStoreId')
->will($this->returnValue(1));
->willReturn(1);
$quote->expects($this->exactly(2))
->method('isVirtual')
->willReturnOnConsecutiveCalls(false, true);

$this->model->setQuote($quote);

$quote->setItemsQty(2);
$quote->setVirtualItemsQty(1);
$this->assertEquals('shipping', $this->model->getAddress(), 'Wrong shipping address');

$quote->setItemsQty(2);
$quote->setVirtualItemsQty(2);
$this->assertEquals('billing', $this->model->getAddress(), 'Wrong billing address');
}

Expand Down Expand Up @@ -855,18 +852,20 @@ public function testSetOptionsWithNull()
private function createOptionMock($optionCode, $optionData = [])
{
$optionMock = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Option::class)
->setMethods([
'setData',
'setItem',
'getItem',
'getCode',
'__wakeup',
'isDeleted',
'delete',
'getValue',
'getProduct',
'save'
])
->setMethods(
[
'setData',
'setItem',
'getItem',
'getCode',
'__wakeup',
'isDeleted',
'delete',
'getValue',
'getProduct',
'save'
]
)
->disableOriginalConstructor()
->getMock();
$optionMock->expects($this->any())
Expand Down
11 changes: 11 additions & 0 deletions app/code/Magento/Sales/Model/Order/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -730,5 +730,16 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\OrderAddressExten
return $this->_setExtensionAttributes($extensionAttributes);
}

/**
* @inheritdoc
*/
public function beforeSave()
{
if ($this->getEmail() === null) {
$this->setEmail($this->getOrder()->getCustomerEmail());
}
return parent::beforeSave();
}

//@codeCoverageIgnoreEnd
}
Loading

0 comments on commit b631f9d

Please sign in to comment.