Skip to content

Commit

Permalink
🔃 [Magento Community Engineering] Community Contributions - 2.3-devel…
Browse files Browse the repository at this point in the history
…op expedited

Accepted Community Pull Requests:
 - #24665: Refactor apply options of sales rule to it's own source model to simplify extending it (by @Bartlomiejsz)
 - #24634: fixed getting error in console while selecting all downloadable links #24633 (by @rani-webkul)
 - #24153: Fix config backend model PDF file name extension (by @Vinai)
 - #23767: #23766 - fix pattern validation on form submit (by @vahir2016)
 - #24030: 24025 add caching for magento product version (by @davidverholen)


Fixed GitHub Issues:
 - #24633: Getting error in console while selecting all downloadable links  (reported by @rani-webkul) has been fixed in #24634 by @rani-webkul in 2.3-develop branch
   Related commits:
     1. 66b7785

 - #24025: Slow Performance of ProductMetadata::getVersion (reported by @beberlei) has been fixed in #24030 by @davidverholen in 2.3-develop branch
   Related commits:
     1. f0856e8
     2. ed1fb03
     3. b2ca7c8
     4. b397814
  • Loading branch information
magento-engcom-team authored Sep 26, 2019
2 parents bf6b166 + 32f8e29 commit ea71192
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 42 deletions.
21 changes: 21 additions & 0 deletions app/code/Magento/Config/Model/Config/Backend/File/Pdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Config\Model\Config\Backend\File;

/**
* System config PDF field backend model.
*/
class Pdf extends \Magento\Config\Model\Config\Backend\File
{
/**
* @inheritdoc
*/
protected function _getAllowedExtensions()
{
return ['pdf'];
}
}
12 changes: 6 additions & 6 deletions app/code/Magento/Config/Model/Config/Backend/Image/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
* See COPYING.txt for license details.
*/

/**
* System config image field backend model for Zend PDF generator
*
* @author Magento Core Team <core@magentocommerce.com>
*/
namespace Magento\Config\Model\Config\Backend\Image;

/**
* System config PDF field backend model.
*
* @api
* @since 100.0.2
* @see \Magento\Config\Model\Config\Backend\File\Pdf
*/
class Pdf extends \Magento\Config\Model\Config\Backend\Image
{
/**
* Returns the list of allowed file extensions.
*
* @return string[]
*/
protected function _getAllowedExtensions()
{
return ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg'];
return ['tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg', 'pdf'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<element name="downloadableLinkByTitle" type="input" selector="//*[@id='downloadable-links-list']/*[contains(.,'{{title}}')]//input" parameterized="true" timeout="30"/>
<element name="downloadableLinkSampleByTitle" type="text" selector="//label[contains(., '{{title}}')]/a[contains(@class, 'sample link')]" parameterized="true"/>
<element name="downloadableSampleLabel" type="text" selector="//a[contains(.,normalize-space('{{title}}'))]" parameterized="true" timeout="30"/>
<element name="downloadableLinkSelectAllCheckbox" type="checkbox" selector="#links_all" />
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?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="SelectAllDownloadableLinksDownloadableProductTest">
<annotations>
<features value="Catalog"/>
<stories value="Create Downloadable Product"/>
<title value="Select all downloadable links downloadable product test"/>
<description value="All the downloadable links must be selected or unselected when anyone click on select all or unselect all checkbox respectively."/>
<severity value="MAJOR"/>
<group value="Downloadable"/>
</annotations>
<before>
<!-- Create category -->
<createData entity="SimpleSubCategory" stepKey="createCategory"/>

<!-- Login as admin -->
<actionGroup ref="LoginAsAdmin" stepKey="LoginAsAdmin"/>

<!-- Create downloadable product -->
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="amOnProductGridPage"/>
<waitForPageLoad stepKey="waitForProductGridPageLoad"/>
<actionGroup ref="GoToSpecifiedCreateProductPage" stepKey="createProduct">
<argument name="productType" value="downloadable"/>
</actionGroup>

<!-- Fill downloadable product values -->
<actionGroup ref="fillMainProductFormNoWeight" stepKey="fillDownloadableProductForm">
<argument name="product" value="DownloadableProduct"/>
</actionGroup>

<!-- Add downloadable product to category -->
<searchAndMultiSelectOption selector="{{AdminProductFormSection.categoriesDropdown}}"
parameterArray="[$$createCategory.name$$]" stepKey="fillCategory"/>

<!-- Fill downloadable link information before the creation link -->
<actionGroup ref="AdminAddDownloadableLinkInformationActionGroup" stepKey="addDownloadableLinkInformation"/>

<!-- Links can be purchased separately -->
<checkOption selector="{{AdminProductDownloadableSection.isLinksPurchasedSeparately}}"
stepKey="checkOptionPurchaseSeparately"/>

<!-- Add first downloadable link -->
<actionGroup ref="addDownloadableProductLinkWithMaxDownloads" stepKey="addFirstDownloadableProductLink">
<argument name="link" value="downloadableLinkWithMaxDownloads"/>
</actionGroup>

<!-- Add second downloadable link -->
<actionGroup ref="addDownloadableProductLink" stepKey="addSecondDownloadableProductLink">
<argument name="link" value="downloadableLink"/>
</actionGroup>

<!-- Save product -->
<actionGroup ref="saveProductForm" stepKey="saveProduct"/>
</before>
<after>
<!-- Delete category -->
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>

<!-- Delete created downloadable product -->
<actionGroup ref="deleteProductUsingProductGrid" stepKey="deleteProduct">
<argument name="product" value="DownloadableProduct"/>
</actionGroup>

<!-- Log out -->
<actionGroup ref="logout" stepKey="logout"/>
</after>

<!-- Step 1: Navigate to store front Product page as guest -->
<amOnPage url="/{{DownloadableProduct.sku}}.html"
stepKey="amOnStorefrontProductPage"/>

<!-- Step 2: click on select all checkbox -->
<click
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllCheckbox}}"
stepKey="selectAllProductLink"/>

<!-- Step 3: Make sure that all product links are checked -->
<seeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLinkWithMaxDownloads.title)}}" stepKey="seeFirstCheckboxChecked"/>

<seeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}" stepKey="seeSecondCheckboxChecked"/>

<!-- Step 4: click again on select all checkbox -->
<click
selector="{{StorefrontDownloadableProductSection.downloadableLinkSelectAllCheckbox}}"
stepKey="unselectAllProductLink"/>

<!-- Step 5: Make sure that all product links are unchecked -->
<dontSeeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLinkWithMaxDownloads.title)}}" stepKey="seeFirstCheckboxUnChecked"/>

<dontSeeCheckboxIsChecked selector="{{StorefrontDownloadableProductSection.downloadableLinkByTitle(downloadableLink.title)}}" stepKey="seeSecondCheckboxUnChecked"/>

</test>
</tests>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\SalesRule\Model\Rule\Action;

use Magento\Framework\Data\OptionSourceInterface;
use Magento\SalesRule\Model\Rule;

/**
* Class SimpleActionOptionsProvider
*/
class SimpleActionOptionsProvider implements OptionSourceInterface
{
/**
* @inheritdoc
*/
public function toOptionArray()
{
return [
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
];
}
}
31 changes: 19 additions & 12 deletions app/code/Magento/SalesRule/Model/Rule/Metadata/ValueProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
*/
namespace Magento\SalesRule\Model\Rule\Metadata;

use Magento\SalesRule\Model\Rule;
use Magento\Store\Model\System\Store;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Convert\DataObject;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider;
use Magento\SalesRule\Model\RuleFactory;
use Magento\Store\Model\System\Store;

/**
* Metadata provider for sales rule edit form.
Expand Down Expand Up @@ -37,31 +40,40 @@ class ValueProvider
protected $objectConverter;

/**
* @var \Magento\SalesRule\Model\RuleFactory
* @var RuleFactory
*/
protected $salesRuleFactory;

/**
* @var SimpleActionOptionsProvider
*/
private $simpleActionOptionsProvider;

/**
* Initialize dependencies.
*
* @param Store $store
* @param GroupRepositoryInterface $groupRepository
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param DataObject $objectConverter
* @param \Magento\SalesRule\Model\RuleFactory $salesRuleFactory
* @param RuleFactory $salesRuleFactory
* @param SimpleActionOptionsProvider|null $simpleActionOptionsProvider
*/
public function __construct(
Store $store,
GroupRepositoryInterface $groupRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
DataObject $objectConverter,
\Magento\SalesRule\Model\RuleFactory $salesRuleFactory
RuleFactory $salesRuleFactory,
SimpleActionOptionsProvider $simpleActionOptionsProvider = null
) {
$this->store = $store;
$this->groupRepository = $groupRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->objectConverter = $objectConverter;
$this->salesRuleFactory = $salesRuleFactory;
$this->simpleActionOptionsProvider = $simpleActionOptionsProvider ?:
ObjectManager::getInstance()->get(SimpleActionOptionsProvider::class);
}

/**
Expand All @@ -71,15 +83,10 @@ public function __construct(
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
public function getMetadataValues(Rule $rule)
{
$customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
$applyOptions = [
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
];
$applyOptions = $this->simpleActionOptionsProvider->toOptionArray();

$couponTypesOptions = [];
$couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\SalesRule\Test\Unit\Model\Rule\Action;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\SalesRule\Model\Rule;
use Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @covers Magento\SalesRule\Model\Rule\Action\SimpleActionOptionsProvider
*/
class SimpleActionOptionsProviderTest extends TestCase
{
/**
* @var SimpleActionOptionsProvider|MockObject
*/
protected $model;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->model = $objectManager->getObject(SimpleActionOptionsProvider::class);
}

public function testToOptionArray()
{
$expected = [
['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
];

$this->assertEquals($expected, $this->model->toOptionArray());
}
}
Loading

0 comments on commit ea71192

Please sign in to comment.