Skip to content

Commit

Permalink
Merge branch '2.4-develop' into 21853
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie committed Nov 25, 2020
2 parents 4c1094a + f55f411 commit 69cee97
Show file tree
Hide file tree
Showing 42 changed files with 1,709 additions and 353 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Model\Sales\Order\Shipment;

use Magento\Catalog\Model\Product\Type;
use Magento\Sales\Model\ValidatorInterface;

/**
* Validate if requested order items can be shipped according to bundle product shipment type
*/
class BundleShipmentTypeValidator implements ValidatorInterface
{
/**
* @inheritdoc
*/
public function validate($item)
{
$result = [];
if (!$item->isDummy(true)) {
return $result;
}

$message = 'Cannot create shipment as bundle product "%1" has shipment type "%2". ' .
'%3 should be shipped instead.';

if ($item->getHasChildren() && $item->getProductType() === Type::TYPE_BUNDLE) {
$result[] = __(
$message,
$item->getSku(),
__('Separately'),
__('Bundle product options'),
);
}

if ($item->getParentItem() && $item->getParentItem()->getProductType() === Type::TYPE_BUNDLE) {
$result[] = __(
$message,
$item->getParentItem()->getSku(),
__('Together'),
__('Bundle product itself'),
);
}

return $result;
}
}
7 changes: 7 additions & 0 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,11 @@
</argument>
</arguments>
</type>
<type name="Magento\Sales\Model\Order\Shipment\ShipmentItemsValidator">
<arguments>
<argument name="validators" xsi:type="array">
<item name="shipment_type" xsi:type="object">Magento\Bundle\Model\Sales\Order\Shipment\BundleShipmentTypeValidator</item>
</argument>
</arguments>
</type>
</config>
3 changes: 3 additions & 0 deletions app/code/Magento/Bundle/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ Select...,Select...
Status,Status
Thumbnail,Thumbnail
Type,Type
"Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead.","Cannot create shipment as bundle product ""%1"" has shipment type ""%2"". %3 should be shipped instead."
"Bundle product itself","Bundle product itself"
"Bundle product options","Bundle product options"
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<severity value="BLOCKER"/>
<testCaseId value="MC-10895"/>
<group value="Catalog"/>
<skip>
<issueId value="MC-13817"/>
</skip>
<group value="mtf_migrated"/>
</annotations>

Expand All @@ -35,8 +32,9 @@
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<!--Generate date for use as default value, needs to be MM/d/YYYY -->
<!--Generate date for use as default value, needs to be MM/d/YYYY and mm/d/yy-->
<generateDate date="now" format="m/j/Y" stepKey="generateDefaultDate"/>
<generateDate date="now" format="m/j/y" stepKey="generateDateCompressedFormat"/>

<!--Navigate to Stores > Attributes > Product.-->
<actionGroup ref="AdminOpenProductAttributePageActionGroup" stepKey="goToProductAttributes"/>
Expand All @@ -57,7 +55,7 @@
<seeOptionIsSelected stepKey="assertInputType" selector="{{AttributePropertiesSection.InputType}}" userInput="{{dateProductAttribute.frontend_input}}"/>
<seeOptionIsSelected stepKey="assertRequired" selector="{{AttributePropertiesSection.ValueRequired}}" userInput="{{dateProductAttribute.is_required_admin}}"/>
<seeInField stepKey="assertAttrCode" selector="{{AdvancedAttributePropertiesSection.AttributeCode}}" userInput="{{dateProductAttribute.attribute_code}}"/>
<seeInField stepKey="assertDefaultValue" selector="{{AdvancedAttributePropertiesSection.DefaultValueDate}}" userInput="{$generateDefaultDate}"/>
<seeInField stepKey="assertDefaultValue" selector="{{AdvancedAttributePropertiesSection.DefaultValueDate}}" userInput="{$generateDateCompressedFormat}"/>

<!--Go to New Product page, add Attribute and check values-->
<amOnPage url="{{AdminProductCreatePage.url('4', 'simple')}}" stepKey="goToCreateSimpleProductPage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ protected function setUp(): void

$this->productFactory = $this->getMockBuilder(
\Magento\Catalog\Model\ResourceModel\ProductFactory::class
)->addMethods(['getTypeId'])
)->disableOriginalConstructor()
->addMethods(['getTypeId'])
->onlyMethods(['create'])
->getMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Magento\Quote\Model\ShippingAssignmentFactory;
use Magento\Quote\Model\ShippingFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -148,7 +149,7 @@ protected function setUp(): void
'importCustomerAddressData',
'save',
'getShippingRateByCode',
'getShippingMethod'
'getShippingMethod',
]
)
->disableOriginalConstructor()
Expand All @@ -167,7 +168,7 @@ protected function setUp(): void
'collectTotals',
'getExtensionAttributes',
'setExtensionAttributes',
'setBillingAddress'
'setBillingAddress',
]
)
->disableOriginalConstructor()
Expand Down Expand Up @@ -238,9 +239,7 @@ private function setShippingAssignmentsMocks($shippingMethod): void
->willReturn(null);
$this->shippingAddressMock->expects($this->once())
->method('setLimitCarrier');
$this->cartExtensionMock = $this->getMockBuilder(CartExtension::class)
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
->getMock();
$this->cartExtensionMock = $this->getCartExtensionMock();
$this->cartExtensionFactoryMock->expects($this->once())
->method('create')
->willReturn($this->cartExtensionMock);
Expand Down Expand Up @@ -622,4 +621,21 @@ public function testSaveAddressInformation(): void
$this->model->saveAddressInformation($cartId, $addressInformationMock)
);
}

/**
* Build cart extension mock.
*
* @return MockObject
*/
private function getCartExtensionMock(): MockObject
{
$mockBuilder = $this->getMockBuilder(CartExtension::class);
try {
$mockBuilder->addMethods(['getShippingAssignments', 'setShippingAssignments']);
} catch (RuntimeException $e) {
// CartExtension already generated.
}

return $mockBuilder->getMock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Quote\Api\Data\PaymentInterface;
use Magento\Store\Model\ScopeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -78,9 +79,7 @@ protected function setUp(): void
$this->subjectMock = $this->getMockForAbstractClass(GuestPaymentInformationManagementInterface::class);
$this->paymentMock = $this->getMockForAbstractClass(PaymentInterface::class);
$this->addressMock = $this->getMockForAbstractClass(AddressInterface::class);
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
->addMethods(['getAgreementIds'])
->getMock();
$this->extensionAttributesMock = $this->getPaymentExtension();
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->checkoutAgreementsListMock = $this->createMock(
CheckoutAgreementsListInterface::class
Expand Down Expand Up @@ -165,4 +164,21 @@ public function testBeforeSavePaymentInformationAndPlaceOrderIfAgreementsNotVali
"The order wasn't placed. First, agree to the terms and conditions, then try placing your order again."
);
}

/**
* Build payment extension mock.
*
* @return MockObject
*/
private function getPaymentExtension(): MockObject
{
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
try {
$mockBuilder->addMethods(['getAgreementIds']);
} catch (RuntimeException $e) {
// Payment extension already generated.
}

return $mockBuilder->getMock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Magento\Quote\Model\Quote;
use Magento\Store\Model\ScopeInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -96,9 +97,7 @@ protected function setUp(): void
->disableOriginalConstructor()
->getMock();
$this->quoteRepositoryMock = $this->getMockForAbstractClass(CartRepositoryInterface::class);
$this->extensionAttributesMock = $this->getMockBuilder(PaymentExtension::class)
->addMethods(['getAgreementIds'])
->getMock();
$this->extensionAttributesMock = $this->getPaymentExtension();
$this->scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
$this->checkoutAgreementsListMock = $this->createMock(
CheckoutAgreementsListInterface::class
Expand Down Expand Up @@ -232,4 +231,21 @@ public function testBeforeSavePaymentInformation()
->willReturn($this->extensionAttributesMock);
$this->model->beforeSavePaymentInformation($this->subjectMock, $cartId, $this->paymentMock, $this->addressMock);
}

/**
* Build payment extension mock.
*
* @return MockObject
*/
private function getPaymentExtension(): MockObject
{
$mockBuilder = $this->getMockBuilder(PaymentExtension::class);
try {
$mockBuilder->addMethods(['getAgreementIds']);
} catch (RuntimeException $e) {
// Payment extension already generated.
}

return $mockBuilder->getMock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ function (array $attributes) use ($elementMock): string {
}
);
$countryMock = $this->getMockBuilder(AbstractElement::class)
->addMethods(['getValue', 'serialize'])
->onlyMethods(['serialize'])
->addMethods(['getValue'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$countryMock->method('serialize')->willReturnCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Downloadable\Model\Link\UpdateHandler;
use Magento\Downloadable\Model\Product\Type;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ protected function setUp(): void
->getMockForAbstractClass();
$this->linkMock = $this->getMockBuilder(LinkInterface::class)
->getMock();
$this->productExtensionMock = $this->createMock(ProductExtensionInterface::class);
$this->productExtensionMock = $this->getProductExtensionMock();
$this->productExtensionMock->expects($this->once())
->method('getDownloadableProductLinks')
->willReturn([$this->linkMock]);
Expand Down Expand Up @@ -145,4 +146,22 @@ public function testExecuteNonDownloadable(): void

$this->assertEquals($this->entityMock, $this->model->execute($this->entityMock));
}

/**
* Build product extension mock.
*
* @return MockObject
*/
private function getProductExtensionMock(): MockObject
{
$mockBuilder = $this->getMockBuilder(ProductExtensionInterface::class)
->disableOriginalConstructor();
try {
$mockBuilder->addMethods(['getDownloadableProductLinks']);
} catch (RuntimeException $e) {
// ProductExtension already generated.
}

return $mockBuilder->getMockForAbstractClass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Magento\Quote\Model\Quote\Item;
use Magento\Quote\Model\Quote\ProductOptionFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\RuntimeException;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -170,14 +171,12 @@ public function testProcessProductOptions()
$this->optionFactoryMock->expects($this->once())->method('create')->willReturn($productOptionMock);
$productOptionMock->expects($this->once())->method('getExtensionAttributes')->willReturn(null);

$extAttributeMock = $this->getMockBuilder(ProductOptionExtension::class)
->addMethods(['setDownloadableOption'])
->getMock();
$extAttributeMock = $this->getProductOptionExtensionMock();

$this->objectHelperMock->expects($this->once())->method('populateWithArray')->with(
$downloadableOptionMock,
[
'downloadable_links' => $downloadableLinks
'downloadable_links' => $downloadableLinks,
],
DownloadableOptionInterface::class
);
Expand Down Expand Up @@ -206,9 +205,7 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()
->method('getOptionByCode')
->with('downloadable_link_ids');

$extAttributeMock = $this->getMockBuilder(ProductOptionExtension::class)
->addMethods(['setDownloadableOption'])
->getMock();
$extAttributeMock = $this->getProductOptionExtensionMock();
$productOptionMock = $this->getMockForAbstractClass(ProductOptionInterface::class);
$productOptionMock->expects($this->any())
->method('getExtensionAttributes')
Expand All @@ -228,7 +225,7 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()
$this->objectHelperMock->expects($this->once())->method('populateWithArray')->with(
$downloadableOptionMock,
[
'downloadable_links' => $downloadableLinks
'downloadable_links' => $downloadableLinks,
],
DownloadableOptionInterface::class
);
Expand All @@ -243,4 +240,21 @@ public function testProcessProductOptionsWhenItemDoesNotHaveDownloadableLinks()

$this->assertEquals($cartItemMock, $this->model->processOptions($cartItemMock));
}

/**
* Build product option extension mock.
*
* @return MockObject
*/
private function getProductOptionExtensionMock(): MockObject
{
$mockBuilder = $this->getMockBuilder(ProductOptionExtension::class);
try {
$mockBuilder->addMethods(['setDownloadableOption']);
} catch (RuntimeException $e) {
// ProductOptionExtension already generated.
}

return $mockBuilder->getMock();
}
}
Loading

0 comments on commit 69cee97

Please sign in to comment.