File: 12.verson1.t

package info (click to toggle)
libdata-ical-perl 0.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 396 kB
  • ctags: 254
  • sloc: perl: 3,464; sh: 51; makefile: 2
file content (84 lines) | stat: -rw-r--r-- 2,366 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/perl -w

use warnings;
use strict;

use constant TESTS_IN_TEST_CALENDAR => 6;
use Test::More tests => 10 + 3 * TESTS_IN_TEST_CALENDAR;
use Test::LongString;
use Test::Warn;

BEGIN { use_ok('Data::ICal') }

my $cal;

warnings_are { $cal = Data::ICal->new(filename => 't/ics/version1.ics') }
    [ {carped => "Unknown property for Data::ICal::Entry::Event: dcreated"},
    {carped => "Unknown property for Data::ICal::Entry::Event: malarm"} ],
    "Got a warning for fake property set";
ok((not $cal), "rejected calendar with version property value 1.0");

warnings_are { $cal = Data::ICal->new(filename => 't/ics/test.ics', vcal10 => 1) }
    [ {carped => "Unknown property for Data::ICal::Entry::Event: duration"} ],
    "Got a warning for fake property set";
ok((not $cal), "rejected calendar with version property value 2.0");

require Test::NoWarnings;

$cal = Data::ICal->new(filename => 't/ics/version1.ics', vcal10 => 1);

isa_ok($cal, 'Data::ICal');

test_calendar($cal);

my $data = $cal->as_string;
like($data, qr/^BEGIN:VCALENDAR/, "looks like a calendar");

my $roundtripped_from_data_cal = Data::ICal->new(data => $data, vcal10 => 1);
isa_ok($roundtripped_from_data_cal, 'Data::ICal');

test_calendar($roundtripped_from_data_cal);

SKIP: {
    my $CAL_FILENAME = "t/ics/out.ics";
    skip "Can't create $CAL_FILENAME: $!", 1 + TESTS_IN_TEST_CALENDAR unless open my $fh,'>', $CAL_FILENAME;
    print $fh $cal->as_string;
    close $fh;

    my $roundtripped_cal = Data::ICal->new(filename => $CAL_FILENAME, vcal10 => 1);
    isa_ok($roundtripped_cal, 'Data::ICal');

    test_calendar($roundtripped_cal);

    unlink $CAL_FILENAME;
}

Test::NoWarnings::had_no_warnings();

sub test_calendar {
    my $s = shift;
    is($s->ical_entry_type, 'VCALENDAR', "Is a VCALENDAR");
    my $id = $s->property('prodid')->[0]->value;
    is($id,'-//Mirapoint Calendar', 'Got id');

    my @entries = @{$s->entries};
    is(@entries,1,"Correct number of entries");

    my $event;

    for (@entries) {
        if ( $_->ical_entry_type eq 'VEVENT' ) {
            $event = $_;
        }
    }
    undef(@entries);

    # Event
    isa_ok($event, 'Data::ICal::Entry::Event');
    is($event->property('summary')->[0]->value, 'cal1');

    # check sub entries
    @entries = @{$event->entries};
    is(@entries, 0, "Got no sub entries");
    undef(@entries);
}