-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SUPESC-514 Fixed default quote change is showing a message to a non-q…
…uote owner (#9419) SUPESC-514 Fixed default quote change is showing a message to a non-quote owner
- Loading branch information
1 parent
2d2e930
commit e744755
Showing
7 changed files
with
191 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"include": { | ||
"spryker/transfer": "Provides transfer objects definition with `::get*OrFail()` functionality." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
.../SprykerTest/Zed/MultiCart/Business/MultiCartFacade/AddDefaultQuoteChangedMessageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerTest\Zed\MultiCart\Business\MultiCartFacade; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\DataBuilder\CustomerBuilder; | ||
use Generated\Shared\Transfer\CustomerTransfer; | ||
use Generated\Shared\Transfer\QuoteTransfer; | ||
use Spryker\Zed\MultiCart\Dependency\Facade\MultiCartToMessengerFacadeInterface; | ||
use Spryker\Zed\MultiCart\MultiCartDependencyProvider; | ||
|
||
/** | ||
* Auto-generated group annotations | ||
* | ||
* @group SprykerTest | ||
* @group Zed | ||
* @group MultiCart | ||
* @group Business | ||
* @group MultiCartFacade | ||
* @group AddDefaultQuoteChangedMessageTest | ||
* Add your own group annotations below this line | ||
*/ | ||
class AddDefaultQuoteChangedMessageTest extends Unit | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const CUSTOMER_REFERENCE_1 = 'customer-reference-1'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const CUSTOMER_REFERENCE_2 = 'customer-reference-2'; | ||
|
||
/** | ||
* @var \SprykerTest\Zed\MultiCart\MultiCartBusinessTester | ||
*/ | ||
protected $tester; | ||
|
||
/** | ||
* @dataProvider quoteOwnerCasesDataProvider | ||
* | ||
* @param bool $isDefaultQuote | ||
* @param bool $isMessageExpected | ||
* | ||
* @return void | ||
*/ | ||
public function testMessagesForQuoteOwner(bool $isDefaultQuote, bool $isMessageExpected): void | ||
{ | ||
// Arrange | ||
$multiCartToMessengerFacadeMock = $this->setupMultiCartToMessengerFacadeMock(); | ||
$quoteTransfer = $this->setupQuote( | ||
static::CUSTOMER_REFERENCE_1, | ||
$isDefaultQuote, | ||
static::CUSTOMER_REFERENCE_1, | ||
); | ||
|
||
// Assert | ||
$multiCartToMessengerFacadeMock | ||
->expects($isMessageExpected ? $this->once() : $this->never()) | ||
->method('addInfoMessage'); | ||
|
||
// Act | ||
$this->tester->getFacade()->addDefaultQuoteChangedMessage($quoteTransfer); | ||
} | ||
|
||
/** | ||
* @dataProvider nonQuoteOwnerCasesDataProvider | ||
* | ||
* @param bool $isDefaultQuote | ||
* @param bool $isMessageExpected | ||
* | ||
* @return void | ||
*/ | ||
public function testMessagesForNonQuoteOwner(bool $isDefaultQuote, bool $isMessageExpected): void | ||
{ | ||
// Arrange | ||
$multiCartToMessengerFacadeMock = $this->setupMultiCartToMessengerFacadeMock(); | ||
$quoteTransfer = $this->setupQuote( | ||
static::CUSTOMER_REFERENCE_1, | ||
$isDefaultQuote, | ||
static::CUSTOMER_REFERENCE_2, | ||
); | ||
|
||
// Assert | ||
$multiCartToMessengerFacadeMock | ||
->expects($isMessageExpected ? $this->once() : $this->never()) | ||
->method('addInfoMessage'); | ||
|
||
// Act | ||
$this->tester->getFacade()->addDefaultQuoteChangedMessage($quoteTransfer); | ||
} | ||
|
||
/** | ||
* @return array<array<bool>> | ||
*/ | ||
public function quoteOwnerCasesDataProvider(): array | ||
{ | ||
return [ | ||
'Test that message is added when quote is not default' => [false, true], | ||
'Test that message is not added when quote is default' => [true, false], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array<array<bool>> | ||
*/ | ||
public function nonQuoteOwnerCasesDataProvider(): array | ||
{ | ||
return [ | ||
'Test that message is not added when quote is not default for its owner' => [false, false], | ||
'Test that message is not added when quote is default for its owner' => [true, false], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $quoteOwnerCustomerReference | ||
* @param bool $isDefaultQuote | ||
* @param string $currentUserCustomerReference | ||
* | ||
* @return \Generated\Shared\Transfer\QuoteTransfer | ||
*/ | ||
protected function setupQuote(string $quoteOwnerCustomerReference, bool $isDefaultQuote, string $currentUserCustomerReference): QuoteTransfer | ||
{ | ||
$quoteTransfer = $this->tester->havePersistentQuote([ | ||
QuoteTransfer::CUSTOMER => $this->buildCustomerTransfer($quoteOwnerCustomerReference), | ||
QuoteTransfer::IS_DEFAULT => $isDefaultQuote, | ||
]); | ||
|
||
if ($quoteOwnerCustomerReference !== $currentUserCustomerReference) { | ||
$quoteTransfer->setCustomer($this->buildCustomerTransfer($currentUserCustomerReference)); | ||
} | ||
|
||
return $quoteTransfer; | ||
} | ||
|
||
/** | ||
* @param string $customerReference | ||
* | ||
* @return \Generated\Shared\Transfer\CustomerTransfer | ||
*/ | ||
protected function buildCustomerTransfer(string $customerReference): CustomerTransfer | ||
{ | ||
return (new CustomerBuilder())->build() | ||
->setCustomerReference($customerReference); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\MultiCart\Dependency\Facade\MultiCartToMessengerFacadeInterface | ||
*/ | ||
protected function setupMultiCartToMessengerFacadeMock(): MultiCartToMessengerFacadeInterface | ||
{ | ||
$multiCartToMessengerFacadeMock = $this | ||
->getMockBuilder(MultiCartToMessengerFacadeInterface::class) | ||
->getMock(); | ||
|
||
$this->tester->setDependency(MultiCartDependencyProvider::FACADE_MESSENGER, $multiCartToMessengerFacadeMock); | ||
|
||
return $multiCartToMessengerFacadeMock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters