Skip to content

Commit

Permalink
OXDEV-1050 Fix order tests
Browse files Browse the repository at this point in the history
  • Loading branch information
godefroy-le-hardi committed Jun 15, 2018
1 parent 4f2c41b commit 6d11ab2
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 122 deletions.
23 changes: 12 additions & 11 deletions tests/Unit/Application/Controller/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace OxidEsales\EshopCommunity\Tests\Unit\Application\Controller;

use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Application\Model\BasketItem;
use OxidEsales\EshopCommunity\Application\Model\Payment;
use oxOutOfStockException;
use \oxUtils;
Expand Down Expand Up @@ -542,24 +544,23 @@ public function testExecuteWithWrongStockCallsMethodsInRightOrder()
$this->setupConfigForOrderExecute();
$this->getPriceForOrderExecute();

$product = $this->getMock(\OxidEsales\Eshop\Application\Model\Article::class, array("checkForStock"));
$product->expects($this->once())->method("checkForStock")->with($this->equalTo(999))->will($this->returnValue($product));
$product = $this->getMock(Article::class, ['checkForStock']);
$product
->method("checkForStock")
->with($this->equalTo(999))
->will($this->returnValue($product));

$basketItem = $this->getMock(\OxidEsales\Eshop\Application\Model\BasketItem::class, array("getArticle", "getAmount"));
$basketItem->expects($this->once())->method("getArticle")->will($this->returnValue($product));
$basketItem->expects($this->once())->method("getAmount")->will($this->returnValue(999));
$basketItem = $this->getMock(BasketItem::class, ['getArticle', 'getAmount']);
$basketItem->method('getArticle')->will($this->returnValue($product));
$basketItem->method('getAmount')->will($this->returnValue(999));

//setting basket info
$basket = $this->getBasketMock($basketItem);
$basket->expects($this->never())->method("getPaymentId");
$basket->expects($this->never())->method("getShippingId");

$session = $this->getSessionMock($basket);
$session->expects($this->once())->method("checkSessionChallenge")->will($this->returnValue(true));
$session->method('checkSessionChallenge')->will($this->returnValue(true));

$order = $this->getOrderMock($session);
//on order success must return next step value
$order->expects($this->never())->method('_getNextStep')->will($this->returnValue('nextStepValue'));
$order->expects($this->never())->method('_getNextStep');

$this->setExpectedException('oxOutOfStockException');
$this->assertNull($order->execute());
Expand Down
236 changes: 125 additions & 111 deletions tests/Unit/Application/Model/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OxidEsales\Eshop\Application\Model\Order;
use OxidEsales\Eshop\Application\Model\Payment;
use OxidEsales\Eshop\Application\Model\UserPayment;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\UtilsObject;
use oxOrder;
use \stdClass;
Expand Down Expand Up @@ -1635,16 +1636,18 @@ public function testGetOrderNetSum()

public function testFinalizeOrderReturnsErrorCodeWhenOrderAlreadyExist()
{
$oOrder = $this->getMock(\OxidEsales\Eshop\Application\Model\Order::class, array('_checkOrderExist'));
$oOrder->expects($this->any())
$order = $this->getMock(Order::class, array('_checkOrderExist'));
$order->expects($this->any())
->method('_checkOrderExist')
->will($this->returnValue('EXISTINGORDERID'));

$oBasket = oxNew('oxBasket');

$iRet = $oOrder->finalizeOrder($oBasket, null);
$basket = oxNew(Basket::class);
$user = oxNew(User::class);

$this->assertEquals(3, $iRet);
$this->assertEquals(
3,
$order->finalizeOrder($basket, $user)
);
}

/**
Expand All @@ -1655,39 +1658,41 @@ public function testFinalizeOrderReturnsErrorCodeWhenOrderAlreadyExist()
*/
public function testFinalizeOrderCallsAllRequiredMethods()
{
$oBasket = oxNew('oxBasket');

$aMethods = array('setId',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_executePayment',
'_updateWishlist',
'_updateNoticeList',
'_markVouchers',
'_sendOrderByEmail',
'_updateOrderDate'
);

$aTestMethods = array_unique($aMethods);
$aTestMethods[] = '_setUser';
$aTestMethods[] = 'validateOrder';
$aTestMethods[] = '_setOrderStatus';
$oOrder = $this->getMock(\OxidEsales\Eshop\Application\Model\Order::class, $aTestMethods);

foreach ($aMethods AS $iKey => $sMethod) {
$oOrder->expects($this->once())
->method($sMethod)
$basket = oxNew(Basket::class);
$user = oxNew(User::class);

$methods = [
'setId',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_executePayment',
'_updateWishlist',
'_updateNoticeList',
'_markVouchers',
'_sendOrderByEmail',
'_updateOrderDate',
];

$testMethods = array_unique($methods);
$testMethods[] = '_setUser';
$testMethods[] = 'validateOrder';
$testMethods[] = '_setOrderStatus';
$order = $this->getMock(Order::class, $testMethods);

foreach ($methods AS $key => $method) {
$order->expects($this->once())
->method($method)
->will($this->returnValue(true));
}

$oOrder->expects($this->atLeastOnce())->method('_setUser');
$oOrder->expects($this->atLeastOnce())->method('_setOrderStatus');
$oOrder->expects($this->once())->method('validateOrder');
$oOrder->expects($this->once())->method('_updateOrderDate');
$order->expects($this->atLeastOnce())->method('_setUser');
$order->expects($this->atLeastOnce())->method('_setOrderStatus');
$order->expects($this->once())->method('validateOrder');
$order->expects($this->once())->method('_updateOrderDate');

$oOrder->finalizeOrder($oBasket, null);
$order->finalizeOrder($basket, $user);
}

/**
Expand All @@ -1698,104 +1703,113 @@ public function testFinalizeOrderCallsAllRequiredMethods()
*/
public function testFinalizeOrderFromRecalculateOrder()
{
$oBasket = oxNew('oxBasket');

$aMethods = array('_setUser',
'_loadFromBasket',
'_setPayment',
'_setOrderStatus',
'save',
'_setOrderStatus',
'_updateWishlist',
'_updateNoticeList',
);
$aTestMethods = array_unique($aMethods);
$aTestMethods[] = '_updateOrderDate';
$oOrder = $this->getMock(\OxidEsales\Eshop\Application\Model\Order::class, $aTestMethods);


foreach ($aMethods AS $iKey => $sMethod) {
$oOrder->expects($this->at($iKey))
->method($sMethod)
$basket = oxNew(Basket::class);
$user = oxNew(User::class);

$methods = [
'_setUser',
'_loadFromBasket',
'_setPayment',
'_setOrderStatus',
'save',
'_updateWishlist',
'_updateNoticeList',
];
$testMethods = array_unique($methods);
$testMethods[] = '_updateOrderDate';
$order = $this->getMock(Order::class, $testMethods);


foreach ($methods AS $key => $method) {
$order
->method($method)
->will($this->returnValue(true));
}

$oOrder->expects($this->never())->method('_updateOrderDate');
$order->expects($this->never())->method('_updateOrderDate');

$oOrder->finalizeOrder($oBasket, null, true);
$order->finalizeOrder($basket, $user, true);
}

/**
* Testing if finalizeOrder() on success returns sending order mail to user status
*/
public function testFinalizeOrderReturnsMailingStatusOnSuccess()
{
$oBasket = oxNew('oxBasket');
$basket = oxNew(Basket::class);
$user = oxNew(User::class);

$methods = [
'setId',
'_setUser',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_setOrderStatus',
'_executePayment',
'_setOrderStatus',
'_updateWishlist',
'_updateNoticeList',
'_markVouchers',
'_sendOrderByEmail',
'validateOrder',
];

$order = $this->getMock(Order::class, array_unique($methods));


$order->expects($this->once())->method('setId')->will($this->returnValue(true));
$order->expects($this->once())->method('_setUser')->will($this->returnValue(true));
$order->expects($this->once())->method('_loadFromBasket')->will($this->returnValue(true));
$order->expects($this->once())->method('_setPayment')->will($this->returnValue(true));
$order->expects($this->once())->method('save')->will($this->returnValue(true));
$order->expects($this->once())->method('_executePayment')->will($this->returnValue(true));
$order->expects($this->atLeastOnce())->method('_setOrderStatus')->will($this->returnValue(true));
$order->expects($this->once())->method('_updateWishlist')->will($this->returnValue(true));
$order->expects($this->once())->method('_markVouchers')->will($this->returnValue(true));
$order->expects($this->once())->method('_sendOrderByEmail')->will($this->returnValue(1));
$order->expects($this->once())->method('validateOrder');

$aMethods = array('setId',
'_setUser',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_setOrderStatus',
'_executePayment',
'_setOrderStatus',
'_updateWishlist',
'_updateNoticeList',
'_markVouchers',
'_sendOrderByEmail',
'validateOrder'
$this->assertEquals(
1,
$order->finalizeOrder($basket, $user)
);

$oOrder = $this->getMock(\OxidEsales\Eshop\Application\Model\Order::class, array_unique($aMethods));


$oOrder->expects($this->once())->method('setId')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_setUser')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_loadFromBasket')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_setPayment')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('save')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_executePayment')->will($this->returnValue(true));
$oOrder->expects($this->atLeastOnce())->method('_setOrderStatus')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_updateWishlist')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_markVouchers')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_sendOrderByEmail')->will($this->returnValue(1));
$oOrder->expects($this->once())->method('validateOrder');

$iRet = $oOrder->finalizeOrder($oBasket, null);
$this->assertEquals(1, $iRet);
}

/**
* Testing if finalize order returns error code if order payment failed
*/
public function testFinalizeOrderReturnsErrorCodeOnPaymentFailure()
{
$oBasket = oxNew('oxBasket');
$basket = oxNew(Basket::class);
$user = oxNew(User::class);

$methods = [
'setId',
'_setUser',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_executePayment',
'validateOrder',
];

$order = $this->getMock(Order::class, $methods);

$order->expects($this->once())->method('setId')->will($this->returnValue(true));
$order->expects($this->once())->method('_setUser')->will($this->returnValue(true));
$order->expects($this->once())->method('_loadFromBasket')->will($this->returnValue(true));
$order->expects($this->once())->method('_setPayment')->will($this->returnValue(true));
$order->expects($this->once())->method('save')->will($this->returnValue(true));
$order->expects($this->once())->method('_executePayment')->will($this->returnValue(2));
$order->expects($this->once())->method('validateOrder');

$aMethods = array('setId',
'_setUser',
'_loadFromBasket',
'_setPayment',
'_setFolder',
'save',
'_executePayment',
'validateOrder'
$this->assertEquals(
2,
$order->finalizeOrder($basket, $user)
);

$oOrder = $this->getMock(\OxidEsales\Eshop\Application\Model\Order::class, $aMethods);

$oOrder->expects($this->once())->method('setId')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_setUser')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_loadFromBasket')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_setPayment')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('save')->will($this->returnValue(true));
$oOrder->expects($this->once())->method('_executePayment')->will($this->returnValue(2));
$oOrder->expects($this->once())->method('validateOrder');

$iRet = $oOrder->finalizeOrder($oBasket, null);
$this->assertEquals(2, $iRet);
}


Expand Down

0 comments on commit 6d11ab2

Please sign in to comment.