Bug 13012: Add more tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 10 Aug 2017 18:52:35 +0000 (15:52 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 10 Aug 2017 19:25:34 +0000 (16:25 -0300)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/Koha/Suggestions.t

index 0a2af42..732ac68 100644 (file)
@@ -47,7 +47,25 @@ my $new_suggestion_2 = Koha::Suggestion->new(
     }
 )->store;
 
-is( $new_suggestion_1->suggesteddate, dt_from_string()->ymd, "If suggesteddate not passed in, it will default to today" );
+subtest 'store' => sub {
+    plan tests => 3;
+    my $suggestion  = Koha::Suggestion->new(
+        {   suggestedby  => $patron->{borrowernumber},
+            biblionumber => $biblio_1->{biblionumber},
+        }
+    )->store;
+
+    is( $suggestion->suggesteddate, dt_from_string()->ymd, "If suggesteddate not passed in, it will default to today" );
+    my $two_days_ago = dt_from_string->subtract( days => 2 );
+    my $two_days_ago_sql = output_pref({dt => $two_days_ago, dateformat => 'sql', dateonly => 1 });
+    $suggestion->suggesteddate($two_days_ago)->store;
+    $suggestion = Koha::Suggestions->find( $suggestion->suggestionid );
+    is( $suggestion->suggesteddate, $two_days_ago_sql, 'If suggesteddate passed in, it should be taken into account' );
+    $suggestion->reason('because!')->store;
+    $suggestion = Koha::Suggestions->find( $suggestion->suggestionid );
+    is( $suggestion->suggesteddate, $two_days_ago_sql, 'If suggestion id modified, suggesteddate should not be modified' );
+    $suggestion->delete;
+};
 
 like( $new_suggestion_1->suggestionid, qr|^\d+$|, 'Adding a new suggestion should have set the suggestionid' );
 is( Koha::Suggestions->search->count, $nb_of_suggestions + 2, 'The 2 suggestions should have been added' );