Skip to content

Commit

Permalink
update phpunit test method test_backup_restore_bookings_with_options_…
Browse files Browse the repository at this point in the history
…quiz_into_other_course() to use few date sessions (#518)
  • Loading branch information
semteacher committed Dec 13, 2024
1 parent 860ff20 commit 6826c90
Showing 1 changed file with 47 additions and 14 deletions.
61 changes: 47 additions & 14 deletions tests/backup/backup_restore_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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();
}
Expand Down Expand Up @@ -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'),
],
],
];
Expand Down

0 comments on commit 6826c90

Please sign in to comment.