Skip to content
Snippets Groups Projects
Commit fe278109 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

fix tests for consultations, fixes #1794

Closes #1794

Merge request studip/studip!1175
parent c0fd6686
No related branches found
No related tags found
No related merge requests found
...@@ -41,17 +41,32 @@ trait ConsultationHelper ...@@ -41,17 +41,32 @@ trait ConsultationHelper
return User::find($credentials['id']); return User::find($credentials['id']);
} }
protected function createBlockWithSlotsForRange(Range $range, array $additional_data = []): ConsultationBlock protected function createBlockWithSlotsForRange(Range $range, bool $lock_blocks = false): ConsultationBlock
{ {
$hour = date('H'); // Generate start and end time. Assures that the day is not a holiday.
$begin = strtotime("today {$hour}:00:00"); $now = time();
$end = strtotime('+2 hours', $begin);
do {
$begin = strtotime('next monday 8:00:00', $now);
$end = strtotime('+2 hours', $begin);
$now = strtotime('+1 week', $now);
$temp = holiday($begin);
} while (is_array($temp) && $temp['col'] === 3);
// Lock blocks?
$additional_data = [];
if ($lock_blocks) {
$additional_data['lock_time'] = ceil(($begin - time()) / 3600);
}
// Generate blocks
$blocks = ConsultationBlock::generateBlocks( $blocks = ConsultationBlock::generateBlocks(
$range, $range,
$begin, $begin,
$end, $end,
date('w'), date('w', $begin),
1 1
); );
$blocks = iterator_to_array($blocks); $blocks = iterator_to_array($blocks);
......
...@@ -27,12 +27,12 @@ class ConsultationsBookingCreateBySlotIndexTest extends Codeception\Test\Unit ...@@ -27,12 +27,12 @@ class ConsultationsBookingCreateBySlotIndexTest extends Codeception\Test\Unit
); );
} }
public function testAutorMayCreateNotCreateBookingDueToLock(): void public function testAutorMayNotCreateBookingDueToLock(): void
{ {
$credentials = $this->tester->getCredentialsForTestDozent(); $credentials = $this->tester->getCredentialsForTestDozent();
$range = User::find($credentials['id']); $range = User::find($credentials['id']);
$block = $this->createBlockWithSlotsForRange($range, ['lock_time' => 2]); $block = $this->createBlockWithSlotsForRange($range, true);
$slot = $this->getSlotFromBlock($block); $slot = $this->getSlotFromBlock($block);
$response = $this->createBooking( $response = $this->createBooking(
......
...@@ -28,12 +28,12 @@ class ConsultationsBookingCreateTest extends Codeception\Test\Unit ...@@ -28,12 +28,12 @@ class ConsultationsBookingCreateTest extends Codeception\Test\Unit
); );
} }
public function testAutorMayCreateNotCreateBookingDueToLock(): void public function testAutorMayNotCreateBookingDueToLock(): void
{ {
$credentials = $this->tester->getCredentialsForTestDozent(); $credentials = $this->tester->getCredentialsForTestDozent();
$range = User::find($credentials['id']); $range = User::find($credentials['id']);
$block = $this->createBlockWithSlotsForRange($range, ['lock_time' => 2]); $block = $this->createBlockWithSlotsForRange($range, true);
$slot = $this->getSlotFromBlock($block); $slot = $this->getSlotFromBlock($block);
$response = $this->createBooking( $response = $this->createBooking(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment