Skip to content

Commit

Permalink
fix and extend test_booking_campaign_blockbooking_customfields() phpu…
Browse files Browse the repository at this point in the history
…nit (#719)
  • Loading branch information
semteacher committed Dec 7, 2024
1 parent 0eb04c0 commit f6ed210
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions tests/booking_campaigns/booking_campaigns_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v
$student6 = $this->getDataGenerator()->create_user();
$student7 = $this->getDataGenerator()->create_user();
$student8 = $this->getDataGenerator()->create_user();
$student9 = $this->getDataGenerator()->create_user(['profile_field_ucustom1' => 'student']);
$student9 = $this->getDataGenerator()->create_user(['profile_field_ucustom1' => 'other1,other2']);
$employee = $this->getDataGenerator()->create_user(['profile_field_ucustom1' => 'employee']);
$multipleugroups = $this->getDataGenerator()->create_user(['profile_field_ucustom1' => 'employee,somethingelse']);
$teacher = $this->getDataGenerator()->create_user();
Expand Down Expand Up @@ -559,7 +559,7 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v

$record = new stdClass();
$record->bookingid = $booking1->id;
$record->text = 'Test option1';
$record->text = 'Test option';
$record->chooseorcreatecourse = 1;
$record->courseid = $course2->id;
$record->useprice = 0;
Expand All @@ -575,7 +575,7 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v

$record = new stdClass();
$record->bookingid = $booking1->id;
$record->text = 'Test option1';
$record->text = 'Test option3';
$record->chooseorcreatecourse = 1;
$record->courseid = $course2->id;
$record->useprice = 0;
Expand All @@ -593,9 +593,9 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v
$campaingdata1 = (object) [
'bofieldname' => 'bcustom1',
'fieldvalue' => 'exclude',
'campaignfieldnameoperator' => '!~', // Does not contain!
'campaignfieldnameoperator' => '!~', // Does not contains!
'cpfield' => 'ucustom1',
'cpoperator' => '~',
'cpoperator' => '~', // Contains!
'cpvalue' => ['student'],
'blockoperator' => 'blockbelow',
'blockinglabel' => 'Below_50',
Expand All @@ -620,7 +620,7 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v
'campaignfieldnameoperator' => null,
'fieldvalue' => '',
'cpfield' => 'ucustom1',
'cpoperator' => '!~',
'cpoperator' => '!~', // Does not contains!
'cpvalue' => ["student", "employee", "teacher"],
'blockoperator' => 'blockalways',
'blockinglabel' => 'multiple user fields',
Expand Down Expand Up @@ -672,30 +672,62 @@ public function test_booking_campaign_blockbooking_customfields(array $bdata): v
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student1->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
// Blocked by campaign1.
[$id, $isavailable, $description] = $boinfo1->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);
// Blocked by campaign1.
[$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student1->id, true);
[$id, $isavailable, $description] = $boinfo3->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);
// All blocked by campaign2.
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student2->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id);
[$id, $isavailable, $description] = $boinfo1->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);
[$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student2->id, true);
[$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student2->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id);

$this->setUser($student3);
singleton_service::destroy_user($student3->id);
// All accessible.
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student3->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo1->is_available($settings2->id, $student3->id, true);
[$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student3->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo1->is_available($settings3->id, $student3->id, true);
[$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student3->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);

$this->setUser($student9);
singleton_service::destroy_user($student9->id);
// All blocked by campaign2.
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $student9->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id);
[$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $student9->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id);
[$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $student9->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_CAMPAIGN_BLOCKBOOKING, $id);

// Try to book options with employee.
$this->setUser($employee);
singleton_service::destroy_user($employee->id);
// All accessible.
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $employee->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $employee->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $employee->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);

// Try to book options with multipleugroups.
$this->setUser($multipleugroups);
singleton_service::destroy_user($multipleugroups->id);
// All accessible.
[$id, $isavailable, $description] = $boinfo1->is_available($settings1->id, $multipleugroups->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo2->is_available($settings2->id, $multipleugroups->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
[$id, $isavailable, $description] = $boinfo3->is_available($settings3->id, $multipleugroups->id, true);
$this->assertEquals(MOD_BOOKING_BO_COND_BOOKITBUTTON, $id);
}

Expand Down

0 comments on commit f6ed210

Please sign in to comment.