Skip to content

Commit

Permalink
Merge pull request #1833 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
EngCom] Public Pull Requests - 2.2-develop
 - MAGETWO-85520: Remove @escapenotverified from documentation #12639
 - MAGETWO-85317: 12526: Currency change, Bank Transfer but checkout page shows "Your credit card will be charged for" #993
 - MAGETWO-85298: 8011: Strip Tags from attribute. #968
 - MAGETWO-85294: 12535: Product change sku via repository. #984
 - MAGETWO-85274: Update CrontabManager.php #12610
 - MAGETWO-84994: 8862: Can't emptying values by magento 2 api #916
  • Loading branch information
ishakhsuvarov authored Dec 12, 2017
2 parents a1ee98a + 3ee65c1 commit 5f763a9
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 23 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,13 @@ protected function initializeProductData(array $productData, $createNew)
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
}
} else {
unset($this->instances[$productData['sku']]);
$product = $this->get($productData['sku']);
if (!empty($productData['id'])) {
unset($this->instancesById[$productData['id']]);
$product = $this->getById($productData['id']);
} else {
unset($this->instances[$productData['sku']]);
$product = $this->get($productData['sku']);
}
}

foreach ($productData as $key => $value) {
Expand Down Expand Up @@ -562,7 +567,7 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
$tierPrices = $product->getData('tier_price');

try {
$existingProduct = $this->get($product->getSku());
$existingProduct = $product->getId() ? $this->getById($product->getId()) : $this->get($product->getSku());

$product->setData(
$this->resourceModel->getLinkField(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public function testSaveException()
->willReturn(true);
$this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock)
->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123')));
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(null);
$this->extensibleDataObjectConverterMock
->expects($this->once())
->method('toNestedArray')
Expand All @@ -634,7 +634,7 @@ public function testSaveInvalidProductException()
$this->initializationHelperMock->expects($this->never())->method('initialize');
$this->resourceModelMock->expects($this->once())->method('validate')->with($this->productMock)
->willReturn(['error1', 'error2']);
$this->productMock->expects($this->never())->method('getId');
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
$this->extensibleDataObjectConverterMock
->expects($this->once())
->method('toNestedArray')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ protected function _prepareValueOptions()
} else {
$addEmptyOption = true;
}
$selectOptions = $attributeObject->getSource()->getAllOptions($addEmptyOption);
$selectOptions = $this->removeTagsFromLabel(
$attributeObject->getSource()->getAllOptions($addEmptyOption)
);
}
}

Expand Down Expand Up @@ -734,4 +736,21 @@ protected function getEavAttributeTableAlias()

return 'at_' . $attribute->getAttributeCode();
}

/**
* Remove html tags from attribute labels.
*
* @param array $selectOptions
* @return array
*/
private function removeTagsFromLabel(array $selectOptions)
{
foreach ($selectOptions as &$option) {
if (isset($option['label'])) {
$option['label'] = strip_tags($option['label']);
}
}

return $selectOptions;
}
}
3 changes: 2 additions & 1 deletion app/code/Magento/Tax/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,5 @@ Rate,Rate
"Order Total Incl. Tax","Order Total Incl. Tax"
"Order Total","Order Total"
"Your credit card will be charged for","Your credit card will be charged for"
"An error occurred while loading tax rates.","An error occurred while loading tax rates."
"An error occurred while loading tax rates.","An error occurred while loading tax rates."
"You will be charged for","You will be charged for"
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<item name="config" xsi:type="array">
<item name="exclTaxLabel" xsi:type="string" translate="true">Order Total Excl. Tax</item>
<item name="inclTaxLabel" xsi:type="string" translate="true">Order Total Incl. Tax</item>
<item name="basicCurrencyMessage" xsi:type="string" translate="true">Your credit card will be charged for</item>
<item name="basicCurrencyMessage" xsi:type="string" translate="true">You will be charged for</item>
<item name="title" xsi:type="string" translate="true">Order Total</item>
</item>
</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Model;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Provide tests for ProductRepository model.
*/
class ProductRepositoryTest extends \PHPUnit\Framework\TestCase
{
/**
* Test subject.
*
* @var ProductRepositoryInterface
*/
private $productRepository;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
}

/**
* Test Product Repository can change(update) "sku" for given product.
*
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
* @magentoAppArea adminhtml
*/
public function testUpdateProductSku()
{
$newSku = 'simple-edited';
$productId = Bootstrap::getObjectManager()->get(ProductResource::class)->getIdBySku('simple');
$initialProduct = Bootstrap::getObjectManager()->create(Product::class)->load($productId);

$initialProduct->setSku($newSku);
$this->productRepository->save($initialProduct);

$updatedProduct = Bootstrap::getObjectManager()->create(Product::class);
$updatedProduct->load($productId);
self::assertSame($newSku, $updatedProduct->getSku());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Rule\Model\Condition\Product;

use Magento\Backend\Helper\Data;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\ProductCategoryList;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\ResourceModel\Product;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
use Magento\Framework\Locale\FormatInterface;
use Magento\Rule\Model\Condition\Context;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Provide tests for Abstract Rule product condition data model.
* @magentoAppArea adminhtml
*/
class AbstractProductTest extends \PHPUnit\Framework\TestCase
{
/**
* Test subject.
*
* @var AbstractProduct|\PHPUnit_Framework_MockObject_MockObject
*/
private $model;

/**
* @inheritdoc
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$context = $objectManager->get(Context::class);
$helperData = $objectManager->get(Data::class);
$config = $objectManager->get(Config::class);
$productFactory = $objectManager->get(ProductFactory::class);
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
$productResource = $objectManager->get(Product::class);
$attributeSetCollection = $objectManager->get(Collection::class);
$localeFormat = $objectManager->get(FormatInterface::class);
$data = [];
$productCategoryList = $objectManager->get(ProductCategoryList::class);
$this->model = $this->getMockBuilder(AbstractProduct::class)
->setMethods(['getOperator', 'getFormName', 'setFormName'])
->setConstructorArgs([
$context,
$helperData,
$config,
$productFactory,
$productRepository,
$productResource,
$attributeSetCollection,
$localeFormat,
$data,
$productCategoryList
])
->getMockForAbstractClass();
}

/**
* Test Abstract Rule product condition data model shows attribute labels in more readable view
* (without html tags, if one presented).
*
* @magentoDataFixture Magento/Rule/_files/dropdown_attribute_with_html.php
*/
public function testGetValueSelectOptions()
{
$expectedLabels = [' ', 'Option 1', 'Option 2', 'Option 3'];
$this->model->setAttribute('dropdown_attribute_with_html');
$options = $this->model->getValueSelectOptions();
$labels = [];
foreach ($options as $option) {
$labels[] = $option['label'];
}
self::assertSame($expectedLabels, $labels);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/* Create attribute */
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
);

if (!$attribute->loadByCode(4, 'dropdown_attribute_with_html')->getId()) {
/** @var $installer \Magento\Catalog\Setup\CategorySetup */
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Setup\CategorySetup::class
);

$attribute->setData(
[
'attribute_code' => 'dropdown_attribute_with_html',
'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
'is_global' => 0,
'is_user_defined' => 1,
'frontend_input' => 'select',
'is_unique' => 0,
'is_required' => 0,
'is_searchable' => 0,
'is_visible_in_advanced_search' => 0,
'is_comparable' => 0,
'is_filterable' => 0,
'is_filterable_in_search' => 0,
'is_used_for_promo_rules' => 0,
'is_html_allowed_on_front' => 1,
'is_visible_on_front' => 0,
'used_in_product_listing' => 0,
'used_for_sort_by' => 0,
'frontend_label' => ['Drop-Down Attribute'],
'backend_type' => 'varchar',
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
'option' => [
'value' => [
'option_1' => ['<a href="#">Option 1</a>'],
'option_2' => ['<a href="#">Option 2</a>'],
'option_3' => ['<a href="#">Option 3</a>'],
],
'order' => [
'option_1' => 1,
'option_2' => 2,
'option_3' => 3,
],
],
]
);
$attribute->save();

/* Assign attribute to attribute set */
$installer->addAttributeToGroup('catalog_product', 'Default', 'Attributes', $attribute->getId());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/* Delete attribute with dropdown_attribute_with_html code */

use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\TestFramework\Helper\Bootstrap;

$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
/** @var $attribute Attribute */
$attribute = Bootstrap::getObjectManager()->create(
Attribute::class
);
$attribute->load('dropdown_attribute_with_html', 'attribute_code');
$attribute->delete();

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ public function testXssSensitiveOutput()
* Static test will cover the following cases:
*
* 1. /\* @noEscape \*\/ before output. Output doesn't require escaping. Test is green.
* 2. /\* @escapeNotVerified \*\/ before output. Output escaping is not checked and
* should be verified. Test is green.
* 3. Methods which contains "html" in their names (e.g. echo $object->{suffix}Html{postfix}() ).
* 2. Methods which contains "html" in their names (e.g. echo $object->{suffix}Html{postfix}() ).
* Data is ready for the HTML output. Test is green.
* 4. AbstractBlock methods escapeHtml, escapeUrl, escapeQuote, escapeXssInUrl are allowed. Test is green.
* 5. Type casting and php function count() are allowed
* 3. AbstractBlock methods escapeHtml, escapeUrl, escapeQuote, escapeXssInUrl are allowed. Test is green.
* 4. Type casting and php function count() are allowed
* (e.g. echo (int)$var, echo (float)$var, echo (bool)$var, echo count($var)). Test is green.
* 6. Output in single quotes (e.g. echo 'some text'). Test is green.
* 7. Output in double quotes without variables (e.g. echo "some text"). Test is green.
* 8. Other of p.1-7. Output is not escaped. Test is red.
* 5. Output in single quotes (e.g. echo 'some text'). Test is green.
* 6. Output in double quotes without variables (e.g. echo "some text"). Test is green.
* 7. Other of p.1-6. Output is not escaped. Test is red.
*
* @param string $file
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/Magento/Framework/Crontab/CrontabManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ public function removeTasks()
private function generateSection($content, $tasks = [])
{
if ($tasks) {
// Add EOL symbol to previous line if not exist.
if (substr($content, -strlen(PHP_EOL)) !== PHP_EOL) {
$content .= PHP_EOL;
}

$content .= $this->getTasksBlockStart() . PHP_EOL;
foreach ($tasks as $task) {
$content .= $task['expression'] . ' ' . PHP_BINARY . ' ' . $task['command'] . PHP_EOL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ public function saveTasksDataProvider()
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
. CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL,
],
[
'tasks' => [
['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"']
],
'content' => '* * * * * /bin/php /var/www/cron.php',
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
. CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php'
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
. CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL,
],
];
}
}
Loading

0 comments on commit 5f763a9

Please sign in to comment.