-
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.
Merge pull request #1707 from spryker/bugfix/cc-9476-order-placement-…
…check CC-9476 Order can be placed without any check after unsuccessful attempt of order placement
- Loading branch information
Showing
6 changed files
with
259 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace: CheckoutPage | ||
include: | ||
- tests/SprykerShopTest/Yves/CheckoutPage/ | ||
actor: Tester | ||
paths: | ||
tests: tests | ||
log: tests/_output | ||
data: tests/_data | ||
support: tests/_support | ||
envs: tests/_envs | ||
settings: | ||
suite_class: \PHPUnit\Framework\TestSuite | ||
colors: true | ||
memory_limit: 1024M | ||
log: true | ||
coverage: | ||
enabled: true | ||
whitelist: | ||
include: | ||
- 'src/*.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
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
125 changes: 125 additions & 0 deletions
125
tests/SprykerShopTest/Yves/CheckoutPage/Controller/CheckoutControllerTest.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,125 @@ | ||
<?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 SprykerShopTest\Yves\CheckoutPage\Controller; | ||
|
||
use Codeception\Test\Unit; | ||
use Generated\Shared\Transfer\QuoteValidationResponseTransfer; | ||
use Spryker\Yves\StepEngine\Process\StepEngine; | ||
use Spryker\Yves\StepEngine\Process\StepEngineInterface; | ||
use SprykerShop\Yves\CheckoutPage\CheckoutPageFactory; | ||
use SprykerShop\Yves\CheckoutPage\Controller\CheckoutController; | ||
use SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToQuoteClientInterface; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
/** | ||
* @group SprykerShop | ||
* @group Yves | ||
* @group CheckoutPage | ||
* @group Controller | ||
* @group CheckoutControllerTest | ||
*/ | ||
class CheckoutControllerTest extends Unit | ||
{ | ||
protected const PLACE_ORDER_URL = '/checkout/place-order'; | ||
protected const PLACE_ORDER_ROUTE = 'checkout-place-order'; | ||
protected const SUCCESS_URL = '/checkout/success'; | ||
|
||
/** | ||
* @var \SprykerShop\Yves\CheckoutPage\Controller\CheckoutController | ||
*/ | ||
protected $controller; | ||
|
||
/** | ||
* @var \SprykerShopTest\Yves\CheckoutPage\CheckoutPageTester | ||
*/ | ||
protected $tester; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->controller = $this->createCheckoutControllerMock(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testPlaceOrderActionExecutesCheckoutPlaceOrderStep(): void | ||
{ | ||
// Arrange | ||
$request = Request::create(static::PLACE_ORDER_URL, Request::METHOD_POST); | ||
$request->request->set('_route', static::PLACE_ORDER_ROUTE); | ||
|
||
// Act | ||
$response = $this->controller->placeOrderAction($request); | ||
|
||
// Assert | ||
$this->assertInstanceOf(RedirectResponse::class, $response); | ||
$this->assertSame($response->getTargetUrl(), static::SUCCESS_URL); | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Controller\CheckoutController | ||
*/ | ||
protected function createCheckoutControllerMock(): CheckoutController | ||
{ | ||
$checkoutControllerMock = $this->getMockBuilder(CheckoutController::class) | ||
->onlyMethods([ | ||
'getFactory', | ||
'redirectResponseInternal', | ||
'canProceedCheckout', | ||
'createStepProcess', | ||
]) | ||
->getMock(); | ||
|
||
$checkoutControllerMock->method('getFactory')->willReturn($this->createCheckoutPageFactoryMock()); | ||
$checkoutControllerMock->method('redirectResponseInternal')->willReturn(new RedirectResponse(static::SUCCESS_URL)); | ||
$checkoutControllerMock->method('canProceedCheckout')->willReturn((new QuoteValidationResponseTransfer())->setIsSuccessful(true)); | ||
$checkoutControllerMock->method('createStepProcess')->willReturn($this->createStepEngineMock()); | ||
|
||
return $checkoutControllerMock; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\CheckoutPageFactory | ||
*/ | ||
protected function createCheckoutPageFactoryMock(): CheckoutPageFactory | ||
{ | ||
$checkoutPageFactoryMock = $this->createMock(CheckoutPageFactory::class); | ||
$checkoutPageFactoryMock->method('getQuoteClient')->willReturn($this->createCheckoutPageToQuoteClientBridgeMock()); | ||
|
||
return $checkoutPageFactoryMock; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\SprykerShop\Yves\CheckoutPage\Dependency\Client\CheckoutPageToQuoteClientInterface | ||
*/ | ||
protected function createCheckoutPageToQuoteClientBridgeMock(): CheckoutPageToQuoteClientInterface | ||
{ | ||
$checkoutPageToQuoteClientBridgeMock = $this->createMock(CheckoutPageToQuoteClientInterface::class); | ||
$checkoutPageToQuoteClientBridgeMock->method('getQuote') | ||
->willReturn($this->tester->createQuoteTransferWithMultiShipment()); | ||
|
||
return $checkoutPageToQuoteClientBridgeMock; | ||
} | ||
|
||
/** | ||
* @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Yves\StepEngine\Process\StepEngineInterface | ||
*/ | ||
protected function createStepEngineMock(): StepEngineInterface | ||
{ | ||
$placeOrderStepMock = $this->createMock(StepEngine::class); | ||
$placeOrderStepMock->expects($this->once())->method('process')->willReturn(new RedirectResponse(static::SUCCESS_URL)); | ||
|
||
return $placeOrderStepMock; | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
tests/SprykerShopTest/Yves/CheckoutPage/_support/CheckoutPageTester.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,85 @@ | ||
<?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 SprykerShopTest\Yves\CheckoutPage; | ||
|
||
use Codeception\Actor; | ||
use Generated\Shared\DataBuilder\ItemBuilder; | ||
use Generated\Shared\DataBuilder\QuoteBuilder; | ||
use Generated\Shared\DataBuilder\ShipmentBuilder; | ||
use Generated\Shared\Transfer\ExpenseTransfer; | ||
use Generated\Shared\Transfer\QuoteTransfer; | ||
use Generated\Shared\Transfer\ShipmentTransfer; | ||
use Spryker\Shared\Price\PriceConfig; | ||
|
||
/** | ||
* Inherited Methods | ||
* | ||
* @method void wantToTest($text) | ||
* @method void wantTo($text) | ||
* @method void execute($callable) | ||
* @method void expectTo($prediction) | ||
* @method void expect($prediction) | ||
* @method void amGoingTo($argumentation) | ||
* @method void am($role) | ||
* @method void lookForwardTo($achieveValue) | ||
* @method void comment($description) | ||
* @method void pause() | ||
* | ||
* @SuppressWarnings(PHPMD) | ||
*/ | ||
class CheckoutPageTester extends Actor | ||
{ | ||
use _generated\CheckoutPageTesterActions; | ||
|
||
/** | ||
* @uses \Spryker\Shared\Shipment\ShipmentConfig::SHIPMENT_EXPENSE_TYPE | ||
*/ | ||
protected const SHIPMENT_EXPENSE_TYPE = 'SHIPMENT_EXPENSE_TYPE'; | ||
|
||
/** | ||
* @return \Generated\Shared\Transfer\QuoteTransfer | ||
*/ | ||
public function createQuoteTransferWithMultiShipment(): QuoteTransfer | ||
{ | ||
$quoteTransfer = (new QuoteBuilder([ | ||
QuoteTransfer::PRICE_MODE => PriceConfig::PRICE_MODE_NET, | ||
QuoteTransfer::ORDER_REFERENCE => 'order-reference', | ||
])) | ||
->withItem( | ||
(new ItemBuilder()) | ||
->withShipment( | ||
(new ShipmentBuilder([ShipmentTransfer::SHIPMENT_SELECTION => 'custom'])) | ||
->withShippingAddress() | ||
->withMethod() | ||
) | ||
) | ||
->withAnotherItem( | ||
(new ItemBuilder()) | ||
->withShipment( | ||
(new ShipmentBuilder([ShipmentTransfer::SHIPMENT_SELECTION => 'custom'])) | ||
->withShippingAddress() | ||
->withMethod() | ||
) | ||
) | ||
->withBillingAddress() | ||
->withCustomer() | ||
->withTotals() | ||
->withCurrency() | ||
->withPayment() | ||
->build(); | ||
|
||
foreach ($quoteTransfer->getItems() as $itemTransfer) { | ||
$quoteTransfer->addExpense( | ||
(new ExpenseTransfer())->setType(static::SHIPMENT_EXPENSE_TYPE) | ||
->setShipment($itemTransfer->getShipment()) | ||
); | ||
} | ||
|
||
return $quoteTransfer; | ||
} | ||
} |
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,20 @@ | ||
namespace: SprykerShopTest\Yves\CheckoutPage | ||
paths: | ||
tests: . | ||
data: ../../../_data | ||
support: _support | ||
log: ../../../_output | ||
coverage: | ||
enabled: true | ||
remote: false | ||
whitelist: | ||
include: | ||
- '../../../../src/*' | ||
suites: | ||
Yves: | ||
path: . | ||
class_name: CheckoutPageTester | ||
modules: | ||
enabled: | ||
- Asserts | ||
- \SprykerTest\Shared\Testify\Helper\Environment |