-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Allow wishlist share when all items are out of stock #26185
Allow wishlist share when all items are out of stock #26185
Conversation
Clicking `Share` on the wishlist view page updates and saves the wishlist before redirecting to the share page. The redirection to the share page only happens when the post body includes wishlist descriptions. Because qty and comment are disabled for out of stock wishlist items these properties are not sent with the post resulting in the share redirect being unreachable when all items are out of stock. This commit updates the controller flow separating the logic conditions for saving and sharing. This allows sharing wishlist where all items are out of stock.
Hi @pmclain. 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.
Please cover the change with automated tests.
@lbajsarowicz This class is currently lacking unit/integration test coverage entirely. I have no desire to create a set of test cases from scratch. This PR is only open because it was faster to fix the issue myself then spending 1-2 weeks arguing with Magento support for a patch. |
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.
I feel your pain. I'll develop MFTF test for that change.
Hi @lbajsarowicz, thank you for the review.
|
✔️ QA passed |
/** | ||
* Test for update method Wishlist controller. | ||
* | ||
* Check if there is not post value result redirect returned. |
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.
The controller will return an redirect regardless of the post value unless the requested wishlist does not exist, in which case a \Magento\Framework\Exception\NotFoundException
is thrown. What if this test is updated for validating the logic within the controller? This may also be a better use case for an integration test over a unit test.
@engcom-Golf Feel free to close. I'll open a support ticket for the impacted clients. |
As we discussed on "slack", i will cover more cases with test |
befc091
to
3c3018d
Compare
@engcom-Golf thanks! looks good to me. |
Hi @lbajsarowicz could you please review new changes ? |
@magento run all tests |
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 need to:
- extract magic numbers to
const
with correct names - replace class attributes names to be explicit when it's mock (
$someClassMock
) and doc blocks to addMockObject|
testUpdate
is completely unreadable. Try to make it clear what it actually does. It's recommended to use 3 sections:
- given
- when
- then
For example
// Given
$this->requestMock->method('getPostValue)->willReturn($postData);
...
$itemMock...
// When
$itemMock->method('load')->with(self::STUB_ITEM_ID)->willReturnSelf();
// Then
$this->messageManagerMock->expects($this->once())->method('addSuccessMessage');
$controllerActionResult = $this->updateController->execute();
$this->assertEquals($this->resultRedirectMock, $controllerActionResult);
Then it's clear what is actually mocked (given), what are our assumptions for the test case (when) and what are expectations (then).
/** | ||
* @var Validator $formKeyValidator | ||
*/ | ||
private $formKeyValidator; |
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.
formKeyValidatorMock
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.
ok
class UpdateTest extends TestCase | ||
{ | ||
/** | ||
* @var Validator $formKeyValidator |
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.
MockObject|Validator
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.
ok
private $formKeyValidator; | ||
|
||
/** | ||
* @var WishlistProviderInterface $wishlistProvider |
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.
MockObject|WishlistProviderInterface
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.
ok
->method('getMessageManager') | ||
->willReturn($this->messageManager); | ||
|
||
$this->updateController = new Update( |
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.
Use ObjectManager helper for building the tested object.
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.
ok
[ | ||
[ | ||
'wishlist_data' => [ | ||
'id' => 1, |
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.
Replace magic numbers with const - for example STUB_PRODUCT_ID
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.
ok
* @dataProvider getWishlistDataProvider | ||
* @return void | ||
*/ | ||
public function testUpdate(array $wishlistDataProvider): void |
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 using wishlistDataProvider['wishlist_data']
and wishlistDataProvider['post_data']
just extract them as function parameters: testUpdateForPostRequest(array $wishlistDataProvider, array $postData)
and introduce verification if no POST data provided: testUpdateRedirectWhenNoPostData()
.
private $wishlistProvider; | ||
|
||
/** | ||
* @var LocaleQuantityProcessor $quantityProcessor |
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.
MockObject|LocaleQuantityProcessor
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.
ok
/** | ||
* @var LocaleQuantityProcessor $quantityProcessor | ||
*/ | ||
private $quantityProcessor; |
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.
quantityProcessorMock
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.
ok
/** | ||
* @var RequestInterface $requestMock | ||
*/ | ||
private $requestMock; |
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.
👍
private $resultFactory; | ||
|
||
/** | ||
* @var RequestInterface $requestMock |
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.
MockObject|RequestInterface
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.
ok
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.
Small changes and we're ready to go!
$this->formKeyValidator, | ||
$this->wishlistProvider, | ||
$this->quantityProcessor | ||
$this->updateController = (new ObjectManagerHelper($this))->getObject( |
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.
Extract this to separate variable:
$objectManager = new ObjectManagerHelper($this);
* Wishlist item id | ||
* | ||
* @var int | ||
*/ |
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.
We don't use Docblocks for consts
* | ||
* @var int | ||
*/ | ||
private const ITEM_ID = 1; |
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.
Prefix with STUB_
as it means that is just "stupid replacement" for actual value, that does not matter for tests.
/** | ||
* Product qty for wishlist | ||
* | ||
* @var int |
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.
We don't use docblocks for const
*/ | ||
private $formKeyValidator; | ||
private const WISHLIST_PRODUCT_QTY = 21; |
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.
Prefix with STUB_
Hi @lbajsarowicz, thank you for the review. |
Hi @pmclain, thank you for your contribution! |
Description (*)
Clicking
Share
on the wishlist view page updates and saves the wishlistbefore redirecting to the share page. The redirection to the share page only
happens when the post body includes wishlist descriptions. Because qty and
comment are disabled for out of stock wishlist items these properties are not
sent with the post resulting in the share redirect being unreachable when all
items are out of stock.
This commit updates the controller flow separating the logic conditions for
saving and sharing. This allows sharing wishlist where all items are out of
stock.
Manual testing scenarios (*)
Expected Result With PR
You should be redirected to the share page for inputting email addresses and messages.
Current Behavior
You are redirected back to the wishlist view without any messaging.
Contribution checklist (*)