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

Defaulting missing alt-text for a product to use the product name. #11323

Merged
merged 9 commits into from
Dec 1, 2017

Conversation

brobie
Copy link
Contributor

@brobie brobie commented Oct 10, 2017

Description

The code in app/code/Magento/Catalog/Block/Product/View/Gallery.php's getGalleryImagesJson() function was setting the image's label to $image->getLabel() regardless of whether the image's label was null or empty. The fix was to test the $image->getLabel() response and if it was empty to use the product's name instead.

Fixed Issues (if relevant)

  1. Empty image alt-text & missing alt attribute on product detail page #9931: Empty image alt-text & missing alt attribute on product detail page

Manual testing scenarios

  1. Manually create a product with images.
  2. Intentionally leave the Image Label blank.
  3. Navigate to that product's PDP and you should see the alt attribute for the image be populated with the product's name.
  4. You should also test images that have Image Labels and ensure that those labels show in the alt attribute

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 Oct 10, 2017

CLA assistant check
All committers have signed the CLA.

@dmanners
Copy link
Contributor

Thanks for this PR @brobie I will review and process this now for you. If I need any further information I will let you know.

@dmanners
Copy link
Contributor

Hi @brobie the fix looks good to me so far but it would be great if you could cover it with a test. Ideally an integration test but a unit test would also be of some benefit here as the method getGalleryImagesJson currently has no coverage. Let me know if you need any assistance with this. Thanks.

@brobie
Copy link
Contributor Author

brobie commented Oct 10, 2017

@dmanners The unit tests have been added. I'm not sure how to kick them off as a part of this new addition to the pull request.

@dmanners
Copy link
Contributor

@brobie thanks, they will be picked up by travis automatically.

@@ -77,6 +77,83 @@ protected function mockContext()
->willReturn($this->registry);
}

public function testGetGalleryImagesJsonWithLabel(){
Copy link
Contributor

Choose a reason for hiding this comment

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

The static tests will complain that the { needs to be on a new line. You should be able to run the static tests over your changes and see all the issues otherwise you can wait until Travis has finished. Though I think there will be nothing more than:

FILE: ...ode/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
  80 | ERROR | [x] Opening brace should be on a new line
  94 | ERROR | [x] Opening brace should be on a new line
 100 | ERROR | [x] Function closing brace must go on the next line
     |       |     following the body; found 1 blank lines before
     |       |     brace
 102 | ERROR | [x] Opening brace should be on a new line
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmanners - I have fixed the above issues, but am curious if you can point me to the correct configuration for running the static code analysis. When I run the below command, I get more issues than what you have said.

vendor/squizlabs/php_codesniffer/bin/phpcs app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php

Copy link
Contributor

Choose a reason for hiding this comment

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

So those results came from the build system. Not 100% sure how it was run but there are a couple of things I have done locally before.

./vendor/bin/phpcs app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php dev/tests/static/framework/Magento - This will run the framework/Magento standards when running phpcs.
You could also try bin/magento dev:tests:run static but that runs them all.
Finally there is a way of running them only on a diff (though I have as yet got that running....) From what I understand you run git diff origin/2.2-develop HEAD --name-only > dev/tests/static/testsuite/Magento/Test/_files/changed_files_local.txt and this will create a list of changed files from your branch compared to another branch (in this case origin/2.2-develop). Then after that when running the suite it should only run on those files you changes. Maybe @okorshenko knows the full command for the static tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is one other option which is to setup Travis against your fork. This would then mean you could run the travis checks before providing a PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@brobie ok so if you run the git diff as described above followed by ./vendor/bin/phpunit --config dev/tests/static/phpunit.xml.dist that should show you the details you are looking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome, I'll give it a try!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the request that mimics the rules used by Magento for Code Sniffer (I think)
vendor/squizlabs/php_codesniffer/bin/phpcs --standard=dev/tests/static/framework/Magento/ruleset.xml app/code/Magento/Catalog/Test/Unit/Block/Product/View/GalleryTest.php

Copy link
Contributor

@dmanners dmanners 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 this PR. It looks good. I will start to process this now.

@dmanners
Copy link
Contributor

dmanners commented Nov 4, 2017

@brobie so we have the following issue during internal testing.

1. Create a simple product that will have an image with an alt text.
2. Export this product to a CSV file.
3. Delete the product from Website
4. Import the previously exported product (CSV) back to the website
5. Open the imported product page (on a backend)

Expected result:
The product still has the alt text, that we created in the first step

Actual result:
The alt text that we had is gone from the product (it was lost)

Would you be up for having a look at fixing this also here. This is part of #9931 which has been linked to this PR.

Thanks

@brobie
Copy link
Contributor Author

brobie commented Nov 5, 2017 via email

@magento-engcom-team magento-engcom-team added 2.2.x Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release labels Nov 7, 2017
@magento-engcom-team magento-engcom-team added Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on develop Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release labels Nov 7, 2017
@dmanners
Copy link
Contributor

Hi @brobie have you had any chance to look into this issue?

@magento-engcom-team magento-engcom-team added the Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release label Nov 22, 2017
@dmanners
Copy link
Contributor

@brobie I think I found the issue with the labels being saved. Will check the fix provided and let you know.

@okorshenko okorshenko merged commit ae5454a into magento:2.2-develop Dec 1, 2017
okorshenko pushed a commit that referenced this pull request Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Award: test coverage Component: Catalog Progress: accept Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants