Bug 15629: Koha::Libraries - Remove ModBranch
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 20 Jan 2016 13:13:14 +0000 (13:13 +0000)
committerBrendan Gallagher <brendan@bywatersolutions.com>
Wed, 24 Feb 2016 03:55:06 +0000 (03:55 +0000)
This subroutine was only used in tests to add/update a library.

Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
20 files changed:
C4/Branch.pm
t/db_dependent/Branch.t
t/db_dependent/Circulation/CheckIfIssuedToPatron.t
t/db_dependent/Circulation/CheckValidBarcode.t
t/db_dependent/Circulation/GetIssues.t
t/db_dependent/Circulation/MarkIssueReturned.t
t/db_dependent/Circulation_Branch.t
t/db_dependent/Circulation_Issuingrule.t
t/db_dependent/Circulation_OfflineOperation.t
t/db_dependent/Circulation_issue.t
t/db_dependent/Items.t
t/db_dependent/Members/GetAllIssues.t
t/db_dependent/Members/GetOverdues.t
t/db_dependent/Members/GetPendingIssues.t
t/db_dependent/Members/IssueSlip.t
t/db_dependent/RotatingCollections.t
t/db_dependent/Suggestions.t
t/db_dependent/Template/Plugin/Branches.t
t/db_dependent/Utils/Datatables_Members.t
t/db_dependent/Utils/Datatables_Virtualshelves.t

index 465a0e4..b8eb9ca 100644 (file)
@@ -33,7 +33,6 @@ BEGIN {
                &GetBranch
                &GetBranches
                &GetBranchesLoop
-               &ModBranch
                &GetBranchInfo
                &mybranch
        );
@@ -171,112 +170,6 @@ sub GetBranchName {
     return ($branchname);
 }
 
-=head2 ModBranch
-
-$error = &ModBranch($newvalue);
-
-This function modifies an existing branch
-
-C<$newvalue> is a ref to an array which contains all the columns from branches table.
-
-=cut
-
-sub ModBranch {
-    my ($data) = @_;
-    
-    my $dbh    = C4::Context->dbh;
-    if ($data->{add}) {
-        my $query  = "
-            INSERT INTO branches
-            (branchcode,branchname,branchaddress1,
-            branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
-            branchcountry,branchphone,branchfax,branchemail,
-            branchurl,branchip,branchprinter,branchnotes,opac_info,
-            branchreplyto, branchreturnpath)
-            VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
-        ";
-        my $sth    = $dbh->prepare($query);
-        $sth->execute(
-            $data->{'branchcode'},       $data->{'branchname'},
-            $data->{'branchaddress1'},   $data->{'branchaddress2'},
-            $data->{'branchaddress3'},   $data->{'branchzip'},
-            $data->{'branchcity'},       $data->{'branchstate'},
-            $data->{'branchcountry'},
-            $data->{'branchphone'},      $data->{'branchfax'},
-            $data->{'branchemail'},      $data->{'branchurl'},
-            $data->{'branchip'},         $data->{'branchprinter'},
-            $data->{'branchnotes'},      $data->{opac_info},
-            $data->{'branchreplyto'},    $data->{'branchreturnpath'}
-        );
-        return 1 if $dbh->err;
-    } else {
-        my $query  = "
-            UPDATE branches
-            SET branchname=?,branchaddress1=?,
-                branchaddress2=?,branchaddress3=?,branchzip=?,
-                branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
-                branchfax=?,branchemail=?,branchurl=?,branchip=?,
-                branchprinter=?,branchnotes=?,opac_info=?,
-                branchreplyto=?, branchreturnpath=?
-            WHERE branchcode=?
-        ";
-        my $sth    = $dbh->prepare($query);
-        $sth->execute(
-            $data->{'branchname'},
-            $data->{'branchaddress1'},   $data->{'branchaddress2'},
-            $data->{'branchaddress3'},   $data->{'branchzip'},
-            $data->{'branchcity'},       $data->{'branchstate'},       
-            $data->{'branchcountry'},
-            $data->{'branchphone'},      $data->{'branchfax'},
-            $data->{'branchemail'},      $data->{'branchurl'},
-            $data->{'branchip'},         $data->{'branchprinter'},
-            $data->{'branchnotes'},      $data->{opac_info},
-            $data->{'branchreplyto'},    $data->{'branchreturnpath'},
-            $data->{'branchcode'},
-        );
-    }
-    # sort out the categories....
-    my @checkedcats;
-    my @cats = Koha::LibraryCategories->search;
-    foreach my $cat (@cats) {
-        my $code = $cat->categorycode;
-        if ( $data->{$code} ) {
-            push( @checkedcats, $code );
-        }
-    }
-    my $branchcode = uc( $data->{'branchcode'} );
-    my $branch     = GetBranchInfo($branchcode);
-    $branch = $branch->[0];
-    my $branchcats = $branch->{'categories'};
-    my @addcats;
-    my @removecats;
-    foreach my $bcat (@$branchcats) {
-
-        unless ( grep { /^$bcat$/ } @checkedcats ) {
-            push( @removecats, $bcat );
-        }
-    }
-    foreach my $ccat (@checkedcats) {
-        unless ( grep { /^$ccat$/ } @$branchcats ) {
-            push( @addcats, $ccat );
-        }
-    }
-    foreach my $cat (@addcats) {
-        my $sth =
-          $dbh->prepare(
-"insert into branchrelations (branchcode, categorycode) values(?, ?)"
-          );
-        $sth->execute( $branchcode, $cat );
-    }
-    foreach my $cat (@removecats) {
-        my $sth =
-          $dbh->prepare(
-            "delete from branchrelations where branchcode=? and categorycode=?"
-          );
-        $sth->execute( $branchcode, $cat );
-    }
-}
-
 =head2 GetBranch
 
 $branch = GetBranch( $query, $branches );
index 73e7ec7..c715e98 100644 (file)
@@ -21,9 +21,11 @@ use Modern::Perl;
 use C4::Context;
 use Data::Dumper;
 
-use Test::More tests => 19;
+use Test::More tests => 17;
 
 use C4::Branch;
+use Koha::Database;
+use Koha::Library;
 use Koha::Libraries;
 use Koha::LibraryCategories;
 
@@ -38,17 +40,15 @@ can_ok(
       GetBranch
       GetBranches
       GetBranchesLoop
-      ModBranch
       GetBranchInfo
       mybranch
       )
 );
 
+my $schema = Koha::Database->new->schema;
+$schema->storage->txn_begin;
 
-# Start transaction
 my $dbh = C4::Context->dbh;
-$dbh->{AutoCommit} = 0;
-$dbh->{RaiseError} = 1;
 
 # clear the slate
 $dbh->do('DELETE FROM branchcategories');
@@ -60,7 +60,6 @@ like( $count, '/^\d+$/', "the count is a number" );
 
 #add 2 branches
 my $b1 = {
-    add            => 1,
     branchcode     => 'BRA',
     branchname     => 'BranchA',
     branchaddress1 => 'adr1A',
@@ -104,11 +103,9 @@ my $b2 = {
     opac_info      => 'opacB',
     issuing        => undef,
 };
-ModBranch($b1);
-is( ModBranch($b2), undef, 'the field add is missing' );
+Koha::Library->new($b1)->store;
+Koha::Library->new($b2)->store;
 
-$b2->{add} = 1;
-ModBranch($b2);
 is( Koha::Libraries->search->count, $count + 2, "two branches added" );
 
 is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
@@ -123,7 +120,7 @@ my $branches = GetBranches();
 is( scalar( keys %$branches ),
     Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
 
-#Test ModBranch
+#Test modify a library
 
 $b1 = {
     branchcode     => 'BRA',
@@ -148,7 +145,7 @@ $b1 = {
     issuing        => undef,
 };
 
-ModBranch($b1);
+Koha::Libraries->find($b1->{branchcode})->set($b1)->store;
 is( Koha::Libraries->search->count, $count + 1,
     "A branch has been modified, no new branch added" );
 
@@ -190,8 +187,9 @@ is( $del, 1, 'One row affected' );
 
 is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
 
-$b2->{CAT1} = 1;
-ModBranch($b2);
+my $b2_stored = Koha::Library->new($b2)->store;
+my $CAT1 = Koha::LibraryCategories->find('CAT1');
+$b2_stored->add_to_categories([$CAT1]);
 is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
 
 #Test GetBranchInfo
@@ -209,37 +207,6 @@ is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' );
 
 Koha::LibraryCategory->new($cat2)->store;
 is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
-$b2 = {
-    branchcode     => 'BRB',
-    branchname     => 'BranchB',
-    branchaddress1 => 'adr1B',
-    branchaddress2 => 'adr2B',
-    branchaddress3 => 'adr3B',
-    branchzip      => 'zipB',
-    branchcity     => 'cityB',
-    branchstate    => 'stateB',
-    branchcountry  => 'countryB',
-    branchphone    => 'phoneB',
-    branchfax      => 'faxB',
-    branchemail    => 'emailB',
-    branchreplyto  => 'emailreply',
-    branchreturnpath => 'branchreturn',
-    branchurl      => 'urlB',
-    branchip       => 'ipB',
-    branchprinter  => undef,
-    branchnotes    => 'noteB',
-    opac_info      => 'opacB',
-    issuing        => undef,
-    CAT1           => 1,
-    CAT2           => 1
-};
-ModBranch($b2);
-$b2info = GetBranchInfo( $b2->{branchcode} );
-push( @cat, $cat2->{categorycode} );
-delete $b2->{CAT1};
-delete $b2->{CAT2};
-$b2->{categories} = \@cat;
-is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
 
 #TODO later: test mybranchine and onlymine
 # Actually we cannot mock C4::Context->userenv in unit tests
@@ -248,6 +215,4 @@ is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
 my $loop = GetBranchesLoop;
 is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
 
-# End transaction
-$dbh->rollback;
-
+$schema->storage->txn_rollback;
index 10e10b6..440f36e 100644 (file)
@@ -23,8 +23,8 @@ use Test::MockModule;
 use C4::Biblio;
 use C4::Items;
 use C4::Members;
-use C4::Branch;
 use C4::Category;
+use Koha::Library;
 use MARC::Record;
 
 BEGIN {
@@ -46,7 +46,7 @@ $dbh->do(q|DELETE FROM categories|);
 
 
 my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new( {branchcode => $branchcode, branchname => 'Branch' } )->store;
 
 my $categorycode = 'C';
 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
index 2e43270..39cad00 100644 (file)
@@ -22,7 +22,7 @@ use Test::More tests => 10;
 use C4::Circulation;
 use C4::Biblio;
 use C4::Items;
-use C4::Branch;
+use Koha::Library;
 
 
 BEGIN {
@@ -42,7 +42,7 @@ $dbh->do(q|DELETE FROM categories|);
 
 
 my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
 
 my $categorycode = 'C';
 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
index ddd5186..b215f33 100644 (file)
@@ -10,6 +10,7 @@ use C4::Members;
 use C4::Branch;
 use C4::Category;
 use C4::Circulation;
+use Koha::Library;
 use MARC::Record;
 
 my $dbh = C4::Context->dbh;
@@ -25,7 +26,7 @@ if (@branches) {
     $branchcode = $branches[0];
 } else {
     $branchcode = 'B';
-    ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+    Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
     $branch_created = 1;
 }
 
index 1409fc7..4c6f52c 100644 (file)
@@ -20,9 +20,9 @@ use Modern::Perl;
 use Test::More tests => 2;
 use Test::Warn;
 
-use C4::Branch;
 use C4::Circulation;
 use C4::Members;
+use Koha::Library;
 use t::lib::Mocks;
 
 my $dbh = C4::Context->dbh;
@@ -32,7 +32,7 @@ $dbh->{RaiseError} = 1;
 t::lib::Mocks::mock_preference('AnonymousPatron', '');
 
 my $branchcode = 'B';
-ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
+Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
 
 my $categorycode = 'C';
 $dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
index 19ebf95..ae7eadf 100644 (file)
@@ -3,10 +3,10 @@
 use Modern::Perl;
 use C4::Biblio;
 use C4::Members;
-use C4::Branch;
 use C4::Circulation;
 use C4::Items;
 use C4::Context;
+use Koha::Library;
 
 use Test::More tests => 14;
 
@@ -43,7 +43,6 @@ $dbh->do(q|DELETE FROM default_branch_item_rules|);
 
 #Add branch and category
 my $samplebranch1 = {
-    add            => 1,
     branchcode     => 'SAB1',
     branchname     => 'Sample Branch',
     branchaddress1 => 'sample adr1',
@@ -62,7 +61,6 @@ my $samplebranch1 = {
     opac_info      => 'sample opac',
 };
 my $samplebranch2 = {
-    add            => 1,
     branchcode     => 'SAB2',
     branchname     => 'Sample Branch2',
     branchaddress1 => 'sample adr1_2',
@@ -80,8 +78,8 @@ my $samplebranch2 = {
     branchprinter  => undef,
     opac_info      => 'sample opac2',
 };
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
 
 my $samplecat = {
     categorycode          => 'CAT1',
index 2e8f47a..977cb8b 100644 (file)
@@ -2,9 +2,9 @@
 
 use Modern::Perl;
 use C4::Context;
-use C4::Branch;
 use DateTime;
 use Koha::DateUtils;
+use Koha::Library;
 
 use Test::More tests => 9;
 
@@ -36,7 +36,6 @@ $dbh->do(q|DELETE FROM issuingrules|);
 
 #Add branch and category
 my $samplebranch1 = {
-    add            => 1,
     branchcode     => 'SAB1',
     branchname     => 'Sample Branch',
     branchaddress1 => 'sample adr1',
@@ -55,7 +54,6 @@ my $samplebranch1 = {
     opac_info      => 'sample opac',
 };
 my $samplebranch2 = {
-    add            => 1,
     branchcode     => 'SAB2',
     branchname     => 'Sample Branch2',
     branchaddress1 => 'sample adr1_2',
@@ -73,8 +71,8 @@ my $samplebranch2 = {
     branchprinter  => undef,
     opac_info      => 'sample opac2',
 };
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
 
 my $samplecat = {
     categorycode          => 'CAT1',
index 2f5edf8..387ae64 100644 (file)
@@ -1,8 +1,8 @@
 #!/usr/bin/perl
 
 use Modern::Perl;
-use C4::Branch;
 use C4::Circulation;
+use Koha::Library;
 
 use Test::More tests => 7;
 
@@ -32,7 +32,6 @@ $dbh->do(q|DELETE FROM pending_offline_operations|);
 
 #Add branch
 my $samplebranch1 = {
-    add            => 1,
     branchcode     => 'SAB1',
     branchname     => 'Sample Branch',
     branchaddress1 => 'sample adr1',
@@ -50,7 +49,7 @@ my $samplebranch1 = {
     branchprinter  => undef,
     opac_info      => 'sample opac',
 };
-ModBranch($samplebranch1);
+Koha::Library->new($samplebranch1)->store;
 
 #Begin Tests
 #Test AddOfflineOperation
index 511c3be..9b1a9c8 100644 (file)
@@ -21,11 +21,11 @@ use Koha::DateUtils;
 use DateTime::Duration;
 use C4::Biblio;
 use C4::Members;
-use C4::Branch;
 use C4::Circulation;
 use C4::Items;
 use C4::Context;
 use C4::Reserves;
+use Koha::Library;
 
 use Test::More tests => 32;
 
@@ -76,7 +76,6 @@ my $daysago10 = output_pref({ dt => $dt_today2, dateformat => 'iso', timeformat
 
 #Add branch and category
 my $samplebranch1 = {
-    add            => 1,
     branchcode     => 'CPL',
     branchname     => 'Sample Branch',
     branchaddress1 => 'sample adr1',
@@ -95,7 +94,6 @@ my $samplebranch1 = {
     opac_info      => 'sample opac',
 };
 my $samplebranch2 = {
-    add            => 1,
     branchcode     => 'MPL',
     branchname     => 'Sample Branch2',
     branchaddress1 => 'sample adr1_2',
@@ -113,8 +111,8 @@ my $samplebranch2 = {
     branchprinter  => undef,
     opac_info      => 'sample opac2',
 };
-ModBranch($samplebranch1);
-ModBranch($samplebranch2);
+Koha::Library->new($samplebranch1)->store;
+Koha::Library->new($samplebranch2)->store;
 
 my $samplecat = {
     categorycode          => 'CAT1',
index e3a1e02..a8f9ac2 100755 (executable)
@@ -20,8 +20,8 @@ use Modern::Perl;
 
 use MARC::Record;
 use C4::Biblio;
-use C4::Branch;
 use Koha::Database;
+use Koha::Library;
 
 use t::lib::Mocks;
 use t::lib::TestBuilder;
@@ -202,13 +202,13 @@ subtest 'GetItemsInfo tests' => sub {
                 holdingbranch => $library2->{branchcode},
             }, $biblionumber );
 
-    my $library = Koha::Libraries->find( $library1->{branchcode} )->unblessed;
-    $library->{ opac_info }= "homebranch OPAC info";
-    ModBranch($library);
+    my $library = Koha::Libraries->find( $library1->{branchcode} );
+    $library->opac_info("homebranch OPAC info");
+    $library->store;
 
-    $library = Koha::Libraries->find( $library2->{branchcode} )->unblessed;
-    $library->{ opac_info } = "holdingbranch OPAC info";
-    ModBranch($library);
+    $library = Koha::Libraries->find( $library2->{branchcode} );
+    $library->opac_info("holdingbranch OPAC info");
+    $library->store;
 
     my @results = GetItemsInfo( $biblionumber );
     ok( @results, 'GetItemsInfo returns results');
index 5027b07..62eae89 100644 (file)
@@ -8,9 +8,9 @@ use Test::MockModule;
 use C4::Biblio;
 use C4::Items;
 use C4::Members;
-use C4::Branch;
 use C4::Category;
 use C4::Circulation;
+use Koha::Libraries;
 use MARC::Record;
 
 my $dbh = C4::Context->dbh;
@@ -25,7 +25,7 @@ $dbh->do(q|DELETE FROM biblio|);
 $dbh->do(q|DELETE FROM categories|);
 
 my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
 
 my $categorycode = 'C';
 $dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
index f8a5c6b..da40880 100644 (file)
@@ -8,9 +8,9 @@ use Test::MockModule;
 use C4::Biblio;
 use C4::Items;
 use C4::Members;
-use C4::Branch;
 use C4::Category;
 use C4::Circulation;
+use Koha::Libraries;
 use MARC::Record;
 
 my $dbh = C4::Context->dbh;
@@ -25,7 +25,7 @@ $dbh->do(q|DELETE FROM biblio|);
 $dbh->do(q|DELETE FROM categories|);
 
 my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
 
 my $categorycode = 'C';
 $dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
index 1c1c683..cd51bcb 100644 (file)
@@ -8,9 +8,9 @@ use Test::MockModule;
 use C4::Biblio;
 use C4::Items;
 use C4::Members;
-use C4::Branch;
 use C4::Category;
 use C4::Circulation;
+use Koha::Library;
 use MARC::Record;
 
 my $dbh = C4::Context->dbh;
@@ -25,7 +25,7 @@ $dbh->do(q|DELETE FROM biblio|);
 $dbh->do(q|DELETE FROM categories|);
 
 my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
 
 my $categorycode = 'C';
 $dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
index 8c32c21..84ad115 100644 (file)
@@ -8,11 +8,11 @@ use Test::MockModule;
 use C4::Biblio;
 use C4::Items;
 use C4::Members;
-use C4::Branch;
 use C4::Category;
 use C4::Circulation;
 
 use Koha::DateUtils qw( dt_from_string output_pref );
+use Koha::Library;
 use DateTime::Duration;
 
 use MARC::Record;
@@ -30,7 +30,7 @@ $dbh->do(q|DELETE FROM categories|);
 $dbh->do(q|DELETE FROM letter|);
 
 my $branchcode = 'B';
-ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
+Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
 
 my $categorycode = 'C';
 $dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
index 125dddc..fe47bb8 100644 (file)
@@ -19,8 +19,8 @@ use Modern::Perl;
 
 use Test::More tests => 52;
 use C4::Context;
-use C4::Branch;
 use C4::Biblio;
+use Koha::Library;
 
 BEGIN {
     use_ok('C4::RotatingCollections');
@@ -173,7 +173,6 @@ is_deeply(
 
 #Test TransferCollection
 my $samplebranch = {
-    add            => 1,
     branchcode     => 'SAB',
     branchname     => 'Sample Branch',
     branchaddress1 => 'sample adr1',
@@ -192,7 +191,7 @@ my $samplebranch = {
     branchnotes    => 'sample note',
     opac_info      => 'sample opac',
 };
-ModBranch($samplebranch);
+Koha::Library->new($samplebranch)->store;
 is( TransferCollection( $collection_id1, $samplebranch->{branchcode} ),
     1, "Collection1 has been transfered in the branch SAB" );
 @collection1 = GetCollection($collection_id1);
index ddd7f00..62481d1 100644 (file)
@@ -20,10 +20,10 @@ use Modern::Perl;
 use C4::Context;
 use C4::Members;
 use C4::Letters;
-use C4::Branch;
 use C4::Budgets qw( AddBudgetPeriod AddBudget );
 
 use Koha::DateUtils qw( dt_from_string );
+use Koha::Library;
 use Koha::Libraries;
 
 use DateTime::Duration;
@@ -64,7 +64,7 @@ $dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHE
 
 # Add CPL if missing.
 if (not defined Koha::Libraries->find('CPL')) {
-    ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
+    Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
 }
 
 my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode='S';");
index 5b77d59..fb276f3 100644 (file)
@@ -3,7 +3,7 @@ use Modern::Perl;
 use Test::More tests => 5;
 
 use C4::Context;
-use C4::Branch;
+use Koha::Library;
 use Koha::Template::Plugin::Branches;
 
 my $dbh = C4::Context->dbh;
@@ -11,13 +11,12 @@ $dbh->{AutoCommit} = 0;
 $dbh->{RaiseError} = 1;
 
 for my $i ( 1 .. 5 ) {
-    C4::Branch::ModBranch(
+    Koha::Library->new(
 {
         branchcode     => "test_br_$i",
         branchname     => "test_br_$i",
-        add => 1,
 }
-    );
+    )->store;
 
 }
 
index 855d129..eb9af5a 100644 (file)
@@ -20,12 +20,13 @@ use Modern::Perl;
 use Test::More tests => 19;
 
 use C4::Context;
-use C4::Branch;
 use C4::Members;
 
 use C4::Members::Attributes;
 use C4::Members::AttributeTypes;
 
+use Koha::Library;
+
 use t::lib::Mocks;
 
 use_ok( "C4::Utils::DataTables::Members" );
@@ -42,7 +43,6 @@ my $categorycode = $categories[0]->categorycode;
 # Add a new branch so we control what borrowers it has
 my $branchcode   = "UNC";
 my $branch_data = {
-    add            => 1,
     branchcode     => $branchcode,
     branchname     => 'Universidad Nacional de Cordoba',
     branchaddress1 => 'Haya de la Torre',
@@ -52,7 +52,7 @@ my $branch_data = {
     branchstate    => 'Cordoba',
     branchcountry  => 'Argentina'
 };
-ModBranch( $branch_data );
+Koha::Library->new( $branch_data )->store;
 
 my %john_doe = (
     cardnumber   => '123456',
index 0a8f0ab..cb5ff55 100644 (file)
@@ -21,9 +21,9 @@ use Test::More tests => 13;
 
 use C4::Biblio;
 use C4::Context;
-use C4::Branch;
 use C4::Members;
 
+use Koha::Library;
 use Koha::Virtualshelf;
 use Koha::Virtualshelves;
 
@@ -42,11 +42,10 @@ my @categories   = C4::Category->all;
 my $categorycode = $categories[0]->categorycode;
 my $branchcode   = "ABC";
 my $branch_data = {
-    add            => 1,
     branchcode     => $branchcode,
     branchname     => 'my branchname',
 };
-ModBranch( $branch_data );
+Koha::Library->new( $branch_data )->store;
 
 my %john_doe = (
     cardnumber   => '123456',