Skip to content

Commit

Permalink
Merge pull request #234 from magento-troll/bugfix_s47
Browse files Browse the repository at this point in the history
[Troll] Bugfixes S47
  • Loading branch information
Ganin, Roman(rganin) committed Dec 10, 2015
2 parents d391b29 + 993d62f commit 32ec76e
Show file tree
Hide file tree
Showing 22 changed files with 341 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ protected function getValidatorErrors($errors, $fileInfo, $option)
$this->fileSize->getMaxFileSizeInMb()
);
break;
case \Zend_Validate_File_ImageSize::NOT_DETECTED:
$result[] = __(
"The file '%1' is empty. Please choose another one",
$fileInfo['title']
);
break;
default:
$result[] = __(
"The file '%1' is invalid. Please choose another one",
$fileInfo['title']
);
}
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,30 @@ class ValidatorFile extends Validator
*/
protected $product;

/**
* @var \Magento\Framework\Validator\File\IsImage
*/
protected $isImageValidator;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\File\Size $fileSize
* @param \Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
* @param \Magento\Framework\Validator\File\IsImage $isImageValidator
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\File\Size $fileSize,
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory
\Magento\Framework\HTTP\Adapter\FileTransferFactory $httpFactory,
\Magento\Framework\Validator\File\IsImage $isImageValidator
) {
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->filesystem = $filesystem;
$this->httpFactory = $httpFactory;
$this->isImageValidator = $isImageValidator;
parent::__construct($scopeConfig, $filesystem, $fileSize);
}

Expand Down Expand Up @@ -169,8 +177,15 @@ public function validate($processingParams, $option)
$_height = 0;

if ($tmpDirectory->isReadable($tmpDirectory->getRelativePath($fileInfo['tmp_name']))) {
$imageSize = getimagesize($fileInfo['tmp_name']);
if ($imageSize) {
if (filesize($fileInfo['tmp_name'])) {
if ($this->isImageValidator->isValid($fileInfo['tmp_name'])) {
$imageSize = getimagesize($fileInfo['tmp_name']);
}
} else {
throw new LocalizedException(__('The file is empty. Please choose another one'));
}

if (!empty($imageSize)) {
$_width = $imageSize[0];
$_height = $imageSize[1];
}
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -699,3 +699,4 @@ Autosettings,Autosettings
"Allow Gift Message","Allow Gift Message"
"Meta Title","Meta Title"
"Maximum 255 chars","Maximum 255 chars"
"The file is empty. Please choose another one","The file is empty. Please choose another one"
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require(['prototype'], function(){
</label>
<div class="admin__field-control control">
<?php if ($_fileExists): ?>
<span class="<?php /* @escapeNotVerified */ echo $_fileNamed ?>"><?php /* @escapeNotVerified */ echo $_fileInfo->getTitle(); ?></span>
<span class="<?php /* @noEscape */ echo $_fileNamed ?>"><?php echo $block->escapeHtml($_fileInfo->getTitle()); ?></span>
<a href="javascript:void(0)" class="label" onclick="opFile<?php /* @escapeNotVerified */ echo $_rand; ?>.toggleFileChange($(this).next('.input-box'))">
<?php /* @escapeNotVerified */ echo __('Change') ?>
</a>&nbsp;
Expand All @@ -79,7 +79,7 @@ require(['prototype'], function(){
<?php endif; ?>
<div class="input-box" <?php echo $_fileExists ? 'style="display:none"' : '' ?>>
<!-- ToDo UI: add appropriate file class when z-index issue in ui dialog will be resolved -->
<input type="file" name="<?php /* @escapeNotVerified */ echo $_fileName; ?>" class="product-custom-option<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?>" price="<?php /* @escapeNotVerified */ echo $block->getCurrencyPrice($_option->getPrice(true)) ?>" <?php echo $_fileExists ? 'disabled="disabled"' : '' ?>/>
<input type="file" name="<?php /* @noEscape */ echo $_fileName; ?>" class="product-custom-option<?php echo $_option->getIsRequire() ? ' required-entry' : '' ?>" price="<?php /* @escapeNotVerified */ echo $block->getCurrencyPrice($_option->getPrice(true)) ?>" <?php echo $_fileExists ? 'disabled="disabled"' : '' ?>/>
<input type="hidden" name="<?php /* @escapeNotVerified */ echo $_fieldNameAction; ?>" value="<?php /* @escapeNotVerified */ echo $_fieldValueAction; ?>" />

<?php if ($_option->getFileExtension()): ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
<?php $class = ($_option->getIsRequire()) ? ' required' : ''; ?>

<div class="field file<?php /* @escapeNotVerified */ echo $class; ?>">
<label class="label" for="<?php /* @escapeNotVerified */ echo $_fileName; ?>" id="<?php /* @escapeNotVerified */ echo $_fileName; ?>-label">
<label class="label" for="<?php /* @noEscape */ echo $_fileName; ?>" id="<?php /* @noEscape */ echo $_fileName; ?>-label">
<span><?php echo $block->escapeHtml($_option->getTitle()) ?></span>
<?php /* @escapeNotVerified */ echo $block->getFormatedPrice() ?>
</label>
<?php if ($_fileExists): ?>
<div class="control">
<span class="<?php /* @escapeNotVerified */ echo $_fileNamed ?>"><?php /* @escapeNotVerified */ echo $_fileInfo->getTitle(); ?></span>
<a href="javascript:void(0)" class="label" id="change-<?php /* @escapeNotVerified */ echo $_fileName ?>" >
<span class="<?php /* @noEscape */ echo $_fileNamed ?>"><?php echo $block->escapeHtml($_fileInfo->getTitle()); ?></span>
<a href="javascript:void(0)" class="label" id="change-<?php /* @noEscape */ echo $_fileName ?>" >
<?php /* @escapeNotVerified */ echo __('Change') ?>
</a>
<?php if (!$_option->getIsRequire()): ?>
Expand All @@ -35,8 +35,8 @@
<?php endif; ?>
<div class="control" id="input-box-<?php /* @escapeNotVerified */ echo $_fileName ?>"
data-mage-init='{"priceOptionFile":{
"fileName":"<?php /* @escapeNotVerified */ echo $_fileName ?>",
"fileNamed":"<?php /* @escapeNotVerified */ echo $_fileNamed ?>",
"fileName":"<?php /* @noEscape */ echo $_fileName ?>",
"fileNamed":"<?php /* @noEscape */ echo $_fileNamed ?>",
"fieldNameAction":"<?php /* @escapeNotVerified */ echo $_fieldNameAction ?>",
"changeFileSelector":"#change-<?php /* @escapeNotVerified */ echo $_fileName ?>",
"deleteFileSelector":"#delete-<?php /* @escapeNotVerified */ echo $_fileName ?>"}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogRule\Plugin\Indexer\Product\Save;

use Magento\CatalogRule\Model\Indexer\Product\ProductRuleProcessor;

class ApplyRulesAfterReindex
{
/**
* @var ProductRuleProcessor
*/
protected $productRuleProcessor;

/**
* @param ProductRuleProcessor $productRuleProcessor
*/
public function __construct(ProductRuleProcessor $productRuleProcessor)
{
$this->productRuleProcessor = $productRuleProcessor;
}

/**
* Apply catalog rules after product resource model save
*
* @param \Magento\Catalog\Model\Product $subject
* @param callable $proceed
* @return \Magento\Catalog\Model\Product
*/
public function aroundReindex(
\Magento\Catalog\Model\Product $subject,
callable $proceed
) {
$proceed();
$this->productRuleProcessor->reindexRow($subject->getId());
return;
}
}
12 changes: 12 additions & 0 deletions app/code/Magento/CatalogRule/etc/webapi_rest/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Product">
<plugin name="apply_catalog_rules_after_product_save_and_reindex" type="Magento\CatalogRule\Plugin\Indexer\Product\Save\ApplyRulesAfterReindex"/>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Catalog\Test\Fixture\CatalogAttributeSet;
use Magento\Catalog\Test\Fixture\CatalogProductSimple;
use Magento\Mtf\Fixture\InjectableFixture;
use Magento\Mtf\Fixture\FixtureFactory;
use Magento\Mtf\Constraint\AbstractConstraint;
use Magento\Catalog\Test\Fixture\CatalogProductAttribute;
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
Expand All @@ -20,13 +21,35 @@
*/
class AssertAddedProductAttributeOnProductForm extends AbstractConstraint
{
/**
* Fixture factory.
*
* @var FixtureFactory
*/
protected $fixtureFactory;

/**
* Catalog Product Index page.
*
* @var CatalogProductIndex
*/
protected $catalogProductIndex;

/**
* Catalog Product Edit page.
*
* @var CatalogProductEdit
*/
protected $catalogProductEdit;

/**
* Add this attribute to Default attribute Template. Create product and Assert that created attribute
* is displayed on product form (Products > Inventory > Catalog).
*
* @param InjectableFixture $product
* @param CatalogProductIndex $productGrid
* @param CatalogProductEdit $productEdit
* @param FixtureFactory $fixtureFactory
* @param CatalogProductIndex $catalogProductIndex
* @param CatalogProductEdit $catalogProductEdit
* @param CatalogProductAttribute $attribute
* @param CatalogAttributeSet $attributeSet
* @param CatalogProductAttribute $productAttributeOriginal
Expand All @@ -35,47 +58,44 @@ class AssertAddedProductAttributeOnProductForm extends AbstractConstraint
*/
public function processAssert(
InjectableFixture $product,
CatalogProductIndex $productGrid,
CatalogProductEdit $productEdit,
FixtureFactory $fixtureFactory,
CatalogProductIndex $catalogProductIndex,
CatalogProductEdit $catalogProductEdit,
CatalogProductAttribute $attribute,
CatalogAttributeSet $attributeSet,
CatalogProductAttribute $productAttributeOriginal = null
) {
$this->fixtureFactory = $fixtureFactory;
$this->catalogProductIndex = $catalogProductIndex;
$this->catalogProductEdit = $catalogProductEdit;

if (!$product->hasData('sku')) {
$product = $this->createProductWithAttributeSet($productAttributeOriginal, $attributeSet);
if (!$productAttributeOriginal) {
$productAttributeOriginal = $attribute;
}
$product = $this->objectManager->create(
'Magento\Catalog\Test\TestStep\CreateProductWithAttributeSetStep',
[
'attribute' => $productAttributeOriginal,
'attributeSet' => $attributeSet
]
)->run();
$product = $product['product'];
}
$filterProduct = ['sku' => $product->getSku()];
$productGrid->open();
$productGrid->getProductGrid()->searchAndOpen($filterProduct);
$catalogProductIndex->open();
$catalogProductIndex->getProductGrid()->searchAndOpen($filterProduct);

$catalogProductAttribute = ($productAttributeOriginal !== null)
? array_merge($productAttributeOriginal->getData(), $attribute->getData())
: $attribute->getData();

\PHPUnit_Framework_Assert::assertTrue(
$productEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute),
$catalogProductEdit->getProductForm()->checkAttributeLabel($catalogProductAttribute),
"Product Attribute is absent on Product form."
);
}

/**
* Create Product With AttributeSet.
*
* @param CatalogProductAttribute $attribute
* @param CatalogAttributeSet $attributeSet
* @return CatalogProductSimple
*/
protected function createProductWithAttributeSet(
CatalogProductAttribute $attribute,
CatalogAttributeSet $attributeSet
) {
$product = ObjectManager::getInstance()->create(
'Magento\Catalog\Test\TestStep\AddAttributeToAttributeSetStep',
['attribute' => $attribute, 'attributeSet' => $attributeSet]
)->run();
return $product['product'];
}

/**
* Text of Product Attribute is present on the Product form.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ public function __prepare(FixtureFactory $fixtureFactory)
* @param CatalogAttributeSet $attributeSet
* @param CatalogProductAttributeIndex $attributeIndex
* @param CatalogProductAttributeNew $attributeNew
* @param CatalogProductSimple $productSimple
* @return array
*/
public function testUpdateProductAttribute(
CatalogProductAttribute $productAttributeOriginal,
CatalogProductAttribute $attribute,
CatalogAttributeSet $attributeSet,
CatalogProductAttributeIndex $attributeIndex,
CatalogProductAttributeNew $attributeNew,
CatalogProductSimple $productSimple
CatalogProductAttributeNew $attributeNew
) {
//Precondition
$attributeSet->persist();
Expand All @@ -83,15 +81,32 @@ public function testUpdateProductAttribute(
'attribute_code' => $productAttributeOriginal->getAttributeCode(),
];

/** @var CatalogProductSimple $product */
$product = $this->fixtureFactory->createByCode(
'catalogProductSimple',
[
'dataset' => 'default',
'data' => ['attribute_set_id' => ['attribute_set' => $attributeSet]]
]
);
$product->persist();

$this->objectManager->create(
'Magento\Catalog\Test\TestStep\AddAttributeToAttributeSetStep',
[
'attribute' => $productAttributeOriginal,
'attributeSet' => $attributeSet
]
)->run();

//Steps
$attributeIndex->open();
$attributeIndex->getGrid()->searchAndOpen($filter);
$attributeNew->getAttributeForm()->fill($attribute);
$attributeNew->getPageActions()->save();
$attribute = $this->prepareAttribute($attribute, $productAttributeOriginal);
$productSimple->persist();

return ['product' => $this->prepareProduct($productSimple, $attribute, $attributeSet)];
return ['product' => $this->prepareProduct($product, $attribute, $attributeSet)];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@
<data name="attributeSet/dataset" xsi:type="string">custom_attribute_set</data>
<data name="productAttributeOriginal/dataset" xsi:type="string">attribute_type_dropdown</data>
<data name="attribute/data/frontend_label" xsi:type="string">Dropdown_%isolation%</data>
<data name="attribute/data/options/dataset" xsi:type="string">default</data>
<data name="attribute/data/is_required" xsi:type="string">Yes</data>
<data name="attribute/data/is_global" xsi:type="string">Global</data>
<data name="attribute/data/default_value_text" xsi:type="string">attribute_edited%isolation%</data>
<data name="attribute/data/options/dataset" xsi:type="string">default</data>
<data name="attribute/data/options/3/is_default" xsi:type="string">Yes</data>
<data name="attribute/data/options/3/admin" xsi:type="string">white_edited</data>
<data name="attribute/data/options/3/view" xsi:type="string">option_1_%isolation%_edited</data>
<data name="attribute/data/is_unique" xsi:type="string">Yes</data>
<data name="attribute/data/is_searchable" xsi:type="string">Yes</data>
<data name="attribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data>
Expand All @@ -51,7 +53,7 @@
<constraint name="Magento\Catalog\Test\Constraint\AssertAddedProductAttributeOnProductForm" />
</variation>
<variation name="UpdateProductAttributeEntityTestVariation3">
<data name="productTemplate/dataset" xsi:type="string">custom_attribute_set</data>
<data name="attributeSet/dataset" xsi:type="string">custom_attribute_set</data>
<data name="productAttributeOriginal/dataset" xsi:type="string">tax_class_id</data>
<data name="attribute/data/is_searchable" xsi:type="string">Yes</data>
<data name="attribute/data/is_visible_in_advanced_search" xsi:type="string">Yes</data>
Expand Down
Loading

0 comments on commit 32ec76e

Please sign in to comment.