Skip to content

Commit 5f763a9

Browse files
Merge pull request #1833 from magento-engcom/2.2-develop-prs
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
2 parents a1ee98a + 3ee65c1 commit 5f763a9

File tree

14 files changed

+333
-23
lines changed

14 files changed

+333
-23
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,13 @@ protected function initializeProductData(array $productData, $createNew)
333333
$product->setWebsiteIds([$this->storeManager->getStore(true)->getWebsiteId()]);
334334
}
335335
} else {
336-
unset($this->instances[$productData['sku']]);
337-
$product = $this->get($productData['sku']);
336+
if (!empty($productData['id'])) {
337+
unset($this->instancesById[$productData['id']]);
338+
$product = $this->getById($productData['id']);
339+
} else {
340+
unset($this->instances[$productData['sku']]);
341+
$product = $this->get($productData['sku']);
342+
}
338343
}
339344

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

564569
try {
565-
$existingProduct = $this->get($product->getSku());
570+
$existingProduct = $product->getId() ? $this->getById($product->getId()) : $this->get($product->getSku());
566571

567572
$product->setData(
568573
$this->resourceModel->getLinkField(),

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ public function testSaveException()
610610
->willReturn(true);
611611
$this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock)
612612
->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123')));
613-
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
613+
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(null);
614614
$this->extensibleDataObjectConverterMock
615615
->expects($this->once())
616616
->method('toNestedArray')
@@ -634,7 +634,7 @@ public function testSaveInvalidProductException()
634634
$this->initializationHelperMock->expects($this->never())->method('initialize');
635635
$this->resourceModelMock->expects($this->once())->method('validate')->with($this->productMock)
636636
->willReturn(['error1', 'error2']);
637-
$this->productMock->expects($this->never())->method('getId');
637+
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
638638
$this->extensibleDataObjectConverterMock
639639
->expects($this->once())
640640
->method('toNestedArray')

app/code/Magento/Rule/Model/Condition/Product/AbstractProduct.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,9 @@ protected function _prepareValueOptions()
241241
} else {
242242
$addEmptyOption = true;
243243
}
244-
$selectOptions = $attributeObject->getSource()->getAllOptions($addEmptyOption);
244+
$selectOptions = $this->removeTagsFromLabel(
245+
$attributeObject->getSource()->getAllOptions($addEmptyOption)
246+
);
245247
}
246248
}
247249

@@ -734,4 +736,21 @@ protected function getEavAttributeTableAlias()
734736

735737
return 'at_' . $attribute->getAttributeCode();
736738
}
739+
740+
/**
741+
* Remove html tags from attribute labels.
742+
*
743+
* @param array $selectOptions
744+
* @return array
745+
*/
746+
private function removeTagsFromLabel(array $selectOptions)
747+
{
748+
foreach ($selectOptions as &$option) {
749+
if (isset($option['label'])) {
750+
$option['label'] = strip_tags($option['label']);
751+
}
752+
}
753+
754+
return $selectOptions;
755+
}
737756
}

app/code/Magento/Tax/i18n/en_US.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,5 @@ Rate,Rate
176176
"Order Total Incl. Tax","Order Total Incl. Tax"
177177
"Order Total","Order Total"
178178
"Your credit card will be charged for","Your credit card will be charged for"
179-
"An error occurred while loading tax rates.","An error occurred while loading tax rates."
179+
"An error occurred while loading tax rates.","An error occurred while loading tax rates."
180+
"You will be charged for","You will be charged for"

app/code/Magento/Tax/view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<item name="config" xsi:type="array">
7171
<item name="exclTaxLabel" xsi:type="string" translate="true">Order Total Excl. Tax</item>
7272
<item name="inclTaxLabel" xsi:type="string" translate="true">Order Total Incl. Tax</item>
73-
<item name="basicCurrencyMessage" xsi:type="string" translate="true">Your credit card will be charged for</item>
73+
<item name="basicCurrencyMessage" xsi:type="string" translate="true">You will be charged for</item>
7474
<item name="title" xsi:type="string" translate="true">Order Total</item>
7575
</item>
7676
</item>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Model;
8+
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
13+
/**
14+
* Provide tests for ProductRepository model.
15+
*/
16+
class ProductRepositoryTest extends \PHPUnit\Framework\TestCase
17+
{
18+
/**
19+
* Test subject.
20+
*
21+
* @var ProductRepositoryInterface
22+
*/
23+
private $productRepository;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp()
29+
{
30+
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
31+
}
32+
33+
/**
34+
* Test Product Repository can change(update) "sku" for given product.
35+
*
36+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
37+
* @magentoAppArea adminhtml
38+
*/
39+
public function testUpdateProductSku()
40+
{
41+
$newSku = 'simple-edited';
42+
$productId = Bootstrap::getObjectManager()->get(ProductResource::class)->getIdBySku('simple');
43+
$initialProduct = Bootstrap::getObjectManager()->create(Product::class)->load($productId);
44+
45+
$initialProduct->setSku($newSku);
46+
$this->productRepository->save($initialProduct);
47+
48+
$updatedProduct = Bootstrap::getObjectManager()->create(Product::class);
49+
$updatedProduct->load($productId);
50+
self::assertSame($newSku, $updatedProduct->getSku());
51+
}
52+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Rule\Model\Condition\Product;
8+
9+
use Magento\Backend\Helper\Data;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\ProductCategoryList;
12+
use Magento\Catalog\Model\ProductFactory;
13+
use Magento\Catalog\Model\ResourceModel\Product;
14+
use Magento\Eav\Model\Config;
15+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection;
16+
use Magento\Framework\Locale\FormatInterface;
17+
use Magento\Rule\Model\Condition\Context;
18+
use Magento\TestFramework\Helper\Bootstrap;
19+
20+
/**
21+
* Provide tests for Abstract Rule product condition data model.
22+
* @magentoAppArea adminhtml
23+
*/
24+
class AbstractProductTest extends \PHPUnit\Framework\TestCase
25+
{
26+
/**
27+
* Test subject.
28+
*
29+
* @var AbstractProduct|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $model;
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
protected function setUp()
37+
{
38+
$objectManager = Bootstrap::getObjectManager();
39+
$context = $objectManager->get(Context::class);
40+
$helperData = $objectManager->get(Data::class);
41+
$config = $objectManager->get(Config::class);
42+
$productFactory = $objectManager->get(ProductFactory::class);
43+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
44+
$productResource = $objectManager->get(Product::class);
45+
$attributeSetCollection = $objectManager->get(Collection::class);
46+
$localeFormat = $objectManager->get(FormatInterface::class);
47+
$data = [];
48+
$productCategoryList = $objectManager->get(ProductCategoryList::class);
49+
$this->model = $this->getMockBuilder(AbstractProduct::class)
50+
->setMethods(['getOperator', 'getFormName', 'setFormName'])
51+
->setConstructorArgs([
52+
$context,
53+
$helperData,
54+
$config,
55+
$productFactory,
56+
$productRepository,
57+
$productResource,
58+
$attributeSetCollection,
59+
$localeFormat,
60+
$data,
61+
$productCategoryList
62+
])
63+
->getMockForAbstractClass();
64+
}
65+
66+
/**
67+
* Test Abstract Rule product condition data model shows attribute labels in more readable view
68+
* (without html tags, if one presented).
69+
*
70+
* @magentoDataFixture Magento/Rule/_files/dropdown_attribute_with_html.php
71+
*/
72+
public function testGetValueSelectOptions()
73+
{
74+
$expectedLabels = [' ', 'Option 1', 'Option 2', 'Option 3'];
75+
$this->model->setAttribute('dropdown_attribute_with_html');
76+
$options = $this->model->getValueSelectOptions();
77+
$labels = [];
78+
foreach ($options as $option) {
79+
$labels[] = $option['label'];
80+
}
81+
self::assertSame($expectedLabels, $labels);
82+
}
83+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/* Create attribute */
8+
/** @var $attribute \Magento\Catalog\Model\ResourceModel\Eav\Attribute */
9+
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
10+
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
11+
);
12+
13+
if (!$attribute->loadByCode(4, 'dropdown_attribute_with_html')->getId()) {
14+
/** @var $installer \Magento\Catalog\Setup\CategorySetup */
15+
$installer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
16+
\Magento\Catalog\Setup\CategorySetup::class
17+
);
18+
19+
$attribute->setData(
20+
[
21+
'attribute_code' => 'dropdown_attribute_with_html',
22+
'entity_type_id' => $installer->getEntityTypeId('catalog_product'),
23+
'is_global' => 0,
24+
'is_user_defined' => 1,
25+
'frontend_input' => 'select',
26+
'is_unique' => 0,
27+
'is_required' => 0,
28+
'is_searchable' => 0,
29+
'is_visible_in_advanced_search' => 0,
30+
'is_comparable' => 0,
31+
'is_filterable' => 0,
32+
'is_filterable_in_search' => 0,
33+
'is_used_for_promo_rules' => 0,
34+
'is_html_allowed_on_front' => 1,
35+
'is_visible_on_front' => 0,
36+
'used_in_product_listing' => 0,
37+
'used_for_sort_by' => 0,
38+
'frontend_label' => ['Drop-Down Attribute'],
39+
'backend_type' => 'varchar',
40+
'backend_model' => \Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend::class,
41+
'option' => [
42+
'value' => [
43+
'option_1' => ['<a href="#">Option 1</a>'],
44+
'option_2' => ['<a href="#">Option 2</a>'],
45+
'option_3' => ['<a href="#">Option 3</a>'],
46+
],
47+
'order' => [
48+
'option_1' => 1,
49+
'option_2' => 2,
50+
'option_3' => 3,
51+
],
52+
],
53+
]
54+
);
55+
$attribute->save();
56+
57+
/* Assign attribute to attribute set */
58+
$installer->addAttributeToGroup('catalog_product', 'Default', 'Attributes', $attribute->getId());
59+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
/* Delete attribute with dropdown_attribute_with_html code */
7+
8+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
9+
use Magento\TestFramework\Helper\Bootstrap;
10+
11+
$registry = Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class);
12+
$registry->unregister('isSecureArea');
13+
$registry->register('isSecureArea', true);
14+
/** @var $attribute Attribute */
15+
$attribute = Bootstrap::getObjectManager()->create(
16+
Attribute::class
17+
);
18+
$attribute->load('dropdown_attribute_with_html', 'attribute_code');
19+
$attribute->delete();
20+
21+
$registry->unregister('isSecureArea');
22+
$registry->register('isSecureArea', false);

dev/tests/static/testsuite/Magento/Test/Php/XssPhtmlTemplateTest.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@ public function testXssSensitiveOutput()
2727
* Static test will cover the following cases:
2828
*
2929
* 1. /\* @noEscape \*\/ before output. Output doesn't require escaping. Test is green.
30-
* 2. /\* @escapeNotVerified \*\/ before output. Output escaping is not checked and
31-
* should be verified. Test is green.
32-
* 3. Methods which contains "html" in their names (e.g. echo $object->{suffix}Html{postfix}() ).
30+
* 2. Methods which contains "html" in their names (e.g. echo $object->{suffix}Html{postfix}() ).
3331
* Data is ready for the HTML output. Test is green.
34-
* 4. AbstractBlock methods escapeHtml, escapeUrl, escapeQuote, escapeXssInUrl are allowed. Test is green.
35-
* 5. Type casting and php function count() are allowed
32+
* 3. AbstractBlock methods escapeHtml, escapeUrl, escapeQuote, escapeXssInUrl are allowed. Test is green.
33+
* 4. Type casting and php function count() are allowed
3634
* (e.g. echo (int)$var, echo (float)$var, echo (bool)$var, echo count($var)). Test is green.
37-
* 6. Output in single quotes (e.g. echo 'some text'). Test is green.
38-
* 7. Output in double quotes without variables (e.g. echo "some text"). Test is green.
39-
* 8. Other of p.1-7. Output is not escaped. Test is red.
35+
* 5. Output in single quotes (e.g. echo 'some text'). Test is green.
36+
* 6. Output in double quotes without variables (e.g. echo "some text"). Test is green.
37+
* 7. Other of p.1-6. Output is not escaped. Test is red.
4038
*
4139
* @param string $file
4240
*/

lib/internal/Magento/Framework/Crontab/CrontabManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ public function removeTasks()
138138
private function generateSection($content, $tasks = [])
139139
{
140140
if ($tasks) {
141+
// Add EOL symbol to previous line if not exist.
142+
if (substr($content, -strlen(PHP_EOL)) !== PHP_EOL) {
143+
$content .= PHP_EOL;
144+
}
145+
141146
$content .= $this->getTasksBlockStart() . PHP_EOL;
142147
foreach ($tasks as $task) {
143148
$content .= $task['expression'] . ' ' . PHP_BINARY . ' ' . $task['command'] . PHP_EOL;

lib/internal/Magento/Framework/Crontab/Test/Unit/CrontabManagerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,17 @@ public function saveTasksDataProvider()
337337
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
338338
. CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL,
339339
],
340+
[
341+
'tasks' => [
342+
['command' => '{magentoRoot}run.php % cron:run | grep -v "Ran \'jobs\' by schedule"']
343+
],
344+
'content' => '* * * * * /bin/php /var/www/cron.php',
345+
'contentToSave' => '* * * * * /bin/php /var/www/cron.php' . PHP_EOL
346+
. CrontabManagerInterface::TASKS_BLOCK_START . ' ' . md5(BP) . PHP_EOL
347+
. '* * * * * ' . PHP_BINARY . ' /var/www/magento2/run.php'
348+
. ' %% cron:run | grep -v \"Ran \'jobs\' by schedule\"' . PHP_EOL
349+
. CrontabManagerInterface::TASKS_BLOCK_END . ' ' . md5(BP) . PHP_EOL,
350+
],
340351
];
341352
}
342353
}

0 commit comments

Comments
 (0)