View | Details | Raw Unified | Return to bug 27333
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Club/Hold.t (-23 / +73 lines)
Lines 36-42 my $builder = t::lib::TestBuilder->new; Link Here
36
my $schema = Koha::Database->new->schema;
36
my $schema = Koha::Database->new->schema;
37
37
38
subtest 'add' => sub {
38
subtest 'add' => sub {
39
    plan tests => 5;
39
40
    plan tests => 9;
40
41
41
    $schema->storage->txn_begin;
42
    $schema->storage->txn_begin;
42
43
Lines 45-76 subtest 'add' => sub { Link Here
45
    my $item1 = $builder->build_sample_item({ library => $library->branchcode });
46
    my $item1 = $builder->build_sample_item({ library => $library->branchcode });
46
    my $item2 = $builder->build_sample_item({ library => $library->branchcode });
47
    my $item2 = $builder->build_sample_item({ library => $library->branchcode });
47
48
48
    try {
49
    throws_ok {
49
        Koha::Club::Hold::add({ club_id => $club->id, biblio_id => $item1->biblionumber, pickup_library_id => $library->branchcode });
50
        Koha::Club::Hold::add(
50
    } catch {
51
            {
51
        my $class = ref $_;
52
                club_id => $club->id
52
        ok($class eq 'Koha::Exceptions::ClubHold::NoPatrons', 'Exception thrown when no patron is enrolled in club');
53
            }
53
    };
54
        );
54
55
    }
55
    my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { branchcode => $library->branchcode } });
56
    'Koha::Exceptions::MissingParameter',
56
    my $e = $builder->build_object({ class => 'Koha::Club::Enrollments' , value => { club_id => $club->id, borrowernumber => $patron->borrowernumber, date_canceled => undef }} );
57
      'Exception thrown when biblio_id is passed';
57
58
58
    my $club_hold = Koha::Club::Hold::add({
59
    is( "$@", 'The biblio_id parameter is mandatory' );
59
        club_id => $club->id,
60
60
        biblio_id => $item1->biblionumber,
61
    throws_ok {
61
        pickup_library_id => $library->branchcode
62
        Koha::Club::Hold::add(
62
    });
63
            {
64
                biblio_id => $item1->biblionumber
65
            }
66
        );
67
    }
68
    'Koha::Exceptions::MissingParameter',
69
      'Exception thrown when club_id is passed';
70
71
    is( "$@", 'The club_id parameter is mandatory' );
72
73
    throws_ok {
74
        Koha::Club::Hold::add(
75
            {
76
                club_id           => $club->id,
77
                biblio_id         => $item1->biblionumber,
78
                pickup_library_id => $library->branchcode
79
            }
80
        );
81
    }
82
    'Koha::Exceptions::ClubHold::NoPatrons',
83
      'Exception thrown when no patron is enrolled in club';
84
85
    my $patron = $builder->build_object(
86
        {
87
            class => 'Koha::Patrons',
88
            value => { branchcode => $library->branchcode }
89
        }
90
    );
91
    my $e = $builder->build_object(
92
        {
93
            class => 'Koha::Club::Enrollments',
94
            value => {
95
                club_id        => $club->id,
96
                borrowernumber => $patron->borrowernumber,
97
                date_canceled  => undef
98
            }
99
        }
100
    );
101
102
    my $club_hold = Koha::Club::Hold::add(
103
        {
104
            club_id           => $club->id,
105
            biblio_id         => $item1->biblionumber,
106
            pickup_library_id => $library->branchcode
107
        }
108
    );
63
109
64
    is(blessed($club_hold), 'Koha::Club::Hold', 'add returns a Koha::Club::Hold');
110
    is(blessed($club_hold), 'Koha::Club::Hold', 'add returns a Koha::Club::Hold');
65
111
66
    $e->date_canceled(dt_from_string)->store;
112
    $e->date_canceled(dt_from_string)->store;
67
113
68
    try {
114
    throws_ok {
69
        Koha::Club::Hold::add({ club_id => $club->id, biblio_id => $item2->biblionumber, pickup_library_id => $library->branchcode });
115
        Koha::Club::Hold::add(
70
    } catch {
116
            {
71
        my $class = ref $_;
117
                club_id           => $club->id,
72
        ok($class eq 'Koha::Exceptions::ClubHold::NoPatrons', 'Exception thrown when no patron is enrolled in club');
118
                biblio_id         => $item2->biblionumber,
73
    };
119
                pickup_library_id => $library->branchcode
120
            }
121
        );
122
    }
123
    'Koha::Exceptions::ClubHold::NoPatrons',
124
      'Exception thrown when no patron is enrolled in club';
74
125
75
    my $patron_holds = Koha::Club::Hold::PatronHolds->search({ club_hold_id => $club_hold->id });
126
    my $patron_holds = Koha::Club::Hold::PatronHolds->search({ club_hold_id => $club_hold->id });
76
127
77
- 

Return to bug 27333