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

(-)a/t/db_dependent/Koha/Ticket.t (-2 / +83 lines)
Lines 19-26 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 5;
22
use Test::More tests => 6;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
25
25
use Koha::Database;
26
use Koha::Database;
26
27
Lines 145-147 subtest 'add_update() tests' => sub { Link Here
145
146
146
    $schema->storage->txn_rollback;
147
    $schema->storage->txn_rollback;
147
};
148
};
148
- 
149
150
subtest 'store() tests' => sub {
151
    plan tests => 2;
152
153
    subtest 'acknowledgement notice trigger' => sub {
154
        plan tests => 4;
155
156
        $schema->storage->txn_begin;
157
158
        my $patron = $builder->build_object( { class => "Koha::Patrons" } );
159
        my $biblio = $builder->build_sample_biblio();
160
161
        my $new_ticket = Koha::Ticket->new(
162
            {
163
                reporter_id => $patron->id,
164
                title       => "Testing ticket",
165
                body        => "Testing ticket message",
166
                biblio_id   => $biblio->id
167
            }
168
        )->store();
169
170
        is( ref($new_ticket), 'Koha::Ticket',
171
            'Koha::Ticket->store() returned the Koha::Ticket object' );
172
        my $notices =
173
          Koha::Notice::Messages->search( { borrowernumber => $patron->id } );
174
        is( $notices->count, 1,
175
            'One acknowledgement notice queued for the ticket reporter' );
176
        my $THE_notice = $notices->next;
177
        isnt( $THE_notice->status, 'pending',
178
            'Acknowledgement notice is sent immediately' );
179
180
        $new_ticket->set( { title => "Changed title" } )->store();
181
        $notices =
182
          Koha::Notice::Messages->search( { borrowernumber => $patron->id } );
183
        is( $notices->count, 1,
184
            'Further acknowledgement notices are not queud on subsequent stores'
185
        );
186
187
        $schema->storage->txn_rollback;
188
    };
189
190
    subtest 'cataloger notice trigger' => sub {
191
        plan tests => 4;
192
193
        $schema->storage->txn_begin;
194
195
        my $catemail = 'catalogers@testmail.com';
196
        t::lib::Mocks::mock_preference( 'CatalogerEmails', $catemail );
197
198
        my $patron = $builder->build_object( { class => "Koha::Patrons" } );
199
        my $biblio = $builder->build_sample_biblio();
200
201
        my $new_ticket = Koha::Ticket->new(
202
            {
203
                reporter_id => $patron->id,
204
                title       => "Testing ticket",
205
                body        => "Testing ticket message",
206
                biblio_id   => $biblio->id
207
            }
208
        )->store();
209
210
        is( ref($new_ticket), 'Koha::Ticket',
211
            'Koha::Ticket->store() returned the Koha::Ticket object' );
212
        my $notices =
213
          Koha::Notice::Messages->search( { to_address => $catemail } );
214
        is( $notices->count, 1,
215
            'One notification notice queued for the catalogers when ticket reported' );
216
        my $THE_notice = $notices->next;
217
        isnt( $THE_notice->status, 'pending',
218
            'Notification notice is sent immediately' );
219
220
        $new_ticket->set( { title => "Changed title" } )->store();
221
        $notices =
222
          Koha::Notice::Messages->search( { to_address => $catemail } );
223
        is( $notices->count, 1,
224
            'Further notification notices are not queud on subsequent stores'
225
        );
226
227
        $schema->storage->txn_rollback;
228
    };
229
};

Return to bug 31028