Skip to content

Commit

Permalink
improvement of test_booking_bookit_with_pricecategories_and_zero_pric…
Browse files Browse the repository at this point in the history
…e() method to validate different displayemptyprice settings (Wunderbyte-GmbH#654)
  • Loading branch information
semteacher committed Nov 18, 2024
1 parent 25b0872 commit 40b95f3
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions tests/bo_availability/condition_all_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v
}

/**
* Test of booking option with price as well as cancellation by user.
* Test of booking option with zero price as different displayemptyprice settings.
*
* @covers \condition\priceset::is_available
*
Expand All @@ -224,6 +224,8 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v
public function test_booking_bookit_with_pricecategories_and_zero_price(array $bdata): void {
global $DB, $CFG;

$this->setAdminUser();

// Set parems requred for cancellation.
$bdata['cancancelbook'] = 1;
if (class_exists('local_shopping_cart\shopping_cart')) {
Expand All @@ -239,7 +241,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b
'datatype' => 'text', 'shortname' => 'pricecat', 'name' => 'pricecat',
]);
set_config('pricecategoryfield', 'pricecat', 'booking');
set_config('displayemptyprice', 0, 'booking');
set_config('displayemptyprice', 1, 'booking');

// Create users.
$student1 = $this->getDataGenerator()->create_user(['profile_field_pricecat' => 'realprice']);
Expand All @@ -254,8 +256,6 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b

$booking1 = $this->getDataGenerator()->create_module('booking', $bdata);

$this->setAdminUser();

$this->getDataGenerator()->enrol_user($student1->id, $course1->id, 'student');
$this->getDataGenerator()->enrol_user($student2->id, $course1->id, 'student');
$this->getDataGenerator()->enrol_user($student3->id, $course1->id);
Expand Down Expand Up @@ -316,6 +316,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b
} else {
$this->assertEquals(MOD_BOOKING_BO_COND_NOSHOPPINGCART, $id);
}
// Validation that price == category price.
$price = price::get_price('option', $settings->id);
$this->assertEquals($pricecategorydata3->defaultvalue, $price["price"]);

Expand All @@ -325,10 +326,43 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b
list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id);
// The user sees now either the payment button or the noshoppingcart message.
if (class_exists('local_shopping_cart\shopping_cart')) {
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
$this->assertEquals(MOD_BOOKING_BO_COND_PRICEISSET, $id);
} else {
$this->assertEquals(MOD_BOOKING_BO_COND_NOSHOPPINGCART, $id);
}
// Validation of 0 price.
$price = price::get_price('option', $settings->id);
$this->assertEquals(0, $price["price"]);

// Change displayemptyprice setting value.
$this->setAdminUser();
set_config('displayemptyprice', 0, 'booking');

// Try to book option1 by the student1 - still blocked.
$this->setUser($student1);
singleton_service::destroy_user($student1->id);
list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id);
// The user sees now either the payment button or the noshoppingcart message.
if (class_exists('local_shopping_cart\shopping_cart')) {
$this->assertEquals(MOD_BOOKING_BO_COND_PRICEISSET, $id);
} else {
$this->assertEquals(MOD_BOOKING_BO_COND_NOSHOPPINGCART, $id);
}
$price = price::get_price('option', $settings->id);
$this->assertEquals($pricecategorydata3->defaultvalue, $price["price"]);

// Try to book option1 by the student2 - allowed.
$this->setUser($student2);
singleton_service::destroy_user($student2->id);
list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id);
// The user sees now either the payment button or the noshoppingcart message.
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);

// Book student2 and verify it.
$result = booking_bookit::bookit('option', $settings->id, $student2->id);
$result = booking_bookit::bookit('option', $settings->id, $student2->id);
list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id);

// Mandatory clean-up.
singleton_service::get_instance()->userpricecategory = [];
Expand Down

0 comments on commit 40b95f3

Please sign in to comment.