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

(-)a/t/db_dependent/Koha/Patron/Message/Preferences.t (-48 / +21 lines)
Lines 51-59 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
51
51
52
    $schema->storage->txn_begin;
52
    $schema->storage->txn_begin;
53
53
54
    my $attribute = build_a_test_attribute();
54
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
55
    my $letter = build_a_test_letter();
55
    my $letter = build_a_test_letter();
56
    my $mtt = build_a_test_transport_type();
56
    my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
57
    Koha::Patron::Message::Transport->new({
57
    Koha::Patron::Message::Transport->new({
58
        message_attribute_id   => $attribute->message_attribute_id,
58
        message_attribute_id   => $attribute->message_attribute_id,
59
        message_transport_type => $mtt->message_transport_type,
59
        message_transport_type => $mtt->message_transport_type,
Lines 65-71 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
65
    subtest 'Test for a patron' => sub {
65
    subtest 'Test for a patron' => sub {
66
        plan tests => 3;
66
        plan tests => 3;
67
67
68
        my $patron = build_a_test_patron();
68
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
69
        Koha::Patron::Message::Preference->new({
69
        Koha::Patron::Message::Preference->new({
70
            borrowernumber       => $patron->borrowernumber,
70
            borrowernumber       => $patron->borrowernumber,
71
            message_attribute_id => $attribute->message_attribute_id,
71
            message_attribute_id => $attribute->message_attribute_id,
Lines 99-105 subtest 'Test Koha::Patron::Message::Preferences' => sub { Link Here
99
    };
99
    };
100
100
101
    subtest 'Test for a category' => sub {
101
    subtest 'Test for a category' => sub {
102
        my $category = build_a_test_category();
102
        my $category = $builder->build_object({ class => 'Koha::Patron::Categories' });
103
        Koha::Patron::Message::Preference->new({
103
        Koha::Patron::Message::Preference->new({
104
            categorycode         => $category->categorycode,
104
            categorycode         => $category->categorycode,
105
            message_attribute_id => $attribute->message_attribute_id,
105
            message_attribute_id => $attribute->message_attribute_id,
Lines 167-173 subtest 'Add preferences from defaults' => sub { Link Here
167
167
168
    $schema->storage->txn_begin;
168
    $schema->storage->txn_begin;
169
169
170
    my $patron = build_a_test_patron();
170
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
171
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
171
    my ($default, $mtt1, $mtt2) = build_a_test_category_preference({
172
        patron => $patron,
172
        patron => $patron,
173
    });
173
    });
Lines 198-204 subtest 'Test Koha::Patron::Message::Preference->message_transport_types' => sub Link Here
198
198
199
        $schema->storage->txn_begin;
199
        $schema->storage->txn_begin;
200
200
201
        my $patron = build_a_test_patron();
201
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
202
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
202
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
203
            patron => $patron
203
            patron => $patron
204
        });
204
        });
Lines 261-267 HERE Link Here
261
            my $transports = $pref->message_transport_types;
261
            my $transports = $pref->message_transport_types;
262
            is($appender, undef, 'Nothing in buffer yet');
262
            is($appender, undef, 'Nothing in buffer yet');
263
263
264
            my $mtt_new = build_a_test_transport_type();
264
            my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
265
            Koha::Patron::Message::Transport::Preference->new({
265
            Koha::Patron::Message::Transport::Preference->new({
266
                borrower_message_preference_id =>
266
                borrower_message_preference_id =>
267
                                $pref->borrower_message_preference_id,
267
                                $pref->borrower_message_preference_id,
Lines 286-292 HERE Link Here
286
286
287
        $schema->storage->txn_begin;
287
        $schema->storage->txn_begin;
288
288
289
        my $patron = build_a_test_patron();
289
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
290
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
290
        my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
291
            patron => $patron
291
            patron => $patron
292
        });
292
        });
Lines 386-395 HERE Link Here
386
386
387
        $schema->storage->txn_begin;
387
        $schema->storage->txn_begin;
388
388
389
        my $patron    = build_a_test_patron();
389
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
390
        my $letter    = build_a_test_letter();
390
        my $letter    = build_a_test_letter();
391
        my $attribute = build_a_test_attribute();
391
        my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
392
        my $mtt       = build_a_test_transport_type();
392
        my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
393
        Koha::Patron::Message::Transport->new({
393
        Koha::Patron::Message::Transport->new({
394
            message_attribute_id   => $attribute->message_attribute_id,
394
            message_attribute_id   => $attribute->message_attribute_id,
395
            message_transport_type => $mtt->message_transport_type,
395
            message_transport_type => $mtt->message_transport_type,
Lines 421-428 subtest 'Test Koha::Patron::Message::Preference->message_name' => sub { Link Here
421
421
422
    $schema->storage->txn_begin;
422
    $schema->storage->txn_begin;
423
423
424
    my $patron      = build_a_test_patron();
424
    my $patron      = $builder->build_object({ class => 'Koha::Patrons' });
425
    my $attribute   = build_a_test_attribute();
425
    my $attribute   = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
426
    my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
426
    my ($preference, $mtt1, $mtt2) = build_a_test_complete_preference({
427
        patron => $patron,
427
        patron => $patron,
428
        attr   => $attribute,
428
        attr   => $attribute,
Lines 453-459 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
453
453
454
        $schema->storage->txn_begin;
454
        $schema->storage->txn_begin;
455
455
456
        my $patron = build_a_test_patron();
456
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
457
        eval { Koha::Patron::Message::Preference->new({
457
        eval { Koha::Patron::Message::Preference->new({
458
            borrowernumber => $patron->borrowernumber,
458
            borrowernumber => $patron->borrowernumber,
459
            categorycode   => $patron->categorycode,
459
            categorycode   => $patron->categorycode,
Lines 489-495 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
489
            .' was the categorycode.');
489
            .' was the categorycode.');
490
490
491
        my $attribute = build_a_test_attribute({ takes_days => 0 });
491
        my $attribute = build_a_test_attribute({ takes_days => 0 });
492
        my $patron    = build_a_test_patron();
492
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
493
        eval { Koha::Patron::Message::Preference->new({
493
        eval { Koha::Patron::Message::Preference->new({
494
                borrowernumber => $patron->borrowernumber,
494
                borrowernumber => $patron->borrowernumber,
495
                message_attribute_id => $attribute->message_attribute_id,
495
                message_attribute_id => $attribute->message_attribute_id,
Lines 523-529 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
523
        is ($@->parameter, 'message_transport_types', 'The previous exception '
523
        is ($@->parameter, 'message_transport_types', 'The previous exception '
524
            .'tells us it was the message_transport_types.');
524
            .'tells us it was the message_transport_types.');
525
525
526
        my $mtt_new = build_a_test_transport_type();
526
        my $mtt_new = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
527
        eval {
527
        eval {
528
            Koha::Patron::Message::Preference->new({
528
            Koha::Patron::Message::Preference->new({
529
                borrowernumber => $patron->borrowernumber,
529
                borrowernumber => $patron->borrowernumber,
Lines 591-599 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
591
591
592
        $schema->storage->txn_begin;
592
        $schema->storage->txn_begin;
593
593
594
        my $attribute = build_a_test_attribute();
594
        my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
595
        my $letter = build_a_test_letter();
595
        my $letter = build_a_test_letter();
596
        my $mtt = build_a_test_transport_type();
596
        my $mtt = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
597
        Koha::Patron::Message::Transport->new({
597
        Koha::Patron::Message::Transport->new({
598
            message_attribute_id   => $attribute->message_attribute_id,
598
            message_attribute_id   => $attribute->message_attribute_id,
599
            message_transport_type => $mtt->message_transport_type,
599
            message_transport_type => $mtt->message_transport_type,
Lines 601-607 subtest 'Test adding a new preference with invalid parameters' => sub { Link Here
601
            letter_module          => $letter->module,
601
            letter_module          => $letter->module,
602
            letter_code            => $letter->code,
602
            letter_code            => $letter->code,
603
        })->store;
603
        })->store;
604
        my $patron    = build_a_test_patron();
604
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
605
        my $preference = Koha::Patron::Message::Preference->new({
605
        my $preference = Koha::Patron::Message::Preference->new({
606
            borrowernumber => $patron->borrowernumber,
606
            borrowernumber => $patron->borrowernumber,
607
            message_attribute_id => $attribute->message_attribute_id,
607
            message_attribute_id => $attribute->message_attribute_id,
Lines 640-652 sub build_a_test_attribute { Link Here
640
    );
640
    );
641
}
641
}
642
642
643
sub build_a_test_category {
644
    my $categorycode   = $builder->build({
645
        source => 'Category' })->{categorycode};
646
647
    return Koha::Patron::Categories->find($categorycode);
648
}
649
650
sub build_a_test_letter {
643
sub build_a_test_letter {
651
    my ($params) = @_;
644
    my ($params) = @_;
652
645
Lines 669-694 sub build_a_test_letter { Link Here
669
    });
662
    });
670
}
663
}
671
664
672
sub build_a_test_patron {
673
    my $categorycode   = $builder->build({
674
        source => 'Category' })->{categorycode};
675
    my $branchcode     = $builder->build({
676
        source => 'Branch' })->{branchcode};
677
    my $borrowernumber = $builder->build({
678
        source => 'Borrower' })->{borrowernumber};
679
680
    return Koha::Patrons->find($borrowernumber);
681
}
682
683
sub build_a_test_transport_type {
684
    my $mtt = $builder->build({
685
        source => 'MessageTransportType' });
686
687
    return Koha::Patron::Message::Transport::Types->find(
688
        $mtt->{message_transport_type}
689
    );
690
}
691
692
sub build_a_test_category_preference {
665
sub build_a_test_category_preference {
693
    my ($params) = @_;
666
    my ($params) = @_;
694
667
Lines 698-705 sub build_a_test_category_preference { Link Here
698
                    : build_a_test_attribute($params->{days_in_advance});
671
                    : build_a_test_attribute($params->{days_in_advance});
699
672
700
    my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
673
    my $letter = $params->{letter} ? $params->{letter} : build_a_test_letter();
701
    my $mtt1 = $params->{mtt1} ? $params->{mtt1} : build_a_test_transport_type();
674
    my $mtt1 = $params->{mtt1} ? $params->{mtt1} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
702
    my $mtt2 = $params->{mtt2} ? $params->{mtt2} : build_a_test_transport_type();
675
    my $mtt2 = $params->{mtt2} ? $params->{mtt2} : $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
703
676
704
    Koha::Patron::Message::Transport->new({
677
    Koha::Patron::Message::Transport->new({
705
        message_attribute_id   => $attr->message_attribute_id,
678
        message_attribute_id   => $attr->message_attribute_id,
(-)a/t/db_dependent/Koha/Patron/Message/Transport/Preferences.t (-47 / +4 lines)
Lines 47-54 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
47
47
48
    $schema->storage->txn_begin;
48
    $schema->storage->txn_begin;
49
49
50
    my $attribute = build_a_test_attribute();
50
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
51
    my $mtt       = build_a_test_transport_type();
51
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
52
    my $letter    = build_a_test_letter({
52
    my $letter    = build_a_test_letter({
53
        mtt => $mtt->message_transport_type
53
        mtt => $mtt->message_transport_type
54
    });
54
    });
Lines 61-67 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
61
    })->store;
61
    })->store;
62
62
63
    subtest 'For a patron' => sub {
63
    subtest 'For a patron' => sub {
64
        my $patron    = build_a_test_patron();
64
        my $patron    = $builder->build_object({ class => 'Koha::Patrons' });
65
        my $preference = Koha::Patron::Message::Preference->new({
65
        my $preference = Koha::Patron::Message::Preference->new({
66
            borrowernumber       => $patron->borrowernumber,
66
            borrowernumber       => $patron->borrowernumber,
67
            message_attribute_id => $attribute->message_attribute_id,
67
            message_attribute_id => $attribute->message_attribute_id,
Lines 85-91 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
85
    };
85
    };
86
86
87
    subtest 'For a category' => sub {
87
    subtest 'For a category' => sub {
88
        my $category   = build_a_test_category();
88
        my $category   = $builder->build_object({ class => 'Koha::Patron::Categories' });
89
        my $preference = Koha::Patron::Message::Preference->new({
89
        my $preference = Koha::Patron::Message::Preference->new({
90
            categorycode         => $category->categorycode,
90
            categorycode         => $category->categorycode,
91
            message_attribute_id => $attribute->message_attribute_id,
91
            message_attribute_id => $attribute->message_attribute_id,
Lines 111-139 subtest 'Test Koha::Patron::Message::Transport::Preferences' => sub { Link Here
111
    $schema->storage->txn_rollback;
111
    $schema->storage->txn_rollback;
112
};
112
};
113
113
114
sub build_a_test_attribute {
115
    my ($params) = @_;
116
117
    $params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
118
                            ? 1 : 0;
119
120
    my $attribute = $builder->build({
121
        source => 'MessageAttribute',
122
        value => $params,
123
    });
124
125
    return Koha::Patron::Message::Attributes->find(
126
        $attribute->{message_attribute_id}
127
    );
128
}
129
130
sub build_a_test_category {
131
    my $categorycode   = $builder->build({
132
        source => 'Category' })->{categorycode};
133
134
    return Koha::Patron::Categories->find($categorycode);
135
}
136
137
sub build_a_test_letter {
114
sub build_a_test_letter {
138
    my ($params) = @_;
115
    my ($params) = @_;
139
116
Lines 156-179 sub build_a_test_letter { Link Here
156
    });
133
    });
157
}
134
}
158
135
159
sub build_a_test_patron {
160
    my $categorycode   = $builder->build({
161
        source => 'Category' })->{categorycode};
162
    my $branchcode     = $builder->build({
163
        source => 'Branch' })->{branchcode};
164
    my $borrowernumber = $builder->build({
165
        source => 'Borrower' })->{borrowernumber};
166
167
    return Koha::Patrons->find($borrowernumber);
168
}
169
170
sub build_a_test_transport_type {
171
    my $mtt = $builder->build({
172
        source => 'MessageTransportType' });
173
174
    return Koha::Patron::Message::Transport::Types->find(
175
        $mtt->{message_transport_type}
176
    );
177
}
178
179
1;
136
1;
(-)a/t/db_dependent/Koha/Patron/Message/Transports.t (-28 / +2 lines)
Lines 42-49 subtest 'Test Koha::Patron::Message::Transports' => sub { Link Here
42
42
43
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
44
44
45
    my $attribute = build_a_test_attribute();
45
    my $attribute = $builder->build_object({ class => 'Koha::Patron::Message::Attributes' });
46
    my $mtt       = build_a_test_transport_type();
46
    my $mtt       = $builder->build_object({ class => 'Koha::Patron::Message::Transport::Types' });
47
    my $letter    = build_a_test_letter({
47
    my $letter    = build_a_test_letter({
48
        mtt => $mtt->message_transport_type
48
        mtt => $mtt->message_transport_type
49
    });
49
    });
Lines 69-90 subtest 'Test Koha::Patron::Message::Transports' => sub { Link Here
69
    $schema->storage->txn_rollback;
69
    $schema->storage->txn_rollback;
70
};
70
};
71
71
72
sub build_a_test_attribute {
73
    my ($params) = @_;
74
75
    $params->{takes_days} = $params->{takes_days} && $params->{takes_days} > 0
76
                            ? 1 : 0;
77
78
    my $attribute = $builder->build({
79
        source => 'MessageAttribute',
80
        value => $params,
81
    });
82
83
    return Koha::Patron::Message::Attributes->find(
84
        $attribute->{message_attribute_id}
85
    );
86
}
87
88
sub build_a_test_letter {
72
sub build_a_test_letter {
89
    my ($params) = @_;
73
    my ($params) = @_;
90
74
Lines 107-119 sub build_a_test_letter { Link Here
107
    });
91
    });
108
}
92
}
109
93
110
sub build_a_test_transport_type {
111
    my $mtt = $builder->build({
112
        source => 'MessageTransportType' });
113
114
    return Koha::Patron::Message::Transport::Types->find(
115
        $mtt->{message_transport_type}
116
    );
117
}
118
119
1;
94
1;
120
- 

Return to bug 17499