Skip to content

Commit

Permalink
Merge branch '2.4-develop' into ASI-1833-add-ability-to-disable-rendi…
Browse files Browse the repository at this point in the history
…tions-functionality-to-stores-configuration
  • Loading branch information
sivaschenko committed Sep 18, 2020
2 parents e1bbf88 + 28020ae commit bb3822a
Show file tree
Hide file tree
Showing 32 changed files with 1,066 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<element name="selectFromGalleryButton" type="button" selector="//*[@class='file-uploader-area']/label[text()='Select from Gallery']"/>
<element name="uploadImageFile" type="input" selector=".file-uploader-area>input"/>
<element name="imageFileName" type="text" selector=".file-uploader-filename"/>
<element name="imageFileMeta" type="text" selector=".file-uploader-meta"/>
<element name="removeImageButton" type="button" selector=".file-uploader-summary .action-remove"/>
<element name="AddCMSBlock" type="select" selector="//*[@name='landing_page']"/>
<element name="description" type="input" selector="//*[@name='description']"/>
Expand Down
14 changes: 9 additions & 5 deletions app/code/Magento/Checkout/Model/TotalsInformationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Checkout\Model;

/**
* Class TotalsInformationManagement
* Class for management of totals information.
*/
class TotalsInformationManagement implements \Magento\Checkout\Api\TotalsInformationManagementInterface
{
Expand Down Expand Up @@ -38,7 +38,7 @@ public function __construct(
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function calculate(
$cartId,
Expand All @@ -52,16 +52,20 @@ public function calculate(
$quote->setBillingAddress($addressInformation->getAddress());
} else {
$quote->setShippingAddress($addressInformation->getAddress());
$quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
$addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
);
if ($addressInformation->getShippingCarrierCode() && $addressInformation->getShippingMethodCode()) {
$quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
$addressInformation->getShippingCarrierCode().'_'.$addressInformation->getShippingMethodCode()
);
}
}
$quote->collectTotals();

return $this->cartTotalRepository->get($cartId);
}

/**
* Check if quote have items.
*
* @param \Magento\Quote\Model\Quote $quote
* @throws \Magento\Framework\Exception\LocalizedException
* @return void
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Checkout\Test\Unit\Model;

use Magento\Checkout\Api\Data\TotalsInformationInterface;
use Magento\Checkout\Model\TotalsInformationManagement;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\CartTotalRepositoryInterface;
use Magento\Quote\Model\Quote\Address;

class TotalsInformationManagementTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var CartRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $cartRepositoryMock;

/**
* @var CartTotalRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $cartTotalRepositoryMock;

/**
* @var TotalsInformationManagement
*/
private $totalsInformationManagement;

protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);
$this->cartRepositoryMock = $this->createMock(
CartRepositoryInterface::class
);
$this->cartTotalRepositoryMock = $this->createMock(
CartTotalRepositoryInterface::class
);

$this->totalsInformationManagement = $this->objectManager->getObject(
TotalsInformationManagement::class,
[
'cartRepository' => $this->cartRepositoryMock,
'cartTotalRepository' => $this->cartTotalRepositoryMock,
]
);
}

/**
* Test for \Magento\Checkout\Model\TotalsInformationManagement::calculate.
*
* @param string|null $carrierCode
* @param string|null $carrierMethod
* @param int $methodSetCount
* @dataProvider dataProviderCalculate
*/
public function testCalculate(?string $carrierCode, ?string $carrierMethod, int $methodSetCount)
{
$cartId = 1;
$cartMock = $this->createMock(
\Magento\Quote\Model\Quote::class
);
$cartMock->expects($this->once())->method('getItemsCount')->willReturn(1);
$cartMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
$this->cartRepositoryMock->expects($this->once())->method('get')->with($cartId)->willReturn($cartMock);
$this->cartTotalRepositoryMock->expects($this->once())->method('get')->with($cartId);

$addressInformationMock = $this->createMock(
TotalsInformationInterface::class
);
$addressMock = $this->getMockBuilder(Address::class)
->addMethods(
[
'setShippingMethod',
'setCollectShippingRates',
]
)
->disableOriginalConstructor()
->getMock();

$addressInformationMock->expects($this->once())->method('getAddress')->willReturn($addressMock);
$addressInformationMock->expects($this->any())->method('getShippingCarrierCode')->willReturn($carrierCode);
$addressInformationMock->expects($this->any())->method('getShippingMethodCode')->willReturn($carrierMethod);
$cartMock->expects($this->once())->method('setShippingAddress')->with($addressMock);
$cartMock->expects($this->exactly($methodSetCount))->method('getShippingAddress')->willReturn($addressMock);
$addressMock->expects($this->exactly($methodSetCount))
->method('setCollectShippingRates')->with(true)->willReturn($addressMock);
$addressMock->expects($this->exactly($methodSetCount))
->method('setShippingMethod')->with($carrierCode . '_' . $carrierMethod);
$cartMock->expects($this->once())->method('collectTotals');

$this->totalsInformationManagement->calculate($cartId, $addressInformationMock);
}

/**
* Data provider for testCalculate.
*
* @return array
*/
public function dataProviderCalculate(): array
{
return [
[
null,
null,
0
],
[
null,
'carrier_method',
0
],
[
'carrier_code',
null,
0
],
[
'carrier_code',
'carrier_method',
1
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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="AdminMediaGalleryInsertLargeImageFileSizeTest">
<annotations>
<features value="AdminMediaGalleryInsertLargeImageFileSizeTest"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1806"/>
<title value="Admin user should see correct image file size after rendition"/>
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1507933/scenarios/5200023"/>
<stories value="User inserts image rendition to the content"/>
<description value="Admin user should see correct image file size after rendition"/>
<severity value="AVERAGE"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="category"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<!-- Delete uploaded image -->
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPageFoDelete"/>
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItemForDelete">
<argument name="categoryName" value="$category.name$"/>
</actionGroup>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryForDelete"/>
<actionGroup ref="AdminEnhancedMediaGalleryEnableMassActionModeActionGroup" stepKey="enableMassActionToDeleteImages"/>
<actionGroup ref="AdminEnhancedMediaGallerySelectImageForMassActionActionGroup" stepKey="selectSecondImageToDelete">
<argument name="imageName" value="{{ImageUpload.fileName}}"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryClickDeleteImagesButtonActionGroup" stepKey="clickDeleteSelectedButton"/>
<actionGroup ref="AdminEnhancedMediaGalleryConfirmDeleteImagesActionGroup" stepKey="deleteImages"/>

<!-- Delete category -->
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>

<!-- Open category page -->
<actionGroup ref="AdminOpenCategoryGridPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminEditCategoryInGridPageActionGroup" stepKey="editCategoryItem">
<argument name="categoryName" value="$category.name$"/>
</actionGroup>

<!-- Add image to category from gallery -->
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGallery"/>
<actionGroup ref="AdminEnhancedMediaGalleryUploadImageActionGroup" stepKey="addCategoryImage">
<argument name="image" value="ImageUpload"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickImageInGridActionGroup" stepKey="selectImage">
<argument name="imageName" value="{{ImageUpload.fileName}}"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryClickAddSelectedActionGroup" stepKey="addSelected"/>


<!-- Assert added image size -->
<actionGroup ref="AdminAssertImageUploadFileSizeThanActionGroup" stepKey="assertSize">
<argument name="fileSize" value="26 KB"/>
</actionGroup>
</test>
</tests>
10 changes: 7 additions & 3 deletions app/code/Magento/MediaGalleryRenditions/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
<system>
<section id="system">
<group id="media_gallery_renditions" translate="label" type="text" sortOrder="1010" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Media Gallery Renditions</label>
<label>Media Gallery Image Optimization</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Image Optimization</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<comment>Resize images to improve performance and decrease the file size. When you use an image from Media Gallery on the storefront, the smaller image is generated and placed instead of the original.
Changing these settings will update all generated images.</comment>
<field id="width" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Max Width</label>
<label>Maximum Width</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum width of an image in pixels.</comment>
</field>
<field id="height" translate="label" type="text" sortOrder="30" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Max Height</label>
<label>Maximum Height</label>
<validate>validate-zero-or-greater validate-digits</validate>
<comment>Enter the maximum height of an image in pixels.</comment>
</field>
</group>
</section>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\MediaGalleryUi\Controller\Adminhtml\Image;

use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\MediaGalleryUi\Model\InsertImageData\GetInsertImageData;

/**
* OnInsert action returns on insert image details
*/
class OnInsert extends Action implements HttpPostActionInterface
{
/**
* @see _isAllowed()
*/
public const ADMIN_RESOURCE = 'Magento_MediaGalleryUiApi::insert_assets';

/**
* @var JsonFactory
*/
private $resultJsonFactory;

/**
* @var GetInsertImageData
*/
private $getInsertImageData;

/**
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param GetInsertImageData $getInsertImageData
*/
public function __construct(
Context $context,
JsonFactory $resultJsonFactory,
GetInsertImageData $getInsertImageData
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->getInsertImageData = $getInsertImageData;
}

/**
* Return a content (just a link or an html block) for inserting image to the content
*
* @return ResultInterface
*/
public function execute()
{
$data = $this->getRequest()->getParams();
$insertImageData = $this->getInsertImageData->execute(
$data['filename'],
(bool)$data['force_static_path'],
(bool)$data['as_is'],
isset($data['store']) ? (int)$data['store'] : null
);

return $this->resultJsonFactory->create()->setData([
'content' => $insertImageData->getContent(),
'size' => $insertImageData->getSize(),
'type' => $insertImageData->getType(),
]);
}
}
Loading

0 comments on commit bb3822a

Please sign in to comment.