mirror of
https://github.com/wearepixel/laravel-cart.git
synced 2026-11-14 13:51:44 +00:00
79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
use Wearepixel\Cart\Cart;
|
|
use Wearepixel\Cart\Drivers\SessionDriver;
|
|
use Wearepixel\Cart\Tests\Helpers\SessionMock;
|
|
|
|
beforeEach(function () {
|
|
$events = Mockery::mock('Illuminate\Contracts\Events\Dispatcher');
|
|
$events->shouldReceive('dispatch');
|
|
|
|
$this->cart1 = new Cart(
|
|
new SessionDriver(new SessionMock, 'uniquesessionkey123'),
|
|
$events,
|
|
'shopping',
|
|
require (__DIR__ . '/../Helpers/ConfigMock.php')
|
|
);
|
|
|
|
$this->cart2 = new Cart(
|
|
new SessionDriver(new SessionMock, 'uniquesessionkey456'),
|
|
$events,
|
|
'wishlist',
|
|
require (__DIR__ . '/../Helpers/ConfigMock.php')
|
|
);
|
|
});
|
|
|
|
afterEach(function () {
|
|
Mockery::close();
|
|
});
|
|
|
|
test('cart multiple instances', function () {
|
|
// add 3 items on cart 1
|
|
$itemsForCart1 = [
|
|
[
|
|
'id' => 456,
|
|
'name' => 'Sample Item 1',
|
|
'price' => 67.99,
|
|
'quantity' => 4,
|
|
'attributes' => [],
|
|
],
|
|
[
|
|
'id' => 568,
|
|
'name' => 'Sample Item 2',
|
|
'price' => 69.25,
|
|
'quantity' => 4,
|
|
'attributes' => [],
|
|
],
|
|
[
|
|
'id' => 856,
|
|
'name' => 'Sample Item 3',
|
|
'price' => 50.25,
|
|
'quantity' => 4,
|
|
'attributes' => [],
|
|
],
|
|
];
|
|
|
|
$this->cart1->add($itemsForCart1);
|
|
|
|
expect($this->cart1->isEmpty())->toBeFalse('Cart should not be empty');
|
|
expect($this->cart1->getContent()->toArray())->toHaveCount(3, 'Cart should have 3 items');
|
|
expect($this->cart1->getInstanceName())->toEqual('shopping', 'Cart 1 should have instance name of "shopping"');
|
|
|
|
// add 1 item on cart 2
|
|
$itemsForCart2 = [
|
|
[
|
|
'id' => 456,
|
|
'name' => 'Sample Item 1',
|
|
'price' => 67.99,
|
|
'quantity' => 4,
|
|
'attributes' => [],
|
|
],
|
|
];
|
|
|
|
$this->cart2->add($itemsForCart2);
|
|
|
|
expect($this->cart2->isEmpty())->toBeFalse('Cart should not be empty');
|
|
expect($this->cart2->getContent()->toArray())->toHaveCount(1, 'Cart should have 3 items');
|
|
expect($this->cart2->getInstanceName())->toEqual('wishlist', 'Cart 2 should have instance name of "wishlist"');
|
|
});
|