Bug 18477: Add tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 2 Jan 2018 17:36:43 +0000 (14:36 -0300)
committerFridolin Somers <fridolin.somers@biblibre.com>
Thu, 8 Feb 2018 09:48:26 +0000 (10:48 +0100)
Signed-off-by: Mark Tompsett <mtompset@hotmail.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
(cherry picked from commit 2a0423778e73467beeb57379db49b49b811894aa)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

t/db_dependent/ArticleRequests.t

index a9466a6..c0ae2c9 100755 (executable)
@@ -19,12 +19,13 @@ use Modern::Perl;
 
 use POSIX qw(strftime);
 
-use Test::More tests => 49;
+use Test::More tests => 54;
 
 use t::lib::TestBuilder;
 
 use Koha::Database;
 use Koha::Biblio;
+use Koha::Notice::Messages;
 use Koha::Patron;
 use Koha::Library;
 
@@ -73,21 +74,41 @@ my $patron   = Koha::Patron->new(
 )->store();
 ok( $patron->id, 'Koha::Patron created' );
 
+# store
+Koha::Notice::Messages->delete;
+my $article_request_title = 'an article request title';
 my $article_request = Koha::ArticleRequest->new(
     {
         borrowernumber => $patron->id,
         biblionumber   => $biblio->id,
         itemnumber     => $item->id,
+        title          => $article_request_title,
     }
 )->store();
+
+my $notify_message = Koha::Notice::Messages->search->next;
+is( $notify_message->letter_code, "AR_".Koha::ArticleRequest::Status::Pending);
+# Default AR_PROCESSING template content "Title: <<article_requests.title>>"
+like( $notify_message->content, qr{Title: $article_request_title}, 'Values from article_requests table must be fetched for the notification' );
+
 $article_request = Koha::ArticleRequests->find( $article_request->id );
 ok( $article_request->id, 'Koha::ArticleRequest created' );
-
 is( $article_request->status, Koha::ArticleRequest::Status::Pending, 'New article request has status of Open' );
+is( $article_request->updated_on, undef, 'New article request has not an updated_on date set yet' );
+
+# process
+Koha::Notice::Messages->delete;
 $article_request->process();
+$notify_message = Koha::Notice::Messages->search->next;
+is( $notify_message->letter_code, "AR_".Koha::ArticleRequest::Status::Processing);
 is( $article_request->status, Koha::ArticleRequest::Status::Processing, '$ar->process() changes status to Processing' );
+isnt( $article_request->updated_on, undef, 'Updated article request has an updated_on date set' );
+
+# complete
 $article_request->complete();
 is( $article_request->status, Koha::ArticleRequest::Status::Completed, '$ar->complete() changes status to Completed' );
+
+# cancel
 $article_request->cancel();
 is( $article_request->status, Koha::ArticleRequest::Status::Canceled, '$ar->complete() changes status to Canceled' );
 $article_request->status(Koha::ArticleRequest::Status::Pending);