예제 #1
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Insert items and checkout');
/**
 * @var array $item1
 * @var array $item2
 * @var int   $order
 */
require "_AddItems.php";
$I->amGoingTo('checkout');
$I->sendPATCH('cart');
$I->seeCodeAndJson(200, ['id' => $order, 'total' => floatify($item1['final_price'] + $item2['final_price'])]);
$I->amGoingTo('verify the order was really ~closed~');
$I->sendGET('cart');
$I->assertEquals(sizeof(json_decode($I->grabResponse())->items), 0, 'verify the cart is now empty');
예제 #2
0
<?php

$I = new ApiTester($scenario);
$I->wantTo('Test the cart behaviour with items');
$I->amGoingTo('confirm the cart is empty');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
/**
 * @var array $item1
 * @var array $item2
 * @var int   $item_id
 */
require "_AddItems.php";
$I->amGoingTo('Verify order');
$I->sendGET('cart');
$I->expectTo('see items in order');
$I->seeCodeAndJson(200, ['items' => [$item1, $item2]]);
$I->expectTo('see correct total');
$I->seeResponseContainsJson(['total' => floatify($item1['final_price'] + $item2['final_price'])]);
$I->amGoingTo('delete an item');
$I->sendDELETE('cart/item/' . $item_id);
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [$item2], 'total' => floatify($item2['final_price'])]);
$I->amGoingTo('clear the cart');
$I->sendDELETE('cart');
$I->seeResponseCodeIs(204);
$I->seeResponseEquals('');
$I->sendGET('cart');
$I->seeCodeAndJson(200, ['items' => [], 'total' => floatify(0)]);
예제 #3
0
 * @var int      $order
 * @var callable $gen_item
 */
require "_AddItems.php";
$calculate_discount = function ($discount, ...$items) {
    $mult = 1 - $discount;
    return array_reduce($items, function ($total, $item) use($mult) {
        return floatify($total + floatify($item['final_price'] * $mult));
    }, 0);
};
$I->amGoingTo('use an invalid coupon code');
$I->sendPOST('cart/coupon', ['code' => 'XXX']);
$I->seeResponseCodeIs(HTTP_NOT_FOUND);
$set_coupon = function ($coupon) use($I, $item1, $item2, $calculate_discount) {
    $I->sendPOST('cart/coupon', ['code' => $coupon['code']]);
    $I->seeCodeAndJson(HTTP_OK, $coupon);
    $I->sendGET('cart');
    $I->seeResponseContainsJson(['total' => $calculate_discount($coupon['discount'], $item1, $item2)]);
};
$I->amGoingTo('use a valid coupon code');
$set_coupon($coupons[0]);
$I->amGoingTo('change the coupon');
$set_coupon($coupons[1]);
$I->amGoingTo('add a new item to see the price discount');
$item3 = $gen_item();
$I->sendPUT('cart', $item3);
$item3['final_price'] = $item3['price'] * $item3['qty'];
$I->sendGET('cart');
$I->seeResponseContainsJson(['total' => $calculate_discount($coupons[1]['discount'], $item1, $item2, $item3)]);
$I->amGoingTo('remove the wrong coupon');
$I->sendDELETE('cart/coupon?code=' . $coupons[0]['code']);