Skip to content

Commit

Permalink
Merge pull request #1707 from spryker/bugfix/cc-9476-order-placement-…
Browse files Browse the repository at this point in the history
…check

CC-9476 Order can be placed without any check after unsuccessful attempt of order placement
  • Loading branch information
Spryker Release Bot authored Aug 18, 2020
2 parents 8e58820 + e1c66f4 commit 021ecfc
Show file tree
Hide file tree
Showing 6 changed files with 259 additions and 7 deletions.
20 changes: 20 additions & 0 deletions codeception.yml
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'
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"spryker-shop/product-packaging-unit-widget": "*",
"spryker/code-sniffer": "*",
"spryker/router": "*",
"spryker/silex": "*"
"spryker/silex": "*",
"spryker/testify": "*"
},
"suggest": {
"spryker-shop/cart-code-widget": "If you want to use components from module CartCodeWidget or CheckoutVoucherFormWidget or CheckoutVoucherFormWidgetPlugin",
Expand All @@ -60,11 +61,16 @@
"SprykerShop\\": "src/SprykerShop/"
}
},
"autoload-dev": {
"psr-4": {
"SprykerShopTest\\": "tests/SprykerShopTest/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/",
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/"
"cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/",
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/ tests/"
},
"extra": {
"branch-alias": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ public function placeOrderAction(Request $request)
return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUMMARY);
}

if ($quoteTransfer->getOrderReference() !== null) {
return $this->redirectResponseInternal(CheckoutPageControllerProvider::CHECKOUT_SUCCESS);
}

return $this->createStepProcess()->process($request);
}

Expand Down
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;
}
}
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;
}
}
20 changes: 20 additions & 0 deletions tests/SprykerShopTest/Yves/CheckoutPage/codeception.yml
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

0 comments on commit 021ecfc

Please sign in to comment.