Skip to content

Commit

Permalink
new phpunit test_cartstore_two_costcenters_not_enough_credits() (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
semteacher committed Dec 11, 2024
1 parent bdf9c97 commit 9e94d65
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/shopping_cart_credits_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use advanced_testcase;
use local_shopping_cart_generator;
use local_shopping_cart\local\cartstore;

/**
* Test for shopping_cart_credits
Expand Down Expand Up @@ -249,6 +250,56 @@ public function test_shopping_cart_credits_refund(): void {
$this->assertEmpty($balance2);
}

/**
* Test test_cartstore_get_costcenter
*
* User selects two items with costcenters and no no enough credits in both nocostcenter
* and dedicated costcenters and no default costcenter than proceed to checkout
*
* @covers \cartstore
*/
public function test_cartstore_two_costcenters_not_enough_credits(): void {

parent::setUp();
$this->resetAfterTest(true);

$user1 = $this->getDataGenerator()->create_user();

$cartstore = cartstore::instance((int)$user1->id);

shopping_cart::add_item_to_cart(
'local_shopping_cart',
'option',
7,
$user1->id
);

shopping_cart::add_item_to_cart(
'local_shopping_cart',
'option',
8,
$user1->id
);

// Set credits for all costcenters.
shopping_cart_credits::add_credit($user1->id, 15, 'EUR');
shopping_cart_credits::add_credit($user1->id, 13, 'EUR', 'CostCenter1');
shopping_cart_credits::add_credit($user1->id, 14, 'EUR', 'CostCenter2');

$data = $cartstore->get_data();

// Check total price, costcenter and credits.
// CostCenter2 + noname costcenter has to be used.
$this->assertEmpty($data['remainingcredit']);
$this->assertEquals(5.1, $data['price']);
$this->assertEquals(29, $data['deductible']);
$this->assertEquals(34.1, $data['initialtotal']);
$this->assertEquals(29, $data['credit']);
$this->assertEquals('CostCenter2', $data['costcenter']);
$this->assertArrayHasKey('items', $data);
$this->assertEquals(2, count($data['items']));
}

/**
* Data provider for test_shopping_cart_credits_get_data
*
Expand Down

0 comments on commit 9e94d65

Please sign in to comment.