Skip to content

Commit

Permalink
Merge branch '2.4-develop' into jquery-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
sivaschenko authored May 29, 2021
2 parents 5562e32 + d4aab3c commit 7f7b3d1
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@
<data key="videoTitle">The New Vimeo Player (You Know, For Videos)</data>
<data key="videoShortTitle">The New Vimeo Player</data>
</entity>
<entity name="VimeoPrivateVideo" type="product_video">
<data key="videoUrl">https://vimeo.com/313826626</data>
</entity>
</entities>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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="AdminValidatePrivacyOnVimeoGetVideoInformationTest">
<annotations>
<features value="ProductVideo"/>
<stories value="Add/remove images and videos for all product types and category"/>
<title value="Admin validates Vimeo video privacy when getting video information"/>
<description value="Admin should be able to see warning message when adding Vimeo video with restricted privacy privacy when getting video information"/>
<severity value="AVERAGE"/>
<testCaseId value="MC-42471"/>
<useCaseId value="MC-42105"/>
<group value="productVideo"/>
</annotations>
<before>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>
<actionGroup ref="AdminOpenNewProductFormPageActionGroup" stepKey="openNewProductPage"/>
<actionGroup ref="AdminOpenProductVideoModalActionGroup" stepKey="openAddProductVideoModal"/>
<actionGroup ref="AdminFillProductVideoFieldActionGroup" stepKey="fillVideoUrlField">
<argument name="input" value="{{AdminProductNewVideoSection.videoUrlTextField}}"/>
<argument name="value" value="{{VimeoPrivateVideo.videoUrl}}"/>
</actionGroup>
<actionGroup ref="AdminGetVideoInformationActionGroup" stepKey="clickOnGetVideoInformation"/>
<waitForElementVisible selector="{{AdminConfirmationModalSection.message}}" stepKey="waitForWarningMessage"/>
<see selector="{{AdminConfirmationModalSection.message}}" userInput='Because of its privacy settings, this video cannot be played here.' stepKey="seeAdminWarningMessage"/>
</test>
</tests>
1 change: 1 addition & 0 deletions app/code/Magento/ProductVideo/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ Delete,Delete
"Show related video","Show related video"
"Auto restart video","Auto restart video"
"Delete image in all store views","Delete image in all store views"
"Because of its privacy settings, this video cannot be played here.","Because of its privacy settings, this video cannot be played here."
Original file line number Diff line number Diff line change
Expand Up @@ -495,28 +495,40 @@ define([
*/
function _onVimeoLoaded(data) {
var tmp,
respData;
respData,
videoDescription = '';

if (!data) {
this._onRequestError($.mage.__('Video not found'));

return null;
}
tmp = data;
respData = {
duration: this._formatVimeoDuration(tmp.duration),
channel: tmp['author_name'],
channelId: tmp['author_url'],
uploaded: tmp['upload_date'],
title: tmp.title,
description: tmp.description.replace(/(&nbsp;|<([^>]+)>)/ig, ''),
thumbnail: tmp['thumbnail_url'],
videoId: videoInfo.id,
videoProvider: videoInfo.type
};
this._videoInformation = respData;
this.element.trigger(this._UPDATE_VIDEO_INFORMATION_TRIGGER, respData);
this.element.trigger(this._FINISH_UPDATE_INFORMATION_TRIGGER, true);

if (tmp.description !== null) {
videoDescription = tmp.description;
}

if (tmp.duration == null) {
this._onRequestError(
$.mage.__('Because of its privacy settings, this video cannot be played here.')
);
} else {
respData = {
duration: this._formatVimeoDuration(tmp.duration),
channel: tmp['author_name'],
channelId: tmp['author_url'],
uploaded: tmp['upload_date'],
title: tmp.title,
description: videoDescription.replace(/(&nbsp;|<([^>]+)>)/ig, ''),
thumbnail: tmp['thumbnail_url'],
videoId: videoInfo.id,
videoProvider: videoInfo.type
};
this._videoInformation = respData;
this.element.trigger(this._UPDATE_VIDEO_INFORMATION_TRIGGER, respData);
this.element.trigger(this._FINISH_UPDATE_INFORMATION_TRIGGER, true);
}
}

type = videoInfo.type;
Expand Down
10 changes: 9 additions & 1 deletion app/code/Magento/Quote/Model/ShippingMethodManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,15 @@ public function apply($cartId, $carrierCode, $methodCode)
$this->quoteAddressResource->delete($shippingAddress);
throw new StateException(__('The shipping address is missing. Set the address and try again.'));
}
$shippingAddress->setShippingMethod($carrierCode . '_' . $methodCode);
$shippingMethod = $carrierCode . '_' . $methodCode;
$shippingAddress->setShippingMethod($shippingMethod);
$shippingAssignments = $quote->getExtensionAttributes()->getShippingAssignments();
if (!empty($shippingAssignments)) {
$shippingAssignment = $shippingAssignments[0];
$shipping = $shippingAssignment->getShipping();
$shipping->setMethod($shippingMethod);
$shippingAssignment->setShipping($shipping);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
use Magento\Store\Model\Store;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Quote\Api\Data\CartExtensionInterface;
use Magento\Sales\Model\Order\ShippingAssignmentBuilder;
use Magento\Quote\Api\Data\ShippingInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -103,6 +106,21 @@ class ShippingMethodManagementTest extends TestCase
*/
private $quoteAddressResource;

/**
* @var CartExtensionInterface|MockObject
*/
private $extensionAttributesMock;

/**
* @var ShippingInterface|MockObject
*/
private $shippingMock;

/**
* @var ShippingAssignmentBuilder|MockObject
*/
private $shippingAssignmentBuilder;

protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
Expand Down Expand Up @@ -135,6 +153,7 @@ protected function setUp(): void
'collectTotals',
'save',
'__wakeup',
'getExtensionAttributes'
])
->getMock();

Expand Down Expand Up @@ -190,6 +209,20 @@ protected function setUp(): void
'dataProcessor',
$this->dataProcessor
);

$this->extensionAttributesMock = $this->getMockBuilder(CartExtensionInterface::class)
->setMethods(['getShippingAssignments'])
->getMockForAbstractClass();

$this->shippingMock = $this->getMockForAbstractClass(ShippingInterface::class);

$this->shippingAssignmentBuilder = $this->getMockBuilder(ShippingAssignmentBuilder::class)
->disableOriginalConstructor()
->setMethods([
'getShipping',
'setShipping'
])
->getMock();
}

public function testGetMethodWhenShippingAddressIsNotSet()
Expand Down Expand Up @@ -424,6 +457,24 @@ public function testSetMethodWithCouldNotSaveException()
$this->shippingAddress->expects($this->once())
->method('setShippingMethod')
->with($carrierCode . '_' . $methodCode);
$this->quote->expects($this->once())
->method('getExtensionAttributes')
->willReturn($this->extensionAttributesMock);

$this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments')
->willReturn([$this->shippingAssignmentBuilder]);

$this->shippingAssignmentBuilder->expects($this->once())->method('getShipping')
->willReturn($this->shippingMock);

$this->shippingMock->expects($this->once())
->method('setMethod')
->with($carrierCode . '_' . $methodCode);

$this->shippingAssignmentBuilder->expects($this->once())
->method('setShipping')
->with($this->shippingMock);

$exception = new \Exception('Custom Error');
$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
$this->quoteRepository->expects($this->once())
Expand Down Expand Up @@ -477,6 +528,24 @@ public function testSetMethod()
->method('getCountryId')->willReturn($countryId);
$this->shippingAddress->expects($this->once())
->method('setShippingMethod')->with($carrierCode . '_' . $methodCode);
$this->quote->expects($this->once())
->method('getExtensionAttributes')
->willReturn($this->extensionAttributesMock);

$this->extensionAttributesMock->expects($this->once())->method('getShippingAssignments')
->willReturn([$this->shippingAssignmentBuilder]);

$this->shippingAssignmentBuilder->expects($this->once())->method('getShipping')
->willReturn($this->shippingMock);

$this->shippingMock->expects($this->once())
->method('setMethod')
->with($carrierCode . '_' . $methodCode);

$this->shippingAssignmentBuilder->expects($this->once())
->method('setShipping')
->with($this->shippingMock);

$this->quote->expects($this->once())->method('collectTotals')->willReturnSelf();
$this->quoteRepository->expects($this->once())->method('save')->with($this->quote);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Api;

use Magento\Framework\Webapi\Rest\Request;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;
use Magento\TestFramework\TestCase\WebapiAbstract;
use Magento\Quote\Model\QuoteIdMask;

/**
* Class GuestCollectRatesTest checks that totals will be recollected properly with new shipping method
*/
class GuestCollectRatesTest extends WebapiAbstract
{
const SERVICE_VERSION = 'V1';
const SERVICE_NAME = 'quoteGuestCartTotalManagementV1';
const RESOURCE_PATH = '/V1/guest-carts/';

/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var Quote
*/
protected $quote;

protected function setUp(): void
{
$this->objectManager = Bootstrap::getObjectManager();
$this->quote = $this->objectManager->create(Quote::class);
}

/**
* Checks that totals are properly recollected after changing shipping method
*
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_shipping_method.php
*/
public function testCollectRatesWithChangedShippingMethod()
{
$this->quote->load('test_order_1', 'reserved_order_id');
$cartId = $this->quote->getId();

/** @var QuoteIdMask $quoteIdMask */
$quoteIdMask = $this->objectManager
->create(QuoteIdMaskFactory::class)
->create();
$quoteIdMask->load($cartId, 'quote_id');

$cartId = $quoteIdMask->getMaskedId();
$requestData = [
"shippingMethodCode" => "freeshipping",
"shippingCarrierCode" => "freeshipping",
"paymentMethod" => [
"method" => "checkmo",
],
];

if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) {
$requestData['cartId'] = $cartId;
}

$totals = $this->_webApiCall($this->getListServiceInfo($cartId), $requestData);
$this->assertEquals(20, $totals['grand_total']);
$this->assertEquals(0, $totals['shipping_amount']);

$requestData['shippingMethodCode'] = 'flatrate';
$requestData['shippingCarrierCode'] = 'flatrate';

$totals = $this->_webApiCall($this->getListServiceInfo($cartId), $requestData);
$this->assertEquals(30, $totals['grand_total']);
$this->assertEquals(10, $totals['shipping_amount']);
}

/**
* Service info
*
* @param int $cartId
* @return array
*/
protected function getListServiceInfo($cartId)
{
return [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $cartId . '/collect-totals',
'httpMethod' => Request::HTTP_METHOD_PUT,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => 'quoteGuestCartTotalManagementV1CollectTotals',
],
];
}
}

0 comments on commit 7f7b3d1

Please sign in to comment.