Skip to content
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

Rest api multiselect attribute bc break between 2.1.8 and 2.3.0 #21901

Conversation

Valant13
Copy link
Contributor

Description (*)

Correct conditions for multiselect attribute validation have been added.
Unit test for app/code/Magento/Eav/Model/TypeLocator/SimpleType.php has been created.

Fixed Issues (if relevant)

  1. REST API multiselect attribute BC break between 2.1.8 and 2.3.0 #21364: Rest api multiselect attribute bc break between 2.1.8 and 2.3.0

Manual testing scenarios (*)

  1. Create multiple select product attribute
  2. Create product attribute set
  3. Create simple product and assign it to created attribute set
  4. Update product using PUT method of catalogProductRepositoryV1 API

Sample JSON body (options as string with ids separated by comma):

{
  "product": {
    "sku": "Test Simple Product",
    "custom_attributes": [
      {
        "attribute_code": "test_multiselect",
        "value": "4,5"
      }
    ]
  },
  "saveOptions": true
}

Sample JSON body (options as array of ids in string):

{
  "product": {
    "sku": "Test Simple Product",
    "custom_attributes": [
      {
        "attribute_code": "test_multiselect",
        "value": ["4", "5"]
      }
    ]
  },
  "saveOptions": true
}

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Mar 22, 2019

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team
Copy link
Contributor

Hi @Valant13. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added Component: Eav Release Line: 2.3 Partner: ISM eCompany Pull Request is created by partner ISM eCompany partners-contribution Pull Request is created by Magento Partner labels Mar 22, 2019
@kandy kandy requested a review from paliarush March 22, 2019 18:44
@orlangur orlangur self-assigned this Mar 23, 2019
Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contribution @Valant13!

Please check my comments, simplify implementation and unit test.

Also, please write an API test covering initial case and after all builds are green, squash changes into a single commit.


$arrayFrontendInputs = ['multiselect'];
$frontendInput = $attribute->getFrontendInput();
if (in_array($frontendInput, $arrayFrontendInputs)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (in_array($frontendInput, $arrayFrontendInputs)) {
if ($attribute->getFrontendInput() === 'multiselect') {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for the review.
Do you mean integration tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* @var Attribute|\PHPUnit_Framework_MockObject_MockObject
*/
$attributeMock = $this->getMockBuilder(Attribute::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix formatting and use createMock instead to make mock declarations more compact.

/**
* @var SimpleType|\PHPUnit_Framework_MockObject_MockObject
*/
$simpleType = ($this->objectManger)->getObject(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get rid of ObjectManager and setUp method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @orlangur. I use ObjectManager to create testable class instance. What should I use instead ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant just get rid of property and setUp method but here it also makes sense to replace it with new operator.

* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getTypeDataProvider()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such test does not actually verify anything. It's just a method logic written in a different form.

Try splitting into proper test cases.

@Valant13 Valant13 force-pushed the REST-API-multiselect-attribute-BC-break-between-2.1.8-and-2.3.0 branch from 963f3b7 to c0370a7 Compare March 25, 2019 07:11
@sidolov
Copy link
Contributor

sidolov commented Apr 8, 2019

Hi @Valant13 , looks like you made some commits with email different than in your GitHub profile, please, add email from commits to your profile!
Thank you!

@Valant13 Valant13 requested a review from orlangur April 17, 2019 08:22
/**
* @var SimpleType|\PHPUnit_Framework_MockObject_MockObject
*/
$simpleType = ($this->objectManger)->getObject(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant just get rid of property and setUp method but here it also makes sense to replace it with new operator.

@Valant13 Valant13 requested a review from orlangur April 17, 2019 09:54
Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Valant13 perfect! 👍

LGTM, please squash changes into a single commit so that we have perfectly clean history 😉

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-4920 has been created to process this Pull Request

Copy link
Contributor

@orlangur orlangur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are still not squashed. @Valant13 please do it.

@Valant13
Copy link
Contributor Author

Valant13 commented May 3, 2019

@orlangur, sorry for delay. I will squash changes on the next week

Add conditions for multiselect attribute validation.

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Create unit test for app/code/Magento/Eav/Model/TypeLocator/SimpleType.php.

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Code refactoring.

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Code refactoring.

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Change unit test functionality for app/code/Magento/Eav/Model/TypeLocator/SimpleType.php.

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Create api-functional test for the following case

REST API multiselect attribute BC break between 2.1.8 and 2.3.0.
Remove ObjectManager and setUp method.
@Valant13 Valant13 force-pushed the REST-API-multiselect-attribute-BC-break-between-2.1.8-and-2.3.0 branch from 984c09d to a8bcd7d Compare May 10, 2019 13:51
@Valant13
Copy link
Contributor Author

@orlangur, I have squashed all changes to the single commit

@ghost ghost removed the Progress: needs update label May 11, 2019
@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-4920 has been created to process this Pull Request

@soleksii
Copy link

✔️ QA Passed

Before:

before

After:

after

@Nazar65 Nazar65 force-pushed the REST-API-multiselect-attribute-BC-break-between-2.1.8-and-2.3.0 branch from b3f0fc5 to b44e33d Compare May 13, 2019 09:43
@Nazar65 Nazar65 force-pushed the REST-API-multiselect-attribute-BC-break-between-2.1.8-and-2.3.0 branch from b44e33d to 5162d50 Compare May 13, 2019 11:08
@Nazar65
Copy link
Member

Nazar65 commented May 14, 2019

Hi @Valant13 thank you for collaboration, yours changes doesn't work for SOAP client, and test testUpdateMultiselectAttributesWithArrayValue() failed with following result

SoapFault : Notice: Array to string conversion in /home/nazar/sites/magento/publicPr/22/app/code/Magento/Eav/Model/Entity/Attribute/Backend/ArrayBackend.php on line 47
 /home/nazar/sites/magento/publicPr/22/vendor/zendframework/zend-soap/src/Client.php:1166
 /home/nazar/sites/magento/publicPr/22/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/Webapi/Adapter/Soap.php:55
 /home/nazar/sites/magento/publicPr/22/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/WebapiAbstract.php:176
 /home/nazar/sites/magento/publicPr/22/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php:1236
 /home/nazar/sites/magento/publicPr/22/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php:1620

@VladimirZaets
Copy link
Contributor

@Valant13, I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for collaboration

@m2-assistant
Copy link

m2-assistant bot commented May 28, 2019

Hi @Valant13, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Eav Partner: ISM eCompany Pull Request is created by partner ISM eCompany partners-contribution Pull Request is created by Magento Partner Progress: needs update Release Line: 2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants