Skip to content

Commit 96fbab3

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-86482' into 2.2-develop-pr37
2 parents 4c34cd1 + 32c9545 commit 96fbab3

File tree

13 files changed

+468
-9
lines changed

13 files changed

+468
-9
lines changed

app/code/Magento/Catalog/Test/Mftf/Data/ProductData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,8 @@
219219
<requiredEntity type="product_extension_attribute">EavStockItem</requiredEntity>
220220
<requiredEntity type="custom_attribute">CustomAttributeProductAttribute</requiredEntity>
221221
</entity>
222+
<entity name="ProductWithOptions2" type="product">
223+
<var key="sku" entityType="product" entityKey="sku" />
224+
<requiredEntity type="product_option">ProductOptionDropDownWithLongValuesTitle</requiredEntity>
225+
</entity>
222226
</entities>

app/code/Magento/Catalog/Test/Mftf/Data/ProductOptionData.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@
4848
<requiredEntity type="product_option_value">ProductOptionValueDropdown1</requiredEntity>
4949
<requiredEntity type="product_option_value">ProductOptionValueDropdown2</requiredEntity>
5050
</entity>
51+
<entity name="ProductOptionDropDownWithLongValuesTitle" type="product_option">
52+
<var key="product_sku" entityType="product" entityKey="sku" />
53+
<data key="title">OptionDropDownWithLongTitles</data>
54+
<data key="type">drop_down</data>
55+
<data key="sort_order">4</data>
56+
<data key="is_require">true</data>
57+
<requiredEntity type="product_option_value">ProductOptionValueDropdownLongTitle1</requiredEntity>
58+
<requiredEntity type="product_option_value">ProductOptionValueDropdownLongTitle2</requiredEntity>
59+
</entity>
5160
<entity name="ProductOptionRadiobutton" type="product_option">
5261
<var key="product_sku" entityType="product" entityKey="sku" />
5362
<data key="title">OptionRadioButtons</data>
@@ -101,4 +110,4 @@
101110
<data key="price">0.00</data>
102111
<data key="price_type">percent</data>
103112
</entity>
104-
</entities>
113+
</entities>

app/code/Magento/Catalog/Test/Mftf/Data/ProductOptionValueData.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@
4949
<data key="price">2</data>
5050
<data key="price_type">fixed</data>
5151
</entity>
52-
</entities>
52+
<entity name="ProductOptionValueDropdownLongTitle1" type="product_option_value">
53+
<data key="title">Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj11111Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj11111</data>
54+
<data key="sort_order">1</data>
55+
<data key="price">10</data>
56+
<data key="price_type">fixed</data>
57+
</entity>
58+
<entity name="ProductOptionValueDropdownLongTitle2" type="product_option_value">
59+
<data key="title">Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj22222Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj22222</data>
60+
<data key="sort_order">2</data>
61+
<data key="price">20</data>
62+
<data key="price_type">percent</data>
63+
</entity>
64+
</entities>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Test/etc/testSchema.xsd">
11+
<test name="StorefrontPurchaseProductWithCustomOptionsWithLongValuesTitle">
12+
<annotations>
13+
<group value="Catalog"/>
14+
<title value="Admin should be able to see the full title of the selected custom option value in the order"/>
15+
<description value="Admin should be able to see the full title of the selected custom option value in the order"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MAGETWO-93340"/>
18+
<group value="product"/>
19+
</annotations>
20+
<before>
21+
<!--Create Simple Product with Custom Options-->
22+
<createData entity="_defaultCategory" stepKey="createCategory"/>
23+
<createData entity="_defaultProduct" stepKey="createProduct">
24+
<requiredEntity createDataKey="createCategory"/>
25+
<field key="price">17</field>
26+
</createData>
27+
<updateData createDataKey="createProduct" entity="ProductWithOptions2" stepKey="updateProductWithOptions"/>
28+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
29+
</before>
30+
<after>
31+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
32+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
33+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
34+
</after>
35+
<!-- Login Customer Storefront -->
36+
<actionGroup ref="CustomerLoginOnStorefront" stepKey="customerLogin">
37+
<argument name="customer" value="$$createCustomer$$" />
38+
</actionGroup>
39+
<!-- Checking the correctness of displayed prices for user parameters -->
40+
<amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="amOnProductPage"/>
41+
<waitForPageLoad stepKey="waitForPageLoad"/>
42+
<seeElement selector="{{StorefrontProductInfoMainSection.productAttributeOptionsDropDown(ProductOptionDropDownWithLongValuesTitle.title, ProductOptionValueDropdownLongTitle1.price)}}" stepKey="checkDropDownProductOption"/>
43+
<!-- Adding items to the checkout -->
44+
<selectOption userInput="{{ProductOptionValueDropdownLongTitle1.price}}" selector="{{StorefrontProductInfoMainSection.productOptionSelect(ProductOptionDropDownWithLongValuesTitle.title)}}" stepKey="seeProductOptionDropDown"/>
45+
<grabTextFrom selector="{{StorefrontProductInfoMainSection.productPrice}}" stepKey="finalProductPrice"/>
46+
<actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="addToCartFromStorefrontProductPage">
47+
<argument name="productName" value="$$createProduct.name$$"/>
48+
</actionGroup>
49+
<!-- Checking the correctness of displayed custom options for user parameters on checkout -->
50+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart" />
51+
<conditionalClick selector="{{CheckoutPaymentSection.cartItemsArea}}" dependentSelector="{{CheckoutPaymentSection.cartItemsArea}}" visible="true" stepKey="exposeMiniCart"/>
52+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskForCartItem"/>
53+
<waitForElement selector="{{CheckoutPaymentSection.cartItemsAreaActive}}" time="30" stepKey="waitForCartItemsAreaActive"/>
54+
<see selector="{{CheckoutPaymentSection.cartItems}}" userInput="$$createProduct.name$$" stepKey="seeProductInCart"/>
55+
<conditionalClick selector="{{CheckoutPaymentSection.productOptionsByProductItemName($$createProduct.name$$)}}" dependentSelector="{{CheckoutPaymentSection.productOptionsActiveByProductItemName($$createProduct.name$$)}}" visible="false" stepKey="exposeProductOptions"/>
56+
<see selector="{{CheckoutPaymentSection.productOptionsActiveByProductItemName($$createProduct.name$$)}}" userInput="{{ProductOptionValueDropdownLongTitle1.title}}" stepKey="seeProductOptionValueDropdown1Input1"/>
57+
<click selector="{{CheckoutShippingSection.next}}" stepKey="clickNext"/>
58+
<!-- Place Order -->
59+
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectPayment"/>
60+
<waitForElement selector="{{CheckoutPaymentSection.placeOrder}}" time="30" stepKey="waitForPlaceOrderButton"/>
61+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrder"/>
62+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
63+
<!-- Login to Admin and open Order -->
64+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin1"/>
65+
<amOnPage url="{{AdminOrdersPage.url}}" stepKey="onOrdersPage"/>
66+
<waitForPageLoad stepKey="waitForPageLoad1"/>
67+
<fillField selector="{{AdminOrdersGridSection.search}}" userInput="{$grabOrderNumber}" stepKey="fillOrderNum"/>
68+
<click selector="{{AdminOrdersGridSection.submitSearch}}" stepKey="submitSearchOrderNum"/>
69+
<waitForLoadingMaskToDisappear stepKey="waitForLoadingMaskToDisappearOnSearch"/>
70+
<click selector="{{AdminOrdersGridSection.firstRow}}" stepKey="clickOrderRow"/>
71+
<!-- Checking the correctness of displayed custom options for user parameters on Order -->
72+
<dontSee selector="{{AdminOrderItemsOrderedSection.productNameOptions}}" userInput="{{ProductOptionValueDropdownLongTitle1.title}}" stepKey="dontSeeAdminOrderProductOptionValueDropdown1"/>
73+
<grabTextFrom selector="{{AdminOrderItemsOrderedSection.productNameOptions}} dd" stepKey="productOptionValueText"/>
74+
<assertEquals stepKey="checkProductOptionValue">
75+
<actualResult type="variable">productOptionValueText</actualResult>
76+
<expectedResult type="string">Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj111 ...</expectedResult>
77+
</assertEquals>
78+
<moveMouseOver selector="{{AdminOrderItemsOrderedSection.productNameOptions}} dd" stepKey="hoverProduct"/>
79+
<grabTextFrom selector="{{AdminOrderItemsOrderedSection.productNameOptions}} span:nth-child(2)" stepKey="productOptionValueTruncatedText"/>
80+
<assertEquals stepKey="checkProductOptionTruncatedValue">
81+
<actualResult type="variable">productOptionValueTruncatedText</actualResult>
82+
<expectedResult type="string">11Optisfvdklvfnkljvnfdklpvnfdjklfdvnjkvfdkjnvfdjkfvndj11111</expectedResult>
83+
</assertEquals>
84+
<seeElement selector="{{AdminOrderItemsOrderedSection.productNameOptions}} span:nth-child(2)" stepKey="seeAdminOrderProductOptionValueDropdown1"/>
85+
</test>
86+
</tests>

app/code/Magento/Sales/Block/Adminhtml/Items/Column/Name.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Sales\Block\Adminhtml\Items\Column;
79

10+
use Magento\Framework\Filter\TruncateFilter\Result;
11+
812
/**
913
* Sales Order items name column renderer
1014
*
@@ -13,6 +17,11 @@
1317
*/
1418
class Name extends \Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn
1519
{
20+
/**
21+
* @var Result
22+
*/
23+
private $truncateResult = null;
24+
1625
/**
1726
* Truncate string
1827
*
@@ -22,13 +31,20 @@ class Name extends \Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn
2231
* @param string &$remainder
2332
* @param bool $breakWords
2433
* @return string
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
2535
*/
26-
public function truncateString($value, $length = 80, $etc = '...', &$remainder = '', $breakWords = true)
27-
{
28-
return $this->filterManager->truncate(
36+
public function truncateString(
37+
string $value,
38+
int $length = 80,
39+
string $etc = '...',
40+
string &$remainder = '',
41+
bool $breakWords = true
42+
): string {
43+
$this->truncateResult = $this->filterManager->truncateFilter(
2944
$value,
30-
['length' => $length, 'etc' => $etc, 'remainder' => $remainder, 'breakWords' => $breakWords]
45+
['length' => $length, 'etc' => $etc, 'breakWords' => $breakWords]
3146
);
47+
return $this->truncateResult->getValue();
3248
}
3349

3450
/**
@@ -37,11 +53,14 @@ public function truncateString($value, $length = 80, $etc = '...', &$remainder =
3753
* @param string $value
3854
* @return array
3955
*/
40-
public function getFormattedOption($value)
56+
public function getFormattedOption(string $value): array
4157
{
4258
$remainder = '';
43-
$value = $this->truncateString($value, 55, '', $remainder);
44-
$result = ['value' => nl2br($value), 'remainder' => nl2br($remainder)];
59+
$this->truncateString($value, 55, '', $remainder);
60+
$result = [
61+
'value' => nl2br($this->truncateResult->getValue()),
62+
'remainder' => nl2br($this->truncateResult->getRemainder())
63+
];
4564

4665
return $result;
4766
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
11+
<section name="AdminOrdersGridSection">
12+
<element name="search" type="input" selector="#fulltext"/>
13+
<element name="submitSearch" type="button" selector=".//*[@id='container']/div/div[2]/div[1]/div[2]/button"/>
14+
<element name="firstRow" type="button" selector="tr.data-row:nth-of-type(1)"/>
15+
</section>
16+
</sections>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Filter;
9+
10+
class TruncateFilterTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @dataProvider truncateDataProvider
14+
* @param string $expectedValue
15+
* @param string $expectedRemainder
16+
* @param string $string
17+
* @param int $length
18+
* @param string $etc
19+
* @param bool $breakWords
20+
* @return void
21+
*/
22+
public function testFilter(
23+
string $expectedValue,
24+
string $expectedRemainder,
25+
string $string,
26+
int $length = 5,
27+
string $etc = '...',
28+
bool $breakWords = true
29+
) {
30+
/** @var TruncateFilter $truncateFilter */
31+
$truncateFilter = \Magento\TestFramework\ObjectManager::getInstance()->create(
32+
TruncateFilter::class,
33+
[
34+
'length' => $length,
35+
'etc' => $etc,
36+
'breakWords' => $breakWords,
37+
]
38+
);
39+
$result = $truncateFilter->filter($string);
40+
$this->assertEquals($expectedValue, $result->getValue());
41+
$this->assertEquals($expectedRemainder, $result->getRemainder());
42+
}
43+
44+
/**
45+
* @return array
46+
*/
47+
public function truncateDataProvider() : array
48+
{
49+
return [
50+
'1' => [
51+
'12...',
52+
'34567890',
53+
'1234567890',
54+
],
55+
'2' => [
56+
'123..',
57+
' 456 789',
58+
'123 456 789',
59+
8,
60+
'..',
61+
false,
62+
],
63+
];
64+
}
65+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Block\Adminhtml\Items\Column;
9+
10+
/**
11+
* @magentoAppArea adminhtml
12+
*/
13+
class NameTest extends \PHPUnit\Framework\TestCase
14+
{
15+
/**
16+
* @var Name
17+
*/
18+
private $block;
19+
20+
protected function setUp()
21+
{
22+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
23+
/** @var $layout \Magento\Framework\View\Layout */
24+
$layout = $objectManager->create(\Magento\Framework\View\LayoutInterface::class);
25+
/** @var $block \Magento\Sales\Block\Adminhtml\Items\AbstractItems */
26+
$this->block = $layout->createBlock(Name::class, 'block');
27+
}
28+
29+
/**
30+
* @return void
31+
*/
32+
public function testTruncateString()
33+
{
34+
$remainder = '';
35+
$this->assertEquals(
36+
'12345',
37+
$this->block->truncateString('1234567890', 5, '', $remainder)
38+
);
39+
}
40+
41+
/**
42+
* @return void
43+
*/
44+
public function testGetFormattedOption()
45+
{
46+
$this->assertEquals(
47+
[
48+
'value' => '1234567890123456789012345678901234567890123456789012345',
49+
'remainder' => '67890',
50+
],
51+
$this->block->getFormattedOption(
52+
'123456789012345678901234567890123456789012345678901234567890'
53+
)
54+
);
55+
}
56+
}

lib/internal/Magento/Framework/Filter/Factory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Factory extends AbstractFactory
3232
'decrypt' => \Magento\Framework\Filter\Decrypt::class,
3333
'translit' => \Magento\Framework\Filter\Translit::class,
3434
'translitUrl' => \Magento\Framework\Filter\TranslitUrl::class,
35+
'truncateFilter' => \Magento\Framework\Filter\TruncateFilter::class,
3536
];
3637

3738
/**

lib/internal/Magento/Framework/Filter/FilterManager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* @method string removeTags(string $value, $params = array())
2222
* @method string stripTags(string $value, $params = array())
2323
* @method string truncate(string $value, $params = array())
24+
* @method string truncateFilter(string $value, $params = array())
2425
* @method string encrypt(string $value, $params = array())
2526
* @method string decrypt(string $value, $params = array())
2627
* @method string translit(string $value)

0 commit comments

Comments
 (0)