diff --git a/tests/bo_availability/condition_all_test.php b/tests/bo_availability/condition_all_test.php index afd1bfcae..fab016226 100644 --- a/tests/bo_availability/condition_all_test.php +++ b/tests/bo_availability/condition_all_test.php @@ -51,7 +51,6 @@ * */ final class condition_all_test extends advanced_testcase { - /** * Tests set up. */ @@ -118,7 +117,7 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v /** @var mod_booking_generator $plugingenerator */ $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); - $pricecategorydata = (object)[ + $pricecategorydata = (object) [ 'ordernum' => 1, 'name' => 'default', 'identifier' => 'default', @@ -138,13 +137,13 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v // Check option availability if user is not logged yet. require_logout(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDINPRICE, $id); // Book option1 by the student1 himself. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); // 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); @@ -177,13 +176,13 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v $option->user_submit_response($student1, 0, 0, 0, MOD_BOOKING_VERIFIED); // User 1 should be booked now. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // The student1 attempt to camcel purchase by himself. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Render to see if "cancel purchase" present. $buttons = booking_bookit::render_bookit_button($settings, $student1->id); @@ -196,10 +195,10 @@ public function test_booking_bookit_with_price_and_cancellation(array $bdata): v shoppingcart_history_list::add_round_config($item); $this->assertEquals($settings->id, $item->itemid); $this->assertEquals($student1->id, $item->userid); - $this->assertEquals($pricecategorydata->defaultvalue, (int)$item->price); + $this->assertEquals($pricecategorydata->defaultvalue, (int) $item->price); $this->assertEquals(0, $item->quotaconsumed); // Actual cancellation of purcahse and verify. - $res = shopping_cart::cancel_purchase($settings->id, 'option', $student1->id, 'mod_booking', $item->id, 0); + $res = shopping_cart::cancel_purchase($settings->id, 'option', $student1->id, 'mod_booking', $item->id, 0); $this->assertEquals(1, $res['success']); $this->assertEquals($pricecategorydata->defaultvalue, $res['credit']); $this->assertEmpty($res['error']); @@ -238,7 +237,9 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b // Create user profile custom fields. $this->getDataGenerator()->create_custom_profile_field([ - 'datatype' => 'text', 'shortname' => 'pricecat', 'name' => 'pricecat', + 'datatype' => 'text', + 'shortname' => 'pricecat', + 'name' => 'pricecat', ]); set_config('pricecategoryfield', 'pricecat', 'booking'); set_config('displayemptyprice', 1, 'booking'); @@ -266,7 +267,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b /** @var mod_booking_generator $plugingenerator */ $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); - $pricecategorydata1 = (object)[ + $pricecategorydata1 = (object) [ 'ordernum' => 1, 'name' => 'default', 'identifier' => 'default', @@ -274,7 +275,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b 'pricecatsortorder' => 1, ]; $plugingenerator->create_pricecategory($pricecategorydata1); - $pricecategorydata2 = (object)[ + $pricecategorydata2 = (object) [ 'ordernum' => 2, 'name' => 'ZeroPrice', 'identifier' => 'zeroprice', @@ -283,7 +284,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b ]; $plugingenerator->create_pricecategory($pricecategorydata2); - $pricecategorydata3 = (object)[ + $pricecategorydata3 = (object) [ 'ordernum' => 3, 'name' => 'RealPrice', 'identifier' => 'realprice', @@ -309,7 +310,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b // Try to book option1 by the student1 - blocked. $this->setUser($student1); singleton_service::destroy_user($student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -323,7 +324,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b // Try to book option1 by the student2 - blocked but with 0 price. $this->setUser($student2); singleton_service::destroy_user($student2->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id); + [$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_PRICEISSET, $id); @@ -341,7 +342,7 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b // 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); + [$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); @@ -354,21 +355,21 @@ public function test_booking_bookit_with_pricecategories_and_zero_price(array $b // 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); + [$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); + [$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 = []; } - /** + /** * Test of booking option with fallback different displayemptyprice settings. * * @covers \condition\priceset::is_available @@ -399,7 +400,9 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda // Create user profile custom fields. $this->getDataGenerator()->create_custom_profile_field([ - 'datatype' => 'text', 'shortname' => 'pricecat', 'name' => 'pricecat', + 'datatype' => 'text', + 'shortname' => 'pricecat', + 'name' => 'pricecat', ]); set_config('pricecategoryfield', 'pricecat', 'booking'); set_config('displayemptyprice', 1, 'booking'); @@ -427,7 +430,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda /** @var mod_booking_generator $plugingenerator */ $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); - $pricecategorydata1 = (object)[ + $pricecategorydata1 = (object) [ 'ordernum' => 1, 'name' => 'default', 'identifier' => 'default', @@ -435,7 +438,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda 'pricecatsortorder' => 1, ]; $plugingenerator->create_pricecategory($pricecategorydata1); - $pricecategorydata2 = (object)[ + $pricecategorydata2 = (object) [ 'ordernum' => 2, 'name' => 'staff', 'identifier' => 'staff', @@ -460,7 +463,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student1); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -476,7 +479,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student2); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -488,12 +491,11 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $price = price::get_price('option', $settings->id); $this->assertEquals($pricecategorydata2->defaultvalue, $price["price"]); - // Student one should see the the default price. $this->setUser($student3); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -513,7 +515,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student1); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -529,7 +531,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student2); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -546,7 +548,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student3); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -566,7 +568,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student1); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -582,7 +584,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student2); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -599,7 +601,7 @@ public function test_booking_bookit_with_pricecategories_and_fallback(array $bda $this->setUser($student3); singleton_service::destroy_instance(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id); + [$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); @@ -679,37 +681,37 @@ public function test_booking_bookit_simple(array $bdata): void { // Check option availability if user is not logged yet. require_logout(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDIN, $id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDIN, $id); $this->setAdminUser(); // Via this line, we can get the blocking condition. // The true is only hardblocking, which means low blockers used to only show buttons etc. wont be shown. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); // We are allowed to book. $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CONFIRMBOOKIT, $id); // Now we can actually book. $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // When we run it again, we might want to cancel. $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CONFIRMCANCEL, $id); // Now confirm cancel. $result = booking_bookit::bookit('option', $settings->id, $student1->id); // The result is, that we see the bookingbutton again. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); // That was just for fun. Now we make sure the user is booked again. @@ -722,17 +724,17 @@ public function test_booking_bookit_simple(array $bdata): void { // Now, all the available places are booked. We try to book the third user. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // We still try to book, but no chance. $result = booking_bookit::bookit('option', $settings->id, $student3->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // Check for guest user too - should be "fully booked" as well. $this->setGuestUser(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, 1, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, 1, false); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // Now we add waitinglist to option. @@ -744,20 +746,20 @@ public function test_booking_bookit_simple(array $bdata): void { // Check for guest user - should be allowed to booking in general. $this->setGuestUser(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, 1, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, 1, false); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDIN, $id); // Book student3 again. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, false); // Bookitbutton blocks. $result = booking_bookit::bookit('option', $settings->id, $student3->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, false); // Now student3 is on waitinglist. $result = booking_bookit::bookit('option', $settings->id, $student3->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, false); // User really is booked to waitinglist. $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); @@ -769,7 +771,7 @@ public function test_booking_bookit_simple(array $bdata): void { // Now student4 is on notification list. $result = booking_bookit::bookit('option', $settings->id, $student4->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student4->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student4->id, false); // User really is booked to notifylist. $this->assertEquals(MOD_BOOKING_BO_COND_NOTIFYMELIST, $id); @@ -857,24 +859,24 @@ public function test_booking_bookit_cohorts_and_bookingtime(array $bdata): void // Try to book student1 NOT - allowed. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_ENROLLEDINCOHORTS, $id); // Try to book student2 - allowed. $this->setUser($student2); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); $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); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Try to book student3 - NOT allowed. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_ENROLLEDINCOHORTS, $id); // Now we update test availability setting(s). @@ -887,18 +889,18 @@ public function test_booking_bookit_cohorts_and_bookingtime(array $bdata): void // Try to book student1 - allowed. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); $result = booking_bookit::bookit('option', $settings->id, $student1->id); $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Try to book student3 - NOT allowed. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_ENROLLEDINCOHORTS, $id); } @@ -975,7 +977,7 @@ public function test_booking_bookit_add_to_group(array $bdata): void { // Via this line, we can get the blocking condition. // The true is only hardblocking, which means low blockers used to only show buttons etc. wont be shown. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Now check if the user is enrolled to the course. @@ -999,7 +1001,7 @@ public function test_booking_bookit_add_to_group(array $bdata): void { $result = booking_bookit::bookit('option', $settings->id, $student1->id); $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); } @@ -1069,7 +1071,7 @@ public function test_booking_bookit_bookingtime(array $bdata): void { // Book the student right away. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKING_TIME, $id); $result = booking_bookit::bookit('option', $settings->id, $student1->id); @@ -1077,7 +1079,7 @@ public function test_booking_bookit_bookingtime(array $bdata): void { // Via this line, we can get the blocking condition. // The true is only hardblocking, which means low blockers used to only show buttons etc. wont be shown. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKING_TIME, $id); } @@ -1148,11 +1150,11 @@ public function test_booking_bookit_askforconfirmation(array $bdata): void { // Book the student right away. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); $option = singleton_service::get_instance_of_booking_option($settings->cmid, $settings->id); @@ -1161,7 +1163,7 @@ public function test_booking_bookit_askforconfirmation(array $bdata): void { $option->user_submit_response($student1, 0, 0, 0, MOD_BOOKING_VERIFIED); $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); } @@ -1224,7 +1226,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): /** @var mod_booking_generator $plugingenerator */ $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); - $pricecategorydata = (object)[ + $pricecategorydata = (object) [ 'ordernum' => 1, 'name' => 'default', 'identifier' => 'default', @@ -1244,20 +1246,20 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): // Check option availability if user is not logged yet. require_logout(); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, false); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDINPRICE, $id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ISLOGGEDINPRICE, $id); // Book option1 by the student1 himself. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); // The user books now and is only on waitinglist. $result = booking_bookit::bookit('option', $settings->id, $student1->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); $option = singleton_service::get_instance_of_booking_option($settings->cmid, $settings->id); @@ -1271,15 +1273,15 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): // Add to the shopping_cart - set ALREADYRESERVED and verify status. $option->user_submit_response($student1, 0, 0, 1, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYRESERVED, $id); // Confirm user's booking. $option->user_submit_response($student1, 0, 0, 2, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); // The user sees now, after confirmation, correctly either the payment button or the noshoppingcart message. if (class_exists('local_shopping_cart\shopping_cart')) { @@ -1293,7 +1295,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): $option->user_submit_response($student1, 0, 0, 0, MOD_BOOKING_VERIFIED); // User 1 should be booked now. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Book a second user to fill the waitinglist. @@ -1302,35 +1304,35 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): $option->user_submit_response($student2, 0, 0, 0, MOD_BOOKING_VERIFIED); // Verify that second user is booked. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Now we check the third user. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); // The user is booked on the waitinglist. $result = booking_bookit::bookit('option', $settings->id, $student3->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); // Now we check the fourth user. $this->setUser($student4); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student4->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student4->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); // The user is booked on the waitinglist. $result = booking_bookit::bookit('option', $settings->id, $student4->id); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student4->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student4->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); // Confirm the user. $this->setAdminUser(); $option->user_submit_response($student3, 0, 0, 2, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); $ba = singleton_service::get_instance_of_booking_answers($settings); @@ -1338,7 +1340,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): // Should still be on waitinglist. // Not seeing price. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); // Now we take one user off the waitinglist. @@ -1346,7 +1348,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): $option->user_delete_response($student1->id); // So student1 is now delelted again, a place on the waitinglist has freed up. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); // Also take student 2 from the list, for a second place to free up. @@ -1354,7 +1356,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): $option->user_delete_response($student2->id); // So student2 is now delelted again, a place on the waitinglist has freed up. - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ASKFORCONFIRMATION, $id); // There should be still one free place left. @@ -1362,7 +1364,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): // Status for user 3 should have changed, from waitinglist to price is set. $this->setUser($student3); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student3->id, true); if (class_exists('local_shopping_cart\shopping_cart')) { $this->assertEquals(MOD_BOOKING_BO_COND_PRICEISSET, $id); } else { @@ -1372,7 +1374,7 @@ public function test_booking_bookit_askforconfirmation_with_price(array $bdata): // Even though there are still two free places: // As we didn't confirm student4, he should still be on waitinglist, even though a place would be free. $this->setUser($student4); - list($id, $isavailable, $description) = $boinfo->is_available($settings->id, $student4->id, true); + [$id, $isavailable, $description] = $boinfo->is_available($settings->id, $student4->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ONWAITINGLIST, $id); // Mandatory clean-up. @@ -1400,8 +1402,12 @@ public function test_booking_bookwithcredits(array $bdata): void { $course1 = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); // Create custom profile field. - $this->getDataGenerator()->create_custom_profile_field(['datatype' => 'text', 'shortname' => 'credit', 'name' => 'Credit', - 'visible' => PROFILE_VISIBLE_NONE]); + $this->getDataGenerator()->create_custom_profile_field([ + 'datatype' => 'text', + 'shortname' => 'credit', + 'name' => 'Credit', + 'visible' => PROFILE_VISIBLE_NONE + ]); // Create users. $users = [ @@ -1453,27 +1459,27 @@ public function test_booking_bookwithcredits(array $bdata): void { singleton_service::destroy_user($student2->id); // Verify book with credits. - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKWITHCREDITS, $id); // Student2 does allowed to book option1 in course1. $result = booking_bookit::bookit('option', $settings1->id, $student2->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CONFIRMBOOKWITHCREDITS, $id); $result = booking_bookit::bookit('option', $settings1->id, $student2->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // When we run it again, we might want to cancel. $result = booking_bookit::bookit('option', $settings1->id, $student2->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CONFIRMCANCEL, $id); // Now confirm cancel. $result = booking_bookit::bookit('option', $settings1->id, $student2->id); // The result is, that we see the bookingbutton again. - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKWITHCREDITS, $id); // Book the student1. @@ -1482,7 +1488,7 @@ public function test_booking_bookwithcredits(array $bdata): void { // Student1 does not allowed to book option1 in course1 - no enough credits. $result = booking_bookit::bookit('option', $settings1->id, $student1->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CONFIRMBOOKWITHCREDITS, $id); $this->expectException(\moodle_exception::class); @@ -1545,7 +1551,7 @@ public function test_booking_bookit_overbooking_with_price(array $bdata): void { /** @var mod_booking_generator $plugingenerator */ $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); - $pricecategorydata = (object)[ + $pricecategorydata = (object) [ 'ordernum' => 1, 'name' => 'default', 'identifier' => 'default', @@ -1570,7 +1576,7 @@ public function test_booking_bookit_overbooking_with_price(array $bdata): void { // Book the student1 right away. $this->setUser($student1); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); // The user sees now, after confirmation, correctly either the payment button or the noshoppingcart message. if (class_exists('local_shopping_cart\shopping_cart')) { $this->assertEquals(MOD_BOOKING_BO_COND_PRICEISSET, $id); @@ -1584,7 +1590,7 @@ public function test_booking_bookit_overbooking_with_price(array $bdata): void { $optionobj1 = singleton_service::get_instance_of_booking_option($settings1->cmid, $settings1->id); // Confirm user's booking. $optionobj1->user_submit_response($student1, 0, 0, 0, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Book option 1 by the student2. @@ -1592,18 +1598,18 @@ public function test_booking_bookit_overbooking_with_price(array $bdata): void { // The student2 cannot book - option is fully booked. $result = booking_bookit::bookit('option', $settings1->id, $student2->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // Admin try to override. $this->setAdminUser(); // Cehck current state. We should not use hard block to get "fully booked" (will get permanent "ask confirmation" than). - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, false); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // Even Admin denied to override and confirms the stundet2 booking. $optionobj1->user_submit_response($student2, 0, 0, 0, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, false); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, false); $this->assertEquals(MOD_BOOKING_BO_COND_FULLYBOOKED, $id); // Enable overbooking by athorized user. @@ -1611,7 +1617,7 @@ public function test_booking_bookit_overbooking_with_price(array $bdata): void { // Admin's override now successfull - student2 being booked. $optionobj1->user_submit_response($student2, 0, 0, 0, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Mandatory clean-up. @@ -1705,23 +1711,23 @@ public function test_booking_bookit_overlapping(array $bdata): void { $result = booking_bookit::bookit('option', $settings1->id, $student1->id); // Check for option2, should be blocked because of overlapping. - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_NOOVERLAPPING, $id); // Check for option3, should not be blocked. - list($id, $isavailable, $description) = $boinfo3->is_available($settings3->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); // Now enrol into bookingoption 3 which is forbidden to be booked with overlapping times. $result = booking_bookit::bookit('option', $settings3->id, $student1->id); $result = booking_bookit::bookit('option', $settings3->id, $student1->id); // Check that it really was booked. - list($id, $isavailable, $description) = $boinfo3->is_available($settings3->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); singleton_service::destroy_answers_for_user($student1->id); // Now try to book an option that doesn't contain the nooverlapping flab BUT overlaps with previously booked option 3. - list($id, $isavailable, $description) = $boinfo4->is_available($settings4->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo4->is_available($settings4->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_NOOVERLAPPINGPROXY, $id); } @@ -1825,23 +1831,23 @@ public function test_booking_bookit_overlapping_sessions(array $bdata): void { $result = booking_bookit::bookit('option', $settings1->id, $student1->id); // Check for option2, should be blocked because of overlapping. - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_NOOVERLAPPING, $id); // Check for option3, should not be blocked. - list($id, $isavailable, $description) = $boinfo3->is_available($settings3->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); // Now enrol into bookingoption 3 which is forbidden to be booked with overlapping times. $result = booking_bookit::bookit('option', $settings3->id, $student1->id); $result = booking_bookit::bookit('option', $settings3->id, $student1->id); // Check that it really was booked. - list($id, $isavailable, $description) = $boinfo3->is_available($settings3->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); singleton_service::destroy_answers_for_user($student1->id); // Now try to book an option that doesn't contain the nooverlapping flab BUT overlaps with previously booked option 3. - list($id, $isavailable, $description) = $boinfo4->is_available($settings4->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo4->is_available($settings4->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_JSON_NOOVERLAPPINGPROXY, $id); } @@ -1863,7 +1869,8 @@ public static function booking_common_settings_provider(): array { 'deletedtext' => ['text' => 'text'], 'pollurltext' => ['text' => 'text'], 'pollurlteacherstext' => ['text' => 'text'], - 'notificationtext' => ['text' => 'text'], 'userleave' => ['text' => 'text'], + 'notificationtext' => ['text' => 'text'], + 'userleave' => ['text' => 'text'], 'tags' => '', 'completion' => 2, 'showviews' => ['mybooking,myoptions,showall,showactive,myinstitution'], diff --git a/tests/booking_campaigns/booking_campaigns_test.php b/tests/booking_campaigns/booking_campaigns_test.php index 12653cd86..161119994 100644 --- a/tests/booking_campaigns/booking_campaigns_test.php +++ b/tests/booking_campaigns/booking_campaigns_test.php @@ -83,8 +83,12 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { // Setup test data. $course = $this->getDataGenerator()->create_course(['enablecompletion' => 1]); - $this->getDataGenerator()->create_custom_profile_field(['datatype' => 'text', 'shortname' => 'ugroup1', 'name' => 'ugroup1', - 'visible' => "2"]); + $this->getDataGenerator()->create_custom_profile_field([ + 'datatype' => 'text', + 'shortname' => 'ugroup1', + 'name' => 'ugroup1', + 'visible' => "2", + ]); // Create users. $student1 = $this->getDataGenerator()->create_user(['username' => 'student1', 'ugroup1' => 'student']); $student2 = $this->getDataGenerator()->create_user(); @@ -107,25 +111,25 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { $this->getDataGenerator()->enrol_user($teacher->id, $course->id, 'editingteacher'); $this->getDataGenerator()->enrol_user($bookingmanager->id, $course->id, 'editingteacher'); - $categorydata = new stdClass(); - $categorydata->name = 'BookCustomCat1'; + $categorydata = new stdClass(); + $categorydata->name = 'BookCustomCat1'; $categorydata->component = 'mod_booking'; - $categorydata->area = 'booking'; - $categorydata->itemid = 0; + $categorydata->area = 'booking'; + $categorydata->itemid = 0; $categorydata->contextid = context_system::instance()->id; - $bookingcat = $this->getDataGenerator()->create_custom_field_category((array)$categorydata); + $bookingcat = $this->getDataGenerator()->create_custom_field_category((array) $categorydata); $bookingcat->save(); - $fielddata = new stdClass(); - $fielddata->categoryid = $bookingcat->get('id'); - $fielddata->name = 'Sport1'; - $fielddata->shortname = 'spt1'; + $fielddata = new stdClass(); + $fielddata->categoryid = $bookingcat->get('id'); + $fielddata->name = 'Sport1'; + $fielddata->shortname = 'spt1'; $fielddata->type = 'text'; - $fielddata->configdata = "{\"required\":\"0\",\"uniquevalues\":\"0\",\"locked\":\"0\",\"visibility\":\"2\", + $fielddata->configdata = "{\"required\":\"0\",\"uniquevalues\":\"0\",\"locked\":\"0\",\"visibility\":\"2\", \"defaultvalue\":\"\",\"displaysize\":30,\"maxlength\":50,\"ispassword\":\"0\", \"link\":\"\",\"linktarget\":\"\"}"; - $bookingfield = $this->getDataGenerator()->create_custom_field((array)$fielddata); + $bookingfield = $this->getDataGenerator()->create_custom_field((array) $fielddata); $bookingfield->save(); $this->assertTrue(\core_customfield\field::record_exists($bookingfield->get('id'))); @@ -133,7 +137,7 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { $plugingenerator = self::getDataGenerator()->get_plugin_generator('mod_booking'); // Create 1st blocking campaing: with "above" condition. - $campaingdata1 = (object)[ + $campaingdata1 = (object) [ 'bofieldname' => 'spt1', 'fieldvalue' => 'tennis', 'campaignfieldnameoperator' => '=', @@ -146,15 +150,18 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { 'percentageavailableplaces' => 30, ]; $campaing1 = [ - 'name' => 'bloking_above30', 'type' => 1, - 'starttime' => strtotime('yesterday'), 'endtime' => strtotime('now + 1 month'), - 'pricefactor' => 1, 'limitfactor' => 1, + 'name' => 'bloking_above30', + 'type' => 1, + 'starttime' => strtotime('yesterday'), + 'endtime' => strtotime('now + 1 month'), + 'pricefactor' => 1, + 'limitfactor' => 1, 'json' => json_encode($campaingdata1), ]; $plugingenerator->create_campaign($campaing1); // Create 2nd blocking campaing: with "below" condition. - $campaingdata2 = (object)[ + $campaingdata2 = (object) [ 'bofieldname' => 'spt1', 'fieldvalue' => 'yoga', 'campaignfieldnameoperator' => '=', @@ -167,56 +174,40 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { 'percentageavailableplaces' => 30, ]; $campaing2 = [ - 'name' => 'bloking_below30', 'type' => 1, - 'starttime' => strtotime('yesterday'), 'endtime' => strtotime('now + 1 month'), - 'pricefactor' => 1, 'limitfactor' => 1, + 'name' => 'bloking_below30', + 'type' => 1, + 'starttime' => strtotime('yesterday'), + 'endtime' => strtotime('now + 1 month'), + 'pricefactor' => 1, + 'limitfactor' => 1, 'json' => json_encode($campaingdata2), ]; $plugingenerator->create_campaign($campaing2); - //Create 3rd blocking campaing: with multiple custom user profile fields and without bofield. - $campaingdata3 = (object)[ + // Create 3rd blocking campaing: with multiple custom user profile fields and without bofield. + $campaingdata3 = (object) [ 'bofieldname' => '0', 'campaignfieldnameoperator' => null, 'fieldvalue' => '', 'cpfield' => 'ugroup1', 'cpoperator' => '!~', - 'cpvalue' => ["student","employee"], + 'cpvalue' => ["student", "employee"], 'blockoperator' => 'blockalways', 'blockinglabel' => 'multiple user fields', 'hascapability' => "", 'percentageavailableplaces' => 50, ]; $campaing3 = [ - 'name' => 'multiple_user_fields', 'type' => 1, - 'starttime' => strtotime('yesterday'), 'endtime' => strtotime('now + 1 month'), - 'pricefactor' => 1, 'limitfactor' => 1, + 'name' => 'multiple_user_fields', + 'type' => 1, + 'starttime' => strtotime('yesterday'), + 'endtime' => strtotime('now + 1 month'), + 'pricefactor' => 1, + 'limitfactor' => 1, 'json' => json_encode($campaingdata3), ]; // TODO: For the moment, this campaign isn't active. // First make sure, user contains custom field value in $user->profile['ugroup1']. - // $plugingenerator->create_campaign($campaing3); - - // //Create 4th blocking campaing: with multiple custom user profile fields. - // $campaingdata3 = (object)[ - // 'bofieldname' => 'spt1', - // 'campaignfieldnameoperator' => '!~', - // 'fieldvalue' => 'yoga', - // 'cpfield' => 'ugroup1', - // 'cpoperator' => '!~', - // 'cpvalue' => ["student","employee"], - // 'blockoperator' => 'blockalways', - // 'blockinglabel' => 'multiple user fields', - // 'hascapability' => "", - // 'percentageavailableplaces' => 50, - // ]; - // $campaing4 = [ - // 'name' => 'multiple_user_fields', 'type' => 1, - // 'starttime' => strtotime('now - 3 days'), 'endtime' => strtotime('now + 1 month'), - // 'pricefactor' => 1, 'limitfactor' => 1, - // 'json' => json_encode($campaingdata3), - // ]; - // $plugingenerator->create_campaign($campaing3); // Create 1st booking option. $record = new stdClass(); @@ -252,33 +243,33 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { // Book option1. $result = booking_bookit::bookit('option', $settings1->id, $student1->id); $result = booking_bookit::bookit('option', $settings1->id, $student1->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Try to book option2 but cannot: "block_below_30". - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); // Try to book options with student2. $this->setUser($student2); singleton_service::destroy_user($student2->id); // Try to book option1 but cannot: "block_above_30". - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); // Try to book option2 but cannot: "block_below_30". - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); // Admin's adjustments for options / campaigns. $this->setAdminUser(); // Book the student1 directly into option2 to make it accessible for other users. $optionobj2->user_submit_response($student1, 0, 0, 0, MOD_BOOKING_VERIFIED); - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Validate that option2 become accessible for student2. $this->setUser($student2); singleton_service::destroy_user($student2->id); - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); $this->setAdminUser(); @@ -321,20 +312,20 @@ public function test_booking_bookit_campaign_blockbooking(array $bdata): void { $this->setUser($student1); singleton_service::destroy_user($student1->id); // Validate option1 already booked. - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Try to book option2. - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_ALREADYBOOKED, $id); // Try to book options with student2. $this->setUser($student2); singleton_service::destroy_user($student2->id); // Validate that option1 become accessible for student2 - campaign has not started yet. - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); // Validate that option2 became inaccessible for student2 again. - list($id, $isavailable, $description) = $boinfo2->is_available($settings2->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); } @@ -353,10 +344,14 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v // Create user profile custom fields. $this->getDataGenerator()->create_custom_profile_field([ - 'datatype' => 'text', 'shortname' => 'ucustom1', 'name' => 'ucustom1', + 'datatype' => 'text', + 'shortname' => 'ucustom1', + 'name' => 'ucustom1', ]); $this->getDataGenerator()->create_custom_profile_field([ - 'datatype' => 'text', 'shortname' => 'ucustom2', 'name' => 'ucustom2', + 'datatype' => 'text', + 'shortname' => 'ucustom2', + 'name' => 'ucustom2', ]); $users = [ @@ -395,25 +390,25 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v $this->getDataGenerator()->enrol_user($bookingmanager->id, $course1->id, 'editingteacher'); // Create booking custom field. - $categorydata = new stdClass(); - $categorydata->name = 'BookCustomCat1'; + $categorydata = new stdClass(); + $categorydata->name = 'BookCustomCat1'; $categorydata->component = 'mod_booking'; - $categorydata->area = 'booking'; - $categorydata->itemid = 0; + $categorydata->area = 'booking'; + $categorydata->itemid = 0; $categorydata->contextid = context_system::instance()->id; - $bookingcat = $this->getDataGenerator()->create_custom_field_category((array)$categorydata); + $bookingcat = $this->getDataGenerator()->create_custom_field_category((array) $categorydata); $bookingcat->save(); - $fielddata = new stdClass(); - $fielddata->categoryid = $bookingcat->get('id'); - $fielddata->name = 'bcustom1'; - $fielddata->shortname = 'bcustom1'; + $fielddata = new stdClass(); + $fielddata->categoryid = $bookingcat->get('id'); + $fielddata->name = 'bcustom1'; + $fielddata->shortname = 'bcustom1'; $fielddata->type = 'text'; - $fielddata->configdata = "{\"required\":\"0\",\"uniquevalues\":\"0\",\"locked\":\"0\",\"visibility\":\"2\", + $fielddata->configdata = "{\"required\":\"0\",\"uniquevalues\":\"0\",\"locked\":\"0\",\"visibility\":\"2\", \"defaultvalue\":\"\",\"displaysize\":30,\"maxlength\":50,\"ispassword\":\"0\", \"link\":\"\",\"linktarget\":\"\"}"; - $bookingfield = $this->getDataGenerator()->create_custom_field((array)$fielddata); + $bookingfield = $this->getDataGenerator()->create_custom_field((array) $fielddata); $bookingfield->save(); $this->assertTrue(\core_customfield\field::record_exists($bookingfield->get('id'))); @@ -469,7 +464,7 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v singleton_service::destroy_booking_option_singleton($option3->id); // Mandatory there. // Create blocking campaing. - $campaingdata = (object)[ + $campaingdata = (object) [ 'bofieldname' => 'bcustom1', 'fieldvalue' => 'exclude', 'campaignfieldnameoperator' => '!~', // Does not contain! @@ -483,9 +478,12 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v ]; $campaing = new stdClass(); $campaing = [ - 'name' => 'bloking1', 'type' => 1, - 'starttime' => strtotime('yesterday'), 'endtime' => strtotime('now + 1 week'), - 'pricefactor' => 1, 'limitfactor' => 1, + 'name' => 'bloking1', + 'type' => 1, + 'starttime' => strtotime('yesterday'), + 'endtime' => strtotime('now + 1 week'), + 'pricefactor' => 1, + 'limitfactor' => 1, 'json' => json_encode($campaingdata), ]; @@ -521,29 +519,29 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v $this->setUser($student1); singleton_service::destroy_user($student1->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings2->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings2->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings3->id, $student1->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student1->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id); $this->setUser($student2); singleton_service::destroy_user($student2->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings2->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings2->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings3->id, $student2->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student2->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); $this->setUser($student3); singleton_service::destroy_user($student3->id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings1->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings2->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings2->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); - list($id, $isavailable, $description) = $boinfo1->is_available($settings3->id, $student3->id, true); + [$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student3->id, true); $this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id); } @@ -565,7 +563,8 @@ public static function booking_campaigns_settings_provider(): array { 'deletedtext' => ['text' => 'text'], 'pollurltext' => ['text' => 'text'], 'pollurlteacherstext' => ['text' => 'text'], - 'notificationtext' => ['text' => 'text'], 'userleave' => ['text' => 'text'], + 'notificationtext' => ['text' => 'text'], + 'userleave' => ['text' => 'text'], 'tags' => '', 'completion' => 2, 'showviews' => ['mybooking,myoptions,showall,showactive,myinstitution'],