From 6826c90db5b1ff858f847aee652e36604af42d56 Mon Sep 17 00:00:00 2001 From: Andrii Semenets Date: Fri, 13 Dec 2024 19:22:54 +0200 Subject: [PATCH] update phpunit test method test_backup_restore_bookings_with_options_quiz_into_other_course() to use few date sessions (#518) --- tests/backup/backup_restore_test.php | 61 +++++++++++++++++++++------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/tests/backup/backup_restore_test.php b/tests/backup/backup_restore_test.php index 8adebc417..f50f02ade 100644 --- a/tests/backup/backup_restore_test.php +++ b/tests/backup/backup_restore_test.php @@ -174,14 +174,27 @@ public function test_backup_restore_bookings_with_options_quiz_into_other_course $this->assertCount(2, $options2); $option20 = array_shift($options2); $this->assertEquals($options[0]->text, $option20->text); - $this->assertEquals($options[0]->coursestarttime, $option20->coursestarttime); - $this->assertEquals($options[0]->courseendtime, $option20->courseendtime); + $this->assertEquals($options[0]->coursestarttime_1, $option20->coursestarttime); + $this->assertEquals($options[0]->courseendtime_2, $option20->courseendtime); $this->assertEquals($options[0]->customfield_spt1, $option20->spt1); + $optionsettings = singleton_service::get_instance_of_booking_option_settings($option20->id); + $sessions = $optionsettings->sessions; + $this->assertCount(2, $sessions); + $session1 = array_shift($sessions); + $this->assertEquals($options[0]->coursestarttime_1, $session1->coursestarttime); + $this->assertEquals($options[0]->courseendtime_1, $session1->courseendtime); + $session2 = array_shift($sessions); + $this->assertEquals($options[0]->coursestarttime_2, $session2->coursestarttime); + $this->assertEquals($options[0]->courseendtime_2, $session2->courseendtime); + $option21 = array_shift($options2); $this->assertEquals($options[1]->text, $option21->text); - $this->assertEquals($options[1]->coursestarttime, $option21->coursestarttime); - $this->assertEquals($options[1]->courseendtime, $option21->courseendtime); + $this->assertEquals($options[1]->coursestarttime_1, $option21->coursestarttime); + $this->assertEquals($options[1]->courseendtime_1, $option21->courseendtime); $this->assertEquals($options[1]->customfield_spt1, $option21->spt1); + $optionsettings = singleton_service::get_instance_of_booking_option_settings($option21->id); + $this->assertCount(1, $optionsettings->sessions); + // Validabe 2nd booking and its options. $booking22 = array_shift($bookings2); $this->assertEquals($bookings[1]->name, $booking22->get_name()); @@ -190,14 +203,26 @@ public function test_backup_restore_bookings_with_options_quiz_into_other_course $this->assertCount(2, $options2); $option22 = array_shift($options2); $this->assertEquals($options[2]->text, $option22->text); - $this->assertEquals($options[2]->coursestarttime, $option22->coursestarttime); - $this->assertEquals($options[2]->courseendtime, $option22->courseendtime); + $this->assertEquals($options[2]->coursestarttime_1, $option22->coursestarttime); + $this->assertEquals($options[2]->courseendtime_2, $option22->courseendtime); $this->assertEquals($options[2]->customfield_spt1, $option22->spt1); + $optionsettings = singleton_service::get_instance_of_booking_option_settings($option22->id); + $sessions = $optionsettings->sessions; + $this->assertCount(2, $sessions); + $session1 = array_shift($sessions); + $this->assertEquals($options[2]->coursestarttime_1, $session1->coursestarttime); + $this->assertEquals($options[2]->courseendtime_1, $session1->courseendtime); + $session2 = array_shift($sessions); + $this->assertEquals($options[2]->coursestarttime_2, $session2->coursestarttime); + $this->assertEquals($options[2]->courseendtime_2, $session2->courseendtime); + $option23 = array_shift($options2); $this->assertEquals($options[3]->text, $option23->text); - $this->assertEquals($options[3]->coursestarttime, $option23->coursestarttime); - $this->assertEquals($options[3]->courseendtime, $option23->courseendtime); + $this->assertEquals($options[3]->coursestarttime_1, $option23->coursestarttime); + $this->assertEquals($options[3]->courseendtime_1, $option23->courseendtime); $this->assertEquals($options[3]->customfield_spt1, $option23->spt1); + $optionsettings = singleton_service::get_instance_of_booking_option_settings($option23->id); + $this->assertCount(1, $optionsettings->sessions); singleton_service::destroy_instance(); } @@ -228,21 +253,29 @@ public static function booking_backup_restore_settings_provider(): array { 'showviews' => ['mybooking,myoptions,showall,showactive,myinstitution'], ], 'options' => [ - // Option 1 with dates from 2044/05/15 till 2044/05/17. + // Option 1 with 2 sessions. 0 => [ 'text' => 'Test Option 1', 'courseid' => 0, 'maxanswers' => 2, - 'coursestarttime' => 2346937200, - 'courseendtime' => 2347110000, + 'optiondateid_1' => "0", + 'daystonotify_1' => "0", + 'coursestarttime_1' => strtotime('20 May 2050 15:00'), + 'courseendtime_1' => strtotime('20 June 2050 14:00'), + 'optiondateid_2' => "0", + 'daystonotify_2' => "0", + 'coursestarttime_2' => strtotime('20 June 2050 15:00'), + 'courseendtime_2' => strtotime('20 July 2050 14:00'), ], - // Option 2 with dates from 2044/05/17 till 2044/05/19. + // Option 2 with single session. 1 => [ 'text' => 'Test Option 2', 'courseid' => 0, 'maxanswers' => 4, - 'coursestarttime' => 2347110000, - 'courseendtime' => 2347282800, + 'optiondateid_1' => "0", + 'daystonotify_1' => "0", + 'coursestarttime_1' => strtotime('20 July 2050 15:00'), + 'courseendtime_1' => strtotime('20 August 2050 14:00'), ], ], ];