Bug 13853: (QA followup) Add unit tests for branch getting methods
authorKyle M Hall <kyle@bywatersolutions.com>
Thu, 25 Jun 2015 18:56:18 +0000 (14:56 -0400)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Tue, 11 Aug 2015 17:48:45 +0000 (14:48 -0300)
Signed-off-by: Jonathan Druart <jonathan.druart@koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
t/db_dependent/Items.t

index b78e131..c644492 100755 (executable)
@@ -23,10 +23,11 @@ use C4::Biblio;
 use C4::Branch;
 use Koha::Database;
 
-use Test::More tests => 6;
+use Test::More tests => 8;
 
 BEGIN {
     use_ok('C4::Items');
+    use_ok('Koha::Items');
 }
 
 my $dbh = C4::Context->dbh;
@@ -389,6 +390,33 @@ subtest 'SearchItems test' => sub {
     $dbh->rollback;
 };
 
+subtest 'Koha::Item(s) tests' => sub {
+
+    plan tests => 5;
+
+    # Start transaction
+    my $schema = Koha::Database->new()->schema();
+    $schema->storage->txn_begin();
+    $dbh->{RaiseError} = 1;
+
+    # Create a biblio and item for testing
+    C4::Context->set_preference('marcflavour', 'MARC21');
+    my ($bibnum, $bibitemnum) = get_biblio();
+    my ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch1, holdingbranch => $branch2 } , $bibnum);
+
+    # Get item.
+    my $item = Koha::Items->find( $itemnumber );
+    ok( $item, "Got Koha::Item" );
+
+    my $homebranch = $item->home_branch();
+    ok( $homebranch, "Got Koha::Branch from home_branch method" );
+    is( $homebranch->branchcode(), $branch1, "Home branch code matches homebranch" );
+
+    my $holdingbranch = $item->holding_branch();
+    ok( $holdingbranch, "Got Koha::Branch from holding_branch method" );
+    is( $holdingbranch->branchcode(), $branch2, "Home branch code matches holdingbranch" );
+};
+
 # Helper method to set up a Biblio.
 sub get_biblio {
     my $bib = MARC::Record->new();