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

(-)a/t/db_dependent/Suggestions.t (-35 / +34 lines)
Lines 177-192 isnt( $my_suggestionid, 0, 'Suggestion is correctly saved' ); Link Here
177
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store;
177
my $my_suggestion_with_budget_object = Koha::Suggestion->new($my_suggestion_with_budget)->store;
178
my $my_suggestionid_with_budget      = $my_suggestion_with_budget_object->id;
178
my $my_suggestionid_with_budget      = $my_suggestion_with_budget_object->id;
179
179
180
my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
180
my $suggestion = Koha::Suggestions->find($my_suggestionid);
181
is( $suggestion->{title},         $my_suggestion->{title},         'Suggestion stores the title correctly' );
181
is( $suggestion->title,         $my_suggestion->{title},         'Suggestion stores the title correctly' );
182
is( $suggestion->{author},        $my_suggestion->{author},        'Suggestion stores the author correctly' );
182
is( $suggestion->author,        $my_suggestion->{author},        'Suggestion stores the author correctly' );
183
is( $suggestion->{publishercode}, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' );
183
is( $suggestion->publishercode, $my_suggestion->{publishercode}, 'Suggestion stores the publishercode correctly' );
184
is( $suggestion->{suggestedby},   $my_suggestion->{suggestedby},   'Suggestion stores the borrower number correctly' );
184
is( $suggestion->suggestedby,   $my_suggestion->{suggestedby},   'Suggestion stores the borrower number correctly' );
185
is( $suggestion->{biblionumber},  $my_suggestion->{biblionumber},  'Suggestion stores the biblio number correctly' );
185
is( $suggestion->biblionumber,  $my_suggestion->{biblionumber},  'Suggestion stores the biblio number correctly' );
186
is( $suggestion->{STATUS},        'ASKED', 'Suggestion stores a suggestion with the status ASKED by default' );
186
is( $suggestion->STATUS,    'ASKED', 'Suggestion stores a suggestion with the status ASKED by default' );
187
is( $suggestion->{managedby}, undef, 'Suggestion stores empty string as undef for non existent foreign key (integer)' );
187
is( $suggestion->managedby, undef,   'Suggestion stores empty string as undef for non existent foreign key (integer)' );
188
is( $suggestion->{manageddate}, undef, 'Suggestion stores empty string as undef for date' );
188
is( $suggestion->manageddate, undef, 'Suggestion stores empty string as undef for date' );
189
is( $suggestion->{budgetid},    undef, 'Suggestion should set budgetid to NULL if not given' );
189
is( $suggestion->budgetid,    undef, 'Suggestion should set budgetid to NULL if not given' );
190
190
191
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
191
is( ModSuggestion(), undef, 'ModSuggestion without the suggestion returns undef' );
192
my $mod_suggestion1 = {
192
my $mod_suggestion1 = {
Lines 202-221 is( $status, undef, 'ModSuggestion without the suggestion id returns undef' ); Link Here
202
$mod_suggestion1->{suggestionid} = $my_suggestionid;
202
$mod_suggestion1->{suggestionid} = $my_suggestionid;
203
$status = ModSuggestion($mod_suggestion1);
203
$status = ModSuggestion($mod_suggestion1);
204
is( $status, 1, 'ModSuggestion modifies one entry' );
204
is( $status, 1, 'ModSuggestion modifies one entry' );
205
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
205
$suggestion = Koha::Suggestions->find($my_suggestionid);
206
is( $suggestion->{title},  $mod_suggestion1->{title},  'ModSuggestion modifies the title  correctly' );
206
is( $suggestion->title,  $mod_suggestion1->{title},  'ModSuggestion modifies the title  correctly' );
207
is( $suggestion->{author}, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
207
is( $suggestion->author, $mod_suggestion1->{author}, 'ModSuggestion modifies the author correctly' );
208
is(
208
is(
209
    $suggestion->{publishercode}, $mod_suggestion1->{publishercode},
209
    $suggestion->publishercode, $mod_suggestion1->{publishercode},
210
    'ModSuggestion modifies the publishercode correctly'
210
    'ModSuggestion modifies the publishercode correctly'
211
);
211
);
212
is(
212
is(
213
    $suggestion->{managedby}, undef,
213
    $suggestion->managedby, undef,
214
    'ModSuggestion stores empty string as undef for non existent foreign key (integer)'
214
    'ModSuggestion stores empty string as undef for non existent foreign key (integer)'
215
);
215
);
216
is( $suggestion->{manageddate}, undef, 'ModSuggestion stores empty string as undef for date' );
216
is( $suggestion->manageddate, undef, 'ModSuggestion stores empty string as undef for date' );
217
isnt( $suggestion->{accepteddate}, undef, 'ModSuggestion does not update a non given date value' );
217
isnt( $suggestion->accepteddate, undef, 'ModSuggestion does not update a non given date value' );
218
is( $suggestion->{note}, 'my note', 'ModSuggestion should not erase data if not given' );
218
is( $suggestion->note, 'my note', 'ModSuggestion should not erase data if not given' );
219
219
220
my $messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
220
my $messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
221
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
221
is( @$messages, 0, 'ModSuggestions does not send an email if the status is not updated' );
Lines 246-253 my $mod_suggestion3 = { Link Here
246
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 );
246
t::lib::Mocks::mock_preference( 'FallbackToSMSIfNoEmail', 0 );
247
$status = ModSuggestion($mod_suggestion3);
247
$status = ModSuggestion($mod_suggestion3);
248
is( $status, 1, 'ModSuggestion modifies one entry' );
248
is( $status, 1, 'ModSuggestion modifies one entry' );
249
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
249
$suggestion = Koha::Suggestions->find($my_suggestionid);
250
is( $suggestion->{STATUS}, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
250
is( $suggestion->STATUS, $mod_suggestion3->{STATUS}, 'ModSuggestion modifies the status correctly' );
251
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
251
$messages = C4::Letters::GetQueuedMessages( { borrowernumber => $borrowernumber } );
252
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
252
is( @$messages, 1, 'ModSuggestion sends an email if the status is updated' );
253
is(
253
is(
Lines 437-445 is( ConnectSuggestionAndBiblio(), '0E0', 'ConnectSuggestionAndBiblio without arg Link Here
437
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
437
my $biblio_2                      = $builder->build_object( { class => 'Koha::Biblios' } );
438
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
438
my $connect_suggestion_and_biblio = ConnectSuggestionAndBiblio( $my_suggestionid, $biblio_2->biblionumber );
439
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
439
is( $connect_suggestion_and_biblio, '1', 'ConnectSuggestionAndBiblio returns 1' );
440
$suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
440
$suggestion = Koha::Suggestions->find($my_suggestionid);
441
is(
441
is(
442
    $suggestion->{biblionumber}, $biblio_2->biblionumber,
442
    $suggestion->biblionumber, $biblio_2->biblionumber,
443
    'ConnectSuggestionAndBiblio updates the biblio number correctly'
443
    'ConnectSuggestionAndBiblio updates the biblio number correctly'
444
);
444
);
445
445
Lines 468-480 is( $suggestions->[1]->{title}, $del_suggestion->{title}, 'DelSuggestion deletes Link Here
468
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
468
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
469
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
469
my $my_suggestionid_test_budget_object = Koha::Suggestion->new($my_suggestion)->store;
470
my $my_suggestionid_test_budgetid      = $my_suggestionid_test_budget_object->id;
470
my $my_suggestionid_test_budgetid      = $my_suggestionid_test_budget_object->id;
471
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed();
471
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid);
472
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
472
is( $suggestion->budgetid, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
473
473
474
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
474
$my_suggestion->{budgetid} = '';    # If budgetid == '', NULL should be set in DB
475
ModSuggestion($my_suggestion);
475
ModSuggestion($my_suggestion);
476
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid)->unblessed();
476
$suggestion = Koha::Suggestions->find($my_suggestionid_test_budgetid);
477
is( $suggestion->{budgetid}, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
477
is( $suggestion->budgetid, undef, 'Suggestion Should set budgetid to NULL if equals an empty string' );
478
478
479
my $suggestion2 = {
479
my $suggestion2 = {
480
    title    => "Cuisine d'automne",
480
    title    => "Cuisine d'automne",
Lines 510-520 subtest 'GetUnprocessedSuggestions' => sub { Link Here
510
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
510
        'GetUnprocessedSuggestions should return 0 if a suggestion has been processed but not linked to a fund'
511
    );
511
    );
512
    my $status     = ModSuggestion($mod_suggestion1);
512
    my $status     = ModSuggestion($mod_suggestion1);
513
    my $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
513
    my $suggestion = Koha::Suggestions->find($my_suggestionid);
514
    is( $suggestion->{budgetid}, undef, 'ModSuggestion should set budgetid to NULL if not given' );
514
    is( $suggestion->budgetid, undef, 'ModSuggestion should set budgetid to NULL if not given' );
515
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
515
    ModSuggestion( { suggestionid => $my_suggestionid, budgetid => $budget_id } );
516
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
516
    $suggestion = Koha::Suggestions->find($my_suggestionid);
517
    is( $suggestion->{budgetid}, $budget_id, 'ModSuggestion should modify budgetid if given' );
517
    is( $suggestion->budgetid, $budget_id, 'ModSuggestion should modify budgetid if given' );
518
518
519
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
519
    $unprocessed_suggestions = C4::Suggestions::GetUnprocessedSuggestions;
520
    is(
520
    is(
Lines 733-740 subtest 'ModSuggestion should work on suggestions without a suggester' => sub { Link Here
733
733
734
    $dbh->do(q|DELETE FROM suggestions|);
734
    $dbh->do(q|DELETE FROM suggestions|);
735
    my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id;
735
    my $my_suggestionid = Koha::Suggestion->new($my_suggestion_without_suggestedby)->store()->id;
736
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
736
    $suggestion = Koha::Suggestions->find($my_suggestionid);
737
    is( $suggestion->{suggestedby}, undef, "Suggestedby is undef" );
737
    is( $suggestion->suggestedby, undef, "Suggestedby is undef" );
738
738
739
    ModSuggestion(
739
    ModSuggestion(
740
        {
740
        {
Lines 743-751 subtest 'ModSuggestion should work on suggestions without a suggester' => sub { Link Here
743
            note         => "Test note"
743
            note         => "Test note"
744
        }
744
        }
745
    );
745
    );
746
    $suggestion = Koha::Suggestions->find($my_suggestionid)->unblessed();
746
    $suggestion = Koha::Suggestions->find($my_suggestionid);
747
747
748
    is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" );
748
    is( $suggestion->note, "Test note", "ModSuggestion works on suggestions without a suggester" );
749
};
749
};
750
750
751
subtest 'place_hold tests' => sub {
751
subtest 'place_hold tests' => sub {
752
- 

Return to bug 39721