Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 241dad54

Von Kivitendo Admin vor mehr als 1 Jahr hinzugefügt

  • ID 241dad5457c1ae4eb27da6a48705f24c15d15c4d
  • Vorgänger 7f8c2f99
  • Nachfolger 925ce2e6

Typo in Testname

Unterschiede anzeigen:

t/db/time_recordig.t
1
use Test::More tests => 40;
2

  
3
use strict;
4

  
5
use lib 't';
6
use utf8;
7

  
8
use Support::TestSetup;
9
use Test::Exception;
10
use DateTime;
11

  
12
use_ok 'SL::DB::TimeRecording';
13

  
14
use SL::Dev::ALL qw(:ALL);
15

  
16
Support::TestSetup::login();
17

  
18
my @time_recordings;
19
my ($s1, $e1, $s2, $e2);
20

  
21
sub clear_up {
22
  foreach (qw(TimeRecording Customer)) {
23
    "SL::DB::Manager::${_}"->delete_all(all => 1);
24
  }
25
  SL::DB::Manager::Employee->delete_all(where => [ '!login' => 'unittests' ]);
26
};
27

  
28
########################################
29

  
30
$s1 = DateTime->now_local;
31
$e1 = $s1->clone;
32

  
33
clear_up;
34

  
35
@time_recordings = ();
36
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1);
37

  
38
ok( $time_recordings[0]->is_time_in_wrong_order, 'same start and end detected' );
39
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping if only one time recording entry in db' );
40

  
41
###
42
$time_recordings[0]->end_time(undef);
43
ok( !$time_recordings[0]->is_time_in_wrong_order, 'order ok if no end' );
44

  
45
########################################
46
# ------------s1-----e1-----
47
# --s2---e2-----------------
48
# -> does not overlap
49
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
50
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
51
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
52
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 11, minute => 0);
53

  
54
clear_up;
55

  
56
@time_recordings = ();
57
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
58
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
59

  
60
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: completely before 1' );
61
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: completely before 2' );
62

  
63

  
64
# -------s1-----e1----------
65
# --s2---e2-----------------
66
# -> does not overlap
67
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
68
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
69
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
70
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
71

  
72
clear_up;
73

  
74
@time_recordings = ();
75
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
76
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
77

  
78
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: before 1' );
79
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: before 2' );
80

  
81
# ---s1-----e1--------------
82
# ---------------s2---e2----
83
# -> does not overlap
84
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
85
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
86
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 13, minute => 0);
87
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
88

  
89
clear_up;
90

  
91
@time_recordings = ();
92
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
93
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
94

  
95
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: completely after 1' );
96
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: completely after 2' );
97

  
98
# ---s1-----e1--------------
99
# ----------s2---e2---------
100
# -> does not overlap
101
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
102
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
103
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
104
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
105

  
106
clear_up;
107

  
108
@time_recordings = ();
109
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
110
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
111

  
112
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: after 1' );
113
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: after 2' );
114

  
115
# -------s1-----e1----------
116
# ---s2-----e2--------------
117
# -> overlaps
118
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
119
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
120
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour =>  9, minute => 0);
121
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
122

  
123
clear_up;
124

  
125
@time_recordings = ();
126
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
127
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
128

  
129
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start before, end inbetween' );
130

  
131
# -------s1-----e1----------
132
# -----------s2-----e2------
133
# -> overlaps
134
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
135
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
136
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
137
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
138

  
139
clear_up;
140

  
141
@time_recordings = ();
142
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
143
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
144

  
145
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start inbetween, end after' );
146

  
147
# ---s1---------e1----------
148
# ------s2---e2-------------
149
# -> overlaps
150
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
151
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
152
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
153
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
154

  
155
clear_up;
156

  
157
@time_recordings = ();
158
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
159
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
160

  
161
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: completely inbetween' );
162

  
163

  
164
# ------s1---e1-------------
165
# ---s2---------e2----------
166
# -> overlaps
167
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
168
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
169
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
170
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
171

  
172
clear_up;
173

  
174
@time_recordings = ();
175
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
176
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
177

  
178
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: completely oudside' );
179

  
180

  
181
# ---s1---e1----------------
182
# ---s2---------e2----------
183
# -> overlaps
184
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
185
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
186
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
187
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
188

  
189
clear_up;
190

  
191
@time_recordings = ();
192
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
193
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
194

  
195
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: same start, end outside' );
196

  
197
# ---s1------e1-------------
198
# ------s2---e2-------------
199
# -> overlaps
200
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
201
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
202
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
203
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
204

  
205
clear_up;
206

  
207
@time_recordings = ();
208
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
209
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
210

  
211
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start after, same end' );
212

  
213
# ---s1------e1-------------
214
# ------s2------------------
215
# e2 undef
216
# -> overlaps
217
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
218
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
219
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
220
$e2 = undef;
221

  
222
clear_up;
223

  
224
@time_recordings = ();
225
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
226
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
227

  
228
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start inbetween, no end' );
229

  
230
# ---s1------e1-------------
231
# ---s2---------------------
232
# e2 undef
233
# -> overlaps
234
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
235
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
236
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
237
$e2 = undef;
238

  
239
clear_up;
240

  
241
@time_recordings = ();
242
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
243
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
244

  
245
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: same start, no end' );
246

  
247
# -------s1------e1---------
248
# ---s2---------------------
249
# e2 undef
250
# -> does not overlap
251
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
252
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
253
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
254
$e2 = undef;
255

  
256
clear_up;
257

  
258
@time_recordings = ();
259
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
260
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
261

  
262
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: start before, no end' );
263

  
264
# -------s1------e1---------
265
# -------------------s2-----
266
# e2 undef
267
# -> does not overlap
268
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
269
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
270
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 16, minute => 0);
271
$e2 = undef;
272

  
273
clear_up;
274

  
275
@time_recordings = ();
276
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
277
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
278

  
279
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: start after, no end' );
280

  
281
# -------s1------e1---------
282
# ---------------s2---------
283
# e2 undef
284
# -> does not overlap
285

  
286
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
287
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
288
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
289
$e2 = undef;
290

  
291
clear_up;
292

  
293
@time_recordings = ();
294
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
295
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
296

  
297
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: same start as other end, no end' );
298

  
299
# -------s1------e1---------
300
# -----------e2-------------
301
# s2 undef
302
# -> overlaps
303
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
304
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
305
$s2 = undef;
306
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
307

  
308
clear_up;
309

  
310
@time_recordings = ();
311
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
312
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
313

  
314
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no start, end inbetween' );
315

  
316
# -------s1------e1---------
317
# ---------------e2---------
318
# s2 undef
319
# -> overlaps
320
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
321
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
322
$s2 = undef;
323
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
324

  
325
clear_up;
326

  
327
@time_recordings = ();
328
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
329
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
330

  
331
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no start, same end' );
332

  
333
# -------s1------e1---------
334
# --e2----------------------
335
# s2 undef
336
# -> does not overlap
337
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
338
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
339
$s2 = undef;
340
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
341

  
342
clear_up;
343

  
344
@time_recordings = ();
345
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
346
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
347

  
348
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, end before' );
349

  
350
# -------s1------e1---------
351
# -------------------e2-----
352
# s2 undef
353
# -> does not overlap
354
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
355
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
356
$s2 = undef;
357
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
358

  
359
clear_up;
360

  
361
@time_recordings = ();
362
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
363
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
364

  
365
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, end after' );
366

  
367
# -------s1------e1---------
368
# -------e2-----------------
369
# s2 undef
370
# -> does not overlap
371
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
372
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
373
$s2 = undef;
374
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
375

  
376
clear_up;
377

  
378
@time_recordings = ();
379
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
380
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
381

  
382
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, same end as other start' );
383

  
384
# ----s1--------------------
385
# ----s2-----e2-------------
386
# e1 undef
387
# -> overlaps
388
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
389
$e1 = undef;
390
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
391
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
392

  
393
clear_up;
394

  
395
@time_recordings = ();
396
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
397
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
398

  
399
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no end in db, same start' );
400

  
401
# --------s1----------------
402
# ----s2-----e2-------------
403
# e1 undef
404
# -> does not overlap
405
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
406
$e1 = undef;
407
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
408
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
409

  
410
clear_up;
411

  
412
@time_recordings = ();
413
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
414
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
415

  
416
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, enclosing' );
417

  
418
# ---s1---------------------
419
# ---------s2-----e2--------
420
# e1 undef
421
# -> does not overlap
422
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
423
$e1 = undef;
424
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
425
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
426

  
427
clear_up;
428

  
429
@time_recordings = ();
430
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
431
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
432

  
433
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, completely after' );
434

  
435
# ---------s1---------------
436
# --------------------------
437
# e1, s2, e2 undef
438
# -> does not overlap
439
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
440
$e1 = undef;
441
$s2 = undef;
442
$e2 = undef;
443

  
444
clear_up;
445

  
446
@time_recordings = ();
447
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
448
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
449

  
450
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no times in object' );
451

  
452
# ---------s1---------------
453
# -----s2-------------------
454
# e1, e2 undef
455
# -> does not overlap
456
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
457
$e1 = undef;
458
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
459
$e2 = undef;
460

  
461
clear_up;
462

  
463
@time_recordings = ();
464
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
465
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
466

  
467
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, start before, no end in object' );
468

  
469
# ---------s1---------------
470
# -------------s2-----------
471
# e1, e2 undef
472
# -> does not overlap
473
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
474
$e1 = undef;
475
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
476
$e2 = undef;
477

  
478
clear_up;
479

  
480
@time_recordings = ();
481
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
482
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
483

  
484
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, start after, no end in object' );
485

  
486
# ---------s1---------------
487
# ---------s2---------------
488
# e1, e2 undef
489
# -> overlaps
490
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
491
$e1 = undef;
492
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
493
$e2 = undef;
494

  
495
clear_up;
496

  
497
@time_recordings = ();
498
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
499
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
500

  
501
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no end in db, same start' );
502

  
503
# ---------s1---------------
504
# ---e2---------------------
505
# e1, s2 undef
506
# -> does not overlap
507
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
508
$e1 = undef;
509
$s2 = undef;
510
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
511

  
512
clear_up;
513

  
514
@time_recordings = ();
515
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
516
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
517

  
518
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, end before' );
519

  
520
# ---------s1---------------
521
# ---------------e2---------
522
# e1, s2 undef
523
# -> does not overlap
524
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
525
$e1 = undef;
526
$s2 = undef;
527
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
528

  
529
clear_up;
530

  
531
@time_recordings = ();
532
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
533
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
534

  
535
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, end after' );
536

  
537
# ---------s1---------------
538
# ---------e2---------------
539
# e1, s2 undef
540
# -> does not overlap
541
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
542
$e1 = undef;
543
$s2 = undef;
544
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
545

  
546
clear_up;
547

  
548
@time_recordings = ();
549
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
550
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
551

  
552
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, same end' );
553

  
554
########################################
555
# not overlapping if different staff_member
556
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
557
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
558
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 11, minute => 0);
559
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
560

  
561
clear_up;
562

  
563
@time_recordings = ();
564
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
565
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
566

  
567
ok( $time_recordings[1]->is_time_overlapping, 'overlapping if same staff member' );
568
$time_recordings[1]->update_attributes(staff_member => SL::DB::Employee->new(
569
                                         'login' => 'testuser',
570
                                         'name'  => 'Test User',
571
                                       )->save);
572
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping if different staff member' );
573

  
574
clear_up;
575

  
576
1;
577

  
578

  
579
# set emacs to perl mode
580
# Local Variables:
581
# mode: perl
582
# End:
t/db/time_recording.t
1
use Test::More tests => 40;
2

  
3
use strict;
4

  
5
use lib 't';
6
use utf8;
7

  
8
use Support::TestSetup;
9
use Test::Exception;
10
use DateTime;
11

  
12
use_ok 'SL::DB::TimeRecording';
13

  
14
use SL::Dev::ALL qw(:ALL);
15

  
16
Support::TestSetup::login();
17

  
18
my @time_recordings;
19
my ($s1, $e1, $s2, $e2);
20

  
21
sub clear_up {
22
  foreach (qw(TimeRecording Customer)) {
23
    "SL::DB::Manager::${_}"->delete_all(all => 1);
24
  }
25
  SL::DB::Manager::Employee->delete_all(where => [ '!login' => 'unittests' ]);
26
};
27

  
28
########################################
29

  
30
$s1 = DateTime->now_local;
31
$e1 = $s1->clone;
32

  
33
clear_up;
34

  
35
@time_recordings = ();
36
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1);
37

  
38
ok( $time_recordings[0]->is_time_in_wrong_order, 'same start and end detected' );
39
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping if only one time recording entry in db' );
40

  
41
###
42
$time_recordings[0]->end_time(undef);
43
ok( !$time_recordings[0]->is_time_in_wrong_order, 'order ok if no end' );
44

  
45
########################################
46
# ------------s1-----e1-----
47
# --s2---e2-----------------
48
# -> does not overlap
49
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
50
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
51
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
52
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 11, minute => 0);
53

  
54
clear_up;
55

  
56
@time_recordings = ();
57
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
58
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
59

  
60
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: completely before 1' );
61
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: completely before 2' );
62

  
63

  
64
# -------s1-----e1----------
65
# --s2---e2-----------------
66
# -> does not overlap
67
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
68
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
69
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
70
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
71

  
72
clear_up;
73

  
74
@time_recordings = ();
75
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
76
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
77

  
78
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: before 1' );
79
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: before 2' );
80

  
81
# ---s1-----e1--------------
82
# ---------------s2---e2----
83
# -> does not overlap
84
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
85
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
86
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 13, minute => 0);
87
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
88

  
89
clear_up;
90

  
91
@time_recordings = ();
92
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
93
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
94

  
95
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: completely after 1' );
96
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: completely after 2' );
97

  
98
# ---s1-----e1--------------
99
# ----------s2---e2---------
100
# -> does not overlap
101
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
102
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
103
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
104
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
105

  
106
clear_up;
107

  
108
@time_recordings = ();
109
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
110
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2)->save;
111

  
112
ok( !$time_recordings[0]->is_time_overlapping, 'not overlapping: after 1' );
113
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: after 2' );
114

  
115
# -------s1-----e1----------
116
# ---s2-----e2--------------
117
# -> overlaps
118
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
119
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
120
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour =>  9, minute => 0);
121
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
122

  
123
clear_up;
124

  
125
@time_recordings = ();
126
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
127
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
128

  
129
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start before, end inbetween' );
130

  
131
# -------s1-----e1----------
132
# -----------s2-----e2------
133
# -> overlaps
134
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
135
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
136
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
137
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
138

  
139
clear_up;
140

  
141
@time_recordings = ();
142
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
143
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
144

  
145
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start inbetween, end after' );
146

  
147
# ---s1---------e1----------
148
# ------s2---e2-------------
149
# -> overlaps
150
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
151
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
152
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
153
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
154

  
155
clear_up;
156

  
157
@time_recordings = ();
158
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
159
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
160

  
161
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: completely inbetween' );
162

  
163

  
164
# ------s1---e1-------------
165
# ---s2---------e2----------
166
# -> overlaps
167
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
168
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
169
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
170
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
171

  
172
clear_up;
173

  
174
@time_recordings = ();
175
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
176
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
177

  
178
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: completely oudside' );
179

  
180

  
181
# ---s1---e1----------------
182
# ---s2---------e2----------
183
# -> overlaps
184
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
185
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
186
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
187
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
188

  
189
clear_up;
190

  
191
@time_recordings = ();
192
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
193
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
194

  
195
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: same start, end outside' );
196

  
197
# ---s1------e1-------------
198
# ------s2---e2-------------
199
# -> overlaps
200
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
201
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
202
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
203
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
204

  
205
clear_up;
206

  
207
@time_recordings = ();
208
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
209
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
210

  
211
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start after, same end' );
212

  
213
# ---s1------e1-------------
214
# ------s2------------------
215
# e2 undef
216
# -> overlaps
217
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
218
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
219
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
220
$e2 = undef;
221

  
222
clear_up;
223

  
224
@time_recordings = ();
225
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
226
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
227

  
228
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: start inbetween, no end' );
229

  
230
# ---s1------e1-------------
231
# ---s2---------------------
232
# e2 undef
233
# -> overlaps
234
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
235
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
236
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
237
$e2 = undef;
238

  
239
clear_up;
240

  
241
@time_recordings = ();
242
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
243
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
244

  
245
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: same start, no end' );
246

  
247
# -------s1------e1---------
248
# ---s2---------------------
249
# e2 undef
250
# -> does not overlap
251
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
252
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
253
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
254
$e2 = undef;
255

  
256
clear_up;
257

  
258
@time_recordings = ();
259
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
260
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
261

  
262
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: start before, no end' );
263

  
264
# -------s1------e1---------
265
# -------------------s2-----
266
# e2 undef
267
# -> does not overlap
268
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
269
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
270
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 16, minute => 0);
271
$e2 = undef;
272

  
273
clear_up;
274

  
275
@time_recordings = ();
276
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
277
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
278

  
279
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: start after, no end' );
280

  
281
# -------s1------e1---------
282
# ---------------s2---------
283
# e2 undef
284
# -> does not overlap
285

  
286
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
287
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
288
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
289
$e2 = undef;
290

  
291
clear_up;
292

  
293
@time_recordings = ();
294
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
295
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
296

  
297
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: same start as other end, no end' );
298

  
299
# -------s1------e1---------
300
# -----------e2-------------
301
# s2 undef
302
# -> overlaps
303
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
304
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
305
$s2 = undef;
306
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
307

  
308
clear_up;
309

  
310
@time_recordings = ();
311
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
312
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
313

  
314
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no start, end inbetween' );
315

  
316
# -------s1------e1---------
317
# ---------------e2---------
318
# s2 undef
319
# -> overlaps
320
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
321
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
322
$s2 = undef;
323
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
324

  
325
clear_up;
326

  
327
@time_recordings = ();
328
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
329
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
330

  
331
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no start, same end' );
332

  
333
# -------s1------e1---------
334
# --e2----------------------
335
# s2 undef
336
# -> does not overlap
337
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
338
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
339
$s2 = undef;
340
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
341

  
342
clear_up;
343

  
344
@time_recordings = ();
345
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
346
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
347

  
348
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, end before' );
349

  
350
# -------s1------e1---------
351
# -------------------e2-----
352
# s2 undef
353
# -> does not overlap
354
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
355
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
356
$s2 = undef;
357
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 17, minute => 0);
358

  
359
clear_up;
360

  
361
@time_recordings = ();
362
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
363
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
364

  
365
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, end after' );
366

  
367
# -------s1------e1---------
368
# -------e2-----------------
369
# s2 undef
370
# -> does not overlap
371
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
372
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
373
$s2 = undef;
374
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
375

  
376
clear_up;
377

  
378
@time_recordings = ();
379
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
380
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
381

  
382
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no start, same end as other start' );
383

  
384
# ----s1--------------------
385
# ----s2-----e2-------------
386
# e1 undef
387
# -> overlaps
388
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
389
$e1 = undef;
390
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
391
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
392

  
393
clear_up;
394

  
395
@time_recordings = ();
396
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
397
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
398

  
399
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no end in db, same start' );
400

  
401
# --------s1----------------
402
# ----s2-----e2-------------
403
# e1 undef
404
# -> does not overlap
405
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
406
$e1 = undef;
407
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
408
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
409

  
410
clear_up;
411

  
412
@time_recordings = ();
413
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
414
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
415

  
416
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, enclosing' );
417

  
418
# ---s1---------------------
419
# ---------s2-----e2--------
420
# e1 undef
421
# -> does not overlap
422
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
423
$e1 = undef;
424
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
425
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
426

  
427
clear_up;
428

  
429
@time_recordings = ();
430
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
431
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
432

  
433
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, completely after' );
434

  
435
# ---------s1---------------
436
# --------------------------
437
# e1, s2, e2 undef
438
# -> does not overlap
439
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
440
$e1 = undef;
441
$s2 = undef;
442
$e2 = undef;
443

  
444
clear_up;
445

  
446
@time_recordings = ();
447
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
448
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
449

  
450
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no times in object' );
451

  
452
# ---------s1---------------
453
# -----s2-------------------
454
# e1, e2 undef
455
# -> does not overlap
456
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
457
$e1 = undef;
458
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
459
$e2 = undef;
460

  
461
clear_up;
462

  
463
@time_recordings = ();
464
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
465
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
466

  
467
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, start before, no end in object' );
468

  
469
# ---------s1---------------
470
# -------------s2-----------
471
# e1, e2 undef
472
# -> does not overlap
473
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
474
$e1 = undef;
475
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
476
$e2 = undef;
477

  
478
clear_up;
479

  
480
@time_recordings = ();
481
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
482
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
483

  
484
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, start after, no end in object' );
485

  
486
# ---------s1---------------
487
# ---------s2---------------
488
# e1, e2 undef
489
# -> overlaps
490
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
491
$e1 = undef;
492
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
493
$e2 = undef;
494

  
495
clear_up;
496

  
497
@time_recordings = ();
498
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
499
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
500

  
501
ok( $time_recordings[1]->is_time_overlapping, 'overlapping: no end in db, same start' );
502

  
503
# ---------s1---------------
504
# ---e2---------------------
505
# e1, s2 undef
506
# -> does not overlap
507
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
508
$e1 = undef;
509
$s2 = undef;
510
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
511

  
512
clear_up;
513

  
514
@time_recordings = ();
515
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
516
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
517

  
518
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, end before' );
519

  
520
# ---------s1---------------
521
# ---------------e2---------
522
# e1, s2 undef
523
# -> does not overlap
524
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
525
$e1 = undef;
526
$s2 = undef;
527
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
528

  
529
clear_up;
530

  
531
@time_recordings = ();
532
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
533
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
534

  
535
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, end after' );
536

  
537
# ---------s1---------------
538
# ---------e2---------------
539
# e1, s2 undef
540
# -> does not overlap
541
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
542
$e1 = undef;
543
$s2 = undef;
544
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 12, minute => 0);
545

  
546
clear_up;
547

  
548
@time_recordings = ();
549
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
550
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
551

  
552
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping: no end in db, no start in object, same end' );
553

  
554
########################################
555
# not overlapping if different staff_member
556
$s1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 10, minute => 0);
557
$e1 = DateTime->new(year => 2020, month => 11, day => 15, hour => 15, minute => 0);
558
$s2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 11, minute => 0);
559
$e2 = DateTime->new(year => 2020, month => 11, day => 15, hour => 14, minute => 0);
560

  
561
clear_up;
562

  
563
@time_recordings = ();
564
push @time_recordings, new_time_recording(start_time => $s1, end_time => $e1)->save;
565
push @time_recordings, new_time_recording(start_time => $s2, end_time => $e2);
566

  
567
ok( $time_recordings[1]->is_time_overlapping, 'overlapping if same staff member' );
568
$time_recordings[1]->update_attributes(staff_member => SL::DB::Employee->new(
569
                                         'login' => 'testuser',
570
                                         'name'  => 'Test User',
571
                                       )->save);
572
ok( !$time_recordings[1]->is_time_overlapping, 'not overlapping if different staff member' );
573

  
574
clear_up;
575

  
576
1;
577

  
578

  
579
# set emacs to perl mode
580
# Local Variables:
581
# mode: perl
582
# End:

Auch abrufbar als: Unified diff