-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalize new line symbols in Product Text Option (type=area) #26033
Normalize new line symbols in Product Text Option (type=area) #26033
Conversation
…Option counted differently on backend/frontend"
Hi @Leone. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How your change would behave if some extension code will provide null
or other unexpected input?
*/ | ||
private function normalizeNewLineSymbols($value) | ||
{ | ||
return str_replace(["\r\n", "\n\r", "\r"], ["\n", "\n", "\n"], $value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second argument does not have to be an array: https://3v4l.org/lkhbV
echo str_replace(['a','b','c'], 'd', 'abcdef');
* @param string $value | ||
* @return string | ||
*/ | ||
private function normalizeNewLineSymbols($value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add type hints
/** | ||
* Test for customizable product option with "Text" type | ||
*/ | ||
class TextTest extends \PHPUnit\Framework\TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import class.
/** | ||
* @var Text | ||
*/ | ||
protected $model; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good practice is to use class name / class abstract instead of generic model
.
protected $model; | ||
|
||
/** | ||
* @var \Magento\Framework\ObjectManagerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import class.
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); | ||
$this->model = $this->objectManager->create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to split that into multiple lines.
*/ | ||
protected function setUp() | ||
{ | ||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import class.
{ | ||
return [ | ||
[ | ||
// $productOptionData |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding comments, just replace that with:
[self::STUB_OPTION_DATA, "string \r\n string", "string \n string"],
And extract ['id' => 11, 'type' => 'area']
to private const.
@lbajsarowicz thank you for feedback.
|
|
||
namespace Magento\Catalog\Model\Product\Option\Type; | ||
|
||
use Magento\Catalog\Model\Product\Option; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can organize imports (CTRL + SHIFT + O in PHPStorm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution. You may organize imports.
Hi @lbajsarowicz, thank you for the review.
|
✔️ QA Passed |
@Leone, please fix the failed tests. |
If eliminating Session dependency requires too much effort, the test can be skipped by adding |
Hi @lbajsarowicz, thank you for the review. |
@sivaschenko Indeed, eliminating Session dependency requires too much effort. I added |
✔️ QA Passed |
Hi @Leone, thank you for your contribution! |
Description (*)
Normalize new line symbols in Product Text Option (type=area).
If you add a customizable option to the product (type = area, max characters X), the length of the option value is counts differently by javascript validator and php.
I added the method to normalize new line symbols in text option.
Fixed Issues (if relevant)
Manual testing scenarios (*)
Steps to reproduce from #25974
'Is
twenty
characters'
=> Ok on front, but error on adding to cart: 'The text is too long.'
Questions or comments
Contribution checklist (*)