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

(-)a/C4/Branch.pm (-107 lines)
Lines 33-39 BEGIN { Link Here
33
		&GetBranch
33
		&GetBranch
34
		&GetBranches
34
		&GetBranches
35
		&GetBranchesLoop
35
		&GetBranchesLoop
36
		&ModBranch
37
		&GetBranchInfo
36
		&GetBranchInfo
38
		&mybranch
37
		&mybranch
39
	);
38
	);
Lines 171-282 sub GetBranchName { Link Here
171
    return ($branchname);
170
    return ($branchname);
172
}
171
}
173
172
174
=head2 ModBranch
175
176
$error = &ModBranch($newvalue);
177
178
This function modifies an existing branch
179
180
C<$newvalue> is a ref to an array which contains all the columns from branches table.
181
182
=cut
183
184
sub ModBranch {
185
    my ($data) = @_;
186
    
187
    my $dbh    = C4::Context->dbh;
188
    if ($data->{add}) {
189
        my $query  = "
190
            INSERT INTO branches
191
            (branchcode,branchname,branchaddress1,
192
            branchaddress2,branchaddress3,branchzip,branchcity,branchstate,
193
            branchcountry,branchphone,branchfax,branchemail,
194
            branchurl,branchip,branchprinter,branchnotes,opac_info,
195
            branchreplyto, branchreturnpath)
196
            VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
197
        ";
198
        my $sth    = $dbh->prepare($query);
199
        $sth->execute(
200
            $data->{'branchcode'},       $data->{'branchname'},
201
            $data->{'branchaddress1'},   $data->{'branchaddress2'},
202
            $data->{'branchaddress3'},   $data->{'branchzip'},
203
            $data->{'branchcity'},       $data->{'branchstate'},
204
            $data->{'branchcountry'},
205
            $data->{'branchphone'},      $data->{'branchfax'},
206
            $data->{'branchemail'},      $data->{'branchurl'},
207
            $data->{'branchip'},         $data->{'branchprinter'},
208
            $data->{'branchnotes'},      $data->{opac_info},
209
            $data->{'branchreplyto'},    $data->{'branchreturnpath'}
210
        );
211
        return 1 if $dbh->err;
212
    } else {
213
        my $query  = "
214
            UPDATE branches
215
            SET branchname=?,branchaddress1=?,
216
                branchaddress2=?,branchaddress3=?,branchzip=?,
217
                branchcity=?,branchstate=?,branchcountry=?,branchphone=?,
218
                branchfax=?,branchemail=?,branchurl=?,branchip=?,
219
                branchprinter=?,branchnotes=?,opac_info=?,
220
                branchreplyto=?, branchreturnpath=?
221
            WHERE branchcode=?
222
        ";
223
        my $sth    = $dbh->prepare($query);
224
        $sth->execute(
225
            $data->{'branchname'},
226
            $data->{'branchaddress1'},   $data->{'branchaddress2'},
227
            $data->{'branchaddress3'},   $data->{'branchzip'},
228
            $data->{'branchcity'},       $data->{'branchstate'},       
229
            $data->{'branchcountry'},
230
            $data->{'branchphone'},      $data->{'branchfax'},
231
            $data->{'branchemail'},      $data->{'branchurl'},
232
            $data->{'branchip'},         $data->{'branchprinter'},
233
            $data->{'branchnotes'},      $data->{opac_info},
234
            $data->{'branchreplyto'},    $data->{'branchreturnpath'},
235
            $data->{'branchcode'},
236
        );
237
    }
238
    # sort out the categories....
239
    my @checkedcats;
240
    my @cats = Koha::LibraryCategories->search;
241
    foreach my $cat (@cats) {
242
        my $code = $cat->categorycode;
243
        if ( $data->{$code} ) {
244
            push( @checkedcats, $code );
245
        }
246
    }
247
    my $branchcode = uc( $data->{'branchcode'} );
248
    my $branch     = GetBranchInfo($branchcode);
249
    $branch = $branch->[0];
250
    my $branchcats = $branch->{'categories'};
251
    my @addcats;
252
    my @removecats;
253
    foreach my $bcat (@$branchcats) {
254
255
        unless ( grep { /^$bcat$/ } @checkedcats ) {
256
            push( @removecats, $bcat );
257
        }
258
    }
259
    foreach my $ccat (@checkedcats) {
260
        unless ( grep { /^$ccat$/ } @$branchcats ) {
261
            push( @addcats, $ccat );
262
        }
263
    }
264
    foreach my $cat (@addcats) {
265
        my $sth =
266
          $dbh->prepare(
267
"insert into branchrelations (branchcode, categorycode) values(?, ?)"
268
          );
269
        $sth->execute( $branchcode, $cat );
270
    }
271
    foreach my $cat (@removecats) {
272
        my $sth =
273
          $dbh->prepare(
274
            "delete from branchrelations where branchcode=? and categorycode=?"
275
          );
276
        $sth->execute( $branchcode, $cat );
277
    }
278
}
279
280
=head2 GetBranch
173
=head2 GetBranch
281
174
282
$branch = GetBranch( $query, $branches );
175
$branch = GetBranch( $query, $branches );
(-)a/t/db_dependent/Branch.t (-48 / +13 lines)
Lines 21-29 use Modern::Perl; Link Here
21
use C4::Context;
21
use C4::Context;
22
use Data::Dumper;
22
use Data::Dumper;
23
23
24
use Test::More tests => 19;
24
use Test::More tests => 17;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
use Koha::Database;
28
use Koha::Library;
27
use Koha::Libraries;
29
use Koha::Libraries;
28
use Koha::LibraryCategories;
30
use Koha::LibraryCategories;
29
31
Lines 38-54 can_ok( Link Here
38
      GetBranch
40
      GetBranch
39
      GetBranches
41
      GetBranches
40
      GetBranchesLoop
42
      GetBranchesLoop
41
      ModBranch
42
      GetBranchInfo
43
      GetBranchInfo
43
      mybranch
44
      mybranch
44
      )
45
      )
45
);
46
);
46
47
48
my $schema = Koha::Database->new->schema;
49
$schema->storage->txn_begin;
47
50
48
# Start transaction
49
my $dbh = C4::Context->dbh;
51
my $dbh = C4::Context->dbh;
50
$dbh->{AutoCommit} = 0;
51
$dbh->{RaiseError} = 1;
52
52
53
# clear the slate
53
# clear the slate
54
$dbh->do('DELETE FROM branchcategories');
54
$dbh->do('DELETE FROM branchcategories');
Lines 60-66 like( $count, '/^\d+$/', "the count is a number" ); Link Here
60
60
61
#add 2 branches
61
#add 2 branches
62
my $b1 = {
62
my $b1 = {
63
    add            => 1,
64
    branchcode     => 'BRA',
63
    branchcode     => 'BRA',
65
    branchname     => 'BranchA',
64
    branchname     => 'BranchA',
66
    branchaddress1 => 'adr1A',
65
    branchaddress1 => 'adr1A',
Lines 104-114 my $b2 = { Link Here
104
    opac_info      => 'opacB',
103
    opac_info      => 'opacB',
105
    issuing        => undef,
104
    issuing        => undef,
106
};
105
};
107
ModBranch($b1);
106
Koha::Library->new($b1)->store;
108
is( ModBranch($b2), undef, 'the field add is missing' );
107
Koha::Library->new($b2)->store;
109
108
110
$b2->{add} = 1;
111
ModBranch($b2);
112
is( Koha::Libraries->search->count, $count + 2, "two branches added" );
109
is( Koha::Libraries->search->count, $count + 2, "two branches added" );
113
110
114
is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
111
is( Koha::Libraries->find( $b2->{branchcode} )->delete, 1,          "One row affected" );
Lines 123-129 my $branches = GetBranches(); Link Here
123
is( scalar( keys %$branches ),
120
is( scalar( keys %$branches ),
124
    Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
121
    Koha::Libraries->search->count, "GetBranches returns the right number of branches" );
125
122
126
#Test ModBranch
123
#Test modify a library
127
124
128
$b1 = {
125
$b1 = {
129
    branchcode     => 'BRA',
126
    branchcode     => 'BRA',
Lines 148-154 $b1 = { Link Here
148
    issuing        => undef,
145
    issuing        => undef,
149
};
146
};
150
147
151
ModBranch($b1);
148
Koha::Libraries->find($b1->{branchcode})->set($b1)->store;
152
is( Koha::Libraries->search->count, $count + 1,
149
is( Koha::Libraries->search->count, $count + 1,
153
    "A branch has been modified, no new branch added" );
150
    "A branch has been modified, no new branch added" );
154
151
Lines 190-197 is( $del, 1, 'One row affected' ); Link Here
190
187
191
is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
188
is( Koha::LibraryCategories->search->count, $count_cat + 2, "Category CAT 2 deleted" );
192
189
193
$b2->{CAT1} = 1;
190
my $b2_stored = Koha::Library->new($b2)->store;
194
ModBranch($b2);
191
my $CAT1 = Koha::LibraryCategories->find('CAT1');
192
$b2_stored->add_to_categories([$CAT1]);
195
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
193
is( Koha::Libraries->search->count, $count + 2, 'BRB added' );
196
194
197
#Test GetBranchInfo
195
#Test GetBranchInfo
Lines 209-245 is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1' ); Link Here
209
207
210
Koha::LibraryCategory->new($cat2)->store;
208
Koha::LibraryCategory->new($cat2)->store;
211
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
209
is( Koha::LibraryCategories->search->count, $count_cat + 3, "Two categories added" );
212
$b2 = {
213
    branchcode     => 'BRB',
214
    branchname     => 'BranchB',
215
    branchaddress1 => 'adr1B',
216
    branchaddress2 => 'adr2B',
217
    branchaddress3 => 'adr3B',
218
    branchzip      => 'zipB',
219
    branchcity     => 'cityB',
220
    branchstate    => 'stateB',
221
    branchcountry  => 'countryB',
222
    branchphone    => 'phoneB',
223
    branchfax      => 'faxB',
224
    branchemail    => 'emailB',
225
    branchreplyto  => 'emailreply',
226
    branchreturnpath => 'branchreturn',
227
    branchurl      => 'urlB',
228
    branchip       => 'ipB',
229
    branchprinter  => undef,
230
    branchnotes    => 'noteB',
231
    opac_info      => 'opacB',
232
    issuing        => undef,
233
    CAT1           => 1,
234
    CAT2           => 1
235
};
236
ModBranch($b2);
237
$b2info = GetBranchInfo( $b2->{branchcode} );
238
push( @cat, $cat2->{categorycode} );
239
delete $b2->{CAT1};
240
delete $b2->{CAT2};
241
$b2->{categories} = \@cat;
242
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
243
210
244
#TODO later: test mybranchine and onlymine
211
#TODO later: test mybranchine and onlymine
245
# Actually we cannot mock C4::Context->userenv in unit tests
212
# Actually we cannot mock C4::Context->userenv in unit tests
Lines 248-253 is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' ); Link Here
248
my $loop = GetBranchesLoop;
215
my $loop = GetBranchesLoop;
249
is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
216
is( scalar(@$loop), Koha::Libraries->search->count, 'There is the right number of branches' );
250
217
251
# End transaction
218
$schema->storage->txn_rollback;
252
$dbh->rollback;
253
(-)a/t/db_dependent/Circulation/CheckIfIssuedToPatron.t (-2 / +2 lines)
Lines 23-30 use Test::MockModule; Link Here
23
use C4::Biblio;
23
use C4::Biblio;
24
use C4::Items;
24
use C4::Items;
25
use C4::Members;
25
use C4::Members;
26
use C4::Branch;
27
use C4::Category;
26
use C4::Category;
27
use Koha::Library;
28
use MARC::Record;
28
use MARC::Record;
29
29
30
BEGIN {
30
BEGIN {
Lines 46-52 $dbh->do(q|DELETE FROM categories|); Link Here
46
46
47
47
48
my $branchcode = 'B';
48
my $branchcode = 'B';
49
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
49
Koha::Library->new( {branchcode => $branchcode, branchname => 'Branch' } )->store;
50
50
51
my $categorycode = 'C';
51
my $categorycode = 'C';
52
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
52
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
(-)a/t/db_dependent/Circulation/CheckValidBarcode.t (-2 / +2 lines)
Lines 22-28 use Test::More tests => 10; Link Here
22
use C4::Circulation;
22
use C4::Circulation;
23
use C4::Biblio;
23
use C4::Biblio;
24
use C4::Items;
24
use C4::Items;
25
use C4::Branch;
25
use Koha::Library;
26
26
27
27
28
BEGIN {
28
BEGIN {
Lines 42-48 $dbh->do(q|DELETE FROM categories|); Link Here
42
42
43
43
44
my $branchcode = 'B';
44
my $branchcode = 'B';
45
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
45
Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
46
46
47
my $categorycode = 'C';
47
my $categorycode = 'C';
48
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
48
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
(-)a/t/db_dependent/Circulation/GetIssues.t (-1 / +2 lines)
Lines 10-15 use C4::Members; Link Here
10
use C4::Branch;
10
use C4::Branch;
11
use C4::Category;
11
use C4::Category;
12
use C4::Circulation;
12
use C4::Circulation;
13
use Koha::Library;
13
use MARC::Record;
14
use MARC::Record;
14
15
15
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
Lines 25-31 if (@branches) { Link Here
25
    $branchcode = $branches[0];
26
    $branchcode = $branches[0];
26
} else {
27
} else {
27
    $branchcode = 'B';
28
    $branchcode = 'B';
28
    ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
29
    Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
29
    $branch_created = 1;
30
    $branch_created = 1;
30
}
31
}
31
32
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-2 / +2 lines)
Lines 20-28 use Modern::Perl; Link Here
20
use Test::More tests => 2;
20
use Test::More tests => 2;
21
use Test::Warn;
21
use Test::Warn;
22
22
23
use C4::Branch;
24
use C4::Circulation;
23
use C4::Circulation;
25
use C4::Members;
24
use C4::Members;
25
use Koha::Library;
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
27
28
my $dbh = C4::Context->dbh;
28
my $dbh = C4::Context->dbh;
Lines 32-38 $dbh->{RaiseError} = 1; Link Here
32
t::lib::Mocks::mock_preference('AnonymousPatron', '');
32
t::lib::Mocks::mock_preference('AnonymousPatron', '');
33
33
34
my $branchcode = 'B';
34
my $branchcode = 'B';
35
ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
35
Koha::Library->new({ branchcode => $branchcode, branchname => 'Branch' })->store;
36
36
37
my $categorycode = 'C';
37
my $categorycode = 'C';
38
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
38
$dbh->do("INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
(-)a/t/db_dependent/Circulation_Branch.t (-5 / +3 lines)
Lines 3-12 Link Here
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Biblio;
4
use C4::Biblio;
5
use C4::Members;
5
use C4::Members;
6
use C4::Branch;
7
use C4::Circulation;
6
use C4::Circulation;
8
use C4::Items;
7
use C4::Items;
9
use C4::Context;
8
use C4::Context;
9
use Koha::Library;
10
10
11
use Test::More tests => 14;
11
use Test::More tests => 14;
12
12
Lines 43-49 $dbh->do(q|DELETE FROM default_branch_item_rules|); Link Here
43
43
44
#Add branch and category
44
#Add branch and category
45
my $samplebranch1 = {
45
my $samplebranch1 = {
46
    add            => 1,
47
    branchcode     => 'SAB1',
46
    branchcode     => 'SAB1',
48
    branchname     => 'Sample Branch',
47
    branchname     => 'Sample Branch',
49
    branchaddress1 => 'sample adr1',
48
    branchaddress1 => 'sample adr1',
Lines 62-68 my $samplebranch1 = { Link Here
62
    opac_info      => 'sample opac',
61
    opac_info      => 'sample opac',
63
};
62
};
64
my $samplebranch2 = {
63
my $samplebranch2 = {
65
    add            => 1,
66
    branchcode     => 'SAB2',
64
    branchcode     => 'SAB2',
67
    branchname     => 'Sample Branch2',
65
    branchname     => 'Sample Branch2',
68
    branchaddress1 => 'sample adr1_2',
66
    branchaddress1 => 'sample adr1_2',
Lines 80-87 my $samplebranch2 = { Link Here
80
    branchprinter  => undef,
78
    branchprinter  => undef,
81
    opac_info      => 'sample opac2',
79
    opac_info      => 'sample opac2',
82
};
80
};
83
ModBranch($samplebranch1);
81
Koha::Library->new($samplebranch1)->store;
84
ModBranch($samplebranch2);
82
Koha::Library->new($samplebranch2)->store;
85
83
86
my $samplecat = {
84
my $samplecat = {
87
    categorycode          => 'CAT1',
85
    categorycode          => 'CAT1',
(-)a/t/db_dependent/Circulation_Issuingrule.t (-5 / +3 lines)
Lines 2-10 Link Here
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Context;
4
use C4::Context;
5
use C4::Branch;
6
use DateTime;
5
use DateTime;
7
use Koha::DateUtils;
6
use Koha::DateUtils;
7
use Koha::Library;
8
8
9
use Test::More tests => 9;
9
use Test::More tests => 9;
10
10
Lines 36-42 $dbh->do(q|DELETE FROM issuingrules|); Link Here
36
36
37
#Add branch and category
37
#Add branch and category
38
my $samplebranch1 = {
38
my $samplebranch1 = {
39
    add            => 1,
40
    branchcode     => 'SAB1',
39
    branchcode     => 'SAB1',
41
    branchname     => 'Sample Branch',
40
    branchname     => 'Sample Branch',
42
    branchaddress1 => 'sample adr1',
41
    branchaddress1 => 'sample adr1',
Lines 55-61 my $samplebranch1 = { Link Here
55
    opac_info      => 'sample opac',
54
    opac_info      => 'sample opac',
56
};
55
};
57
my $samplebranch2 = {
56
my $samplebranch2 = {
58
    add            => 1,
59
    branchcode     => 'SAB2',
57
    branchcode     => 'SAB2',
60
    branchname     => 'Sample Branch2',
58
    branchname     => 'Sample Branch2',
61
    branchaddress1 => 'sample adr1_2',
59
    branchaddress1 => 'sample adr1_2',
Lines 73-80 my $samplebranch2 = { Link Here
73
    branchprinter  => undef,
71
    branchprinter  => undef,
74
    opac_info      => 'sample opac2',
72
    opac_info      => 'sample opac2',
75
};
73
};
76
ModBranch($samplebranch1);
74
Koha::Library->new($samplebranch1)->store;
77
ModBranch($samplebranch2);
75
Koha::Library->new($samplebranch2)->store;
78
76
79
my $samplecat = {
77
my $samplecat = {
80
    categorycode          => 'CAT1',
78
    categorycode          => 'CAT1',
(-)a/t/db_dependent/Circulation_OfflineOperation.t (-3 / +2 lines)
Lines 1-8 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
use Modern::Perl;
3
use Modern::Perl;
4
use C4::Branch;
5
use C4::Circulation;
4
use C4::Circulation;
5
use Koha::Library;
6
6
7
use Test::More tests => 7;
7
use Test::More tests => 7;
8
8
Lines 32-38 $dbh->do(q|DELETE FROM pending_offline_operations|); Link Here
32
32
33
#Add branch
33
#Add branch
34
my $samplebranch1 = {
34
my $samplebranch1 = {
35
    add            => 1,
36
    branchcode     => 'SAB1',
35
    branchcode     => 'SAB1',
37
    branchname     => 'Sample Branch',
36
    branchname     => 'Sample Branch',
38
    branchaddress1 => 'sample adr1',
37
    branchaddress1 => 'sample adr1',
Lines 50-56 my $samplebranch1 = { Link Here
50
    branchprinter  => undef,
49
    branchprinter  => undef,
51
    opac_info      => 'sample opac',
50
    opac_info      => 'sample opac',
52
};
51
};
53
ModBranch($samplebranch1);
52
Koha::Library->new($samplebranch1)->store;
54
53
55
#Begin Tests
54
#Begin Tests
56
#Test AddOfflineOperation
55
#Test AddOfflineOperation
(-)a/t/db_dependent/Circulation_issue.t (-5 / +3 lines)
Lines 21-31 use Koha::DateUtils; Link Here
21
use DateTime::Duration;
21
use DateTime::Duration;
22
use C4::Biblio;
22
use C4::Biblio;
23
use C4::Members;
23
use C4::Members;
24
use C4::Branch;
25
use C4::Circulation;
24
use C4::Circulation;
26
use C4::Items;
25
use C4::Items;
27
use C4::Context;
26
use C4::Context;
28
use C4::Reserves;
27
use C4::Reserves;
28
use Koha::Library;
29
29
30
use Test::More tests => 32;
30
use Test::More tests => 32;
31
31
Lines 76-82 my $daysago10 = output_pref({ dt => $dt_today2, dateformat => 'iso', timeformat Link Here
76
76
77
#Add branch and category
77
#Add branch and category
78
my $samplebranch1 = {
78
my $samplebranch1 = {
79
    add            => 1,
80
    branchcode     => 'CPL',
79
    branchcode     => 'CPL',
81
    branchname     => 'Sample Branch',
80
    branchname     => 'Sample Branch',
82
    branchaddress1 => 'sample adr1',
81
    branchaddress1 => 'sample adr1',
Lines 95-101 my $samplebranch1 = { Link Here
95
    opac_info      => 'sample opac',
94
    opac_info      => 'sample opac',
96
};
95
};
97
my $samplebranch2 = {
96
my $samplebranch2 = {
98
    add            => 1,
99
    branchcode     => 'MPL',
97
    branchcode     => 'MPL',
100
    branchname     => 'Sample Branch2',
98
    branchname     => 'Sample Branch2',
101
    branchaddress1 => 'sample adr1_2',
99
    branchaddress1 => 'sample adr1_2',
Lines 113-120 my $samplebranch2 = { Link Here
113
    branchprinter  => undef,
111
    branchprinter  => undef,
114
    opac_info      => 'sample opac2',
112
    opac_info      => 'sample opac2',
115
};
113
};
116
ModBranch($samplebranch1);
114
Koha::Library->new($samplebranch1)->store;
117
ModBranch($samplebranch2);
115
Koha::Library->new($samplebranch2)->store;
118
116
119
my $samplecat = {
117
my $samplecat = {
120
    categorycode          => 'CAT1',
118
    categorycode          => 'CAT1',
(-)a/t/db_dependent/Items.t (-7 / +7 lines)
Lines 20-27 use Modern::Perl; Link Here
20
20
21
use MARC::Record;
21
use MARC::Record;
22
use C4::Biblio;
22
use C4::Biblio;
23
use C4::Branch;
24
use Koha::Database;
23
use Koha::Database;
24
use Koha::Library;
25
25
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
Lines 202-214 subtest 'GetItemsInfo tests' => sub { Link Here
202
                holdingbranch => $library2->{branchcode},
202
                holdingbranch => $library2->{branchcode},
203
            }, $biblionumber );
203
            }, $biblionumber );
204
204
205
    my $library = Koha::Libraries->find( $library1->{branchcode} )->unblessed;
205
    my $library = Koha::Libraries->find( $library1->{branchcode} );
206
    $library->{ opac_info }= "homebranch OPAC info";
206
    $library->opac_info("homebranch OPAC info");
207
    ModBranch($library);
207
    $library->store;
208
208
209
    $library = Koha::Libraries->find( $library2->{branchcode} )->unblessed;
209
    $library = Koha::Libraries->find( $library2->{branchcode} );
210
    $library->{ opac_info } = "holdingbranch OPAC info";
210
    $library->opac_info("holdingbranch OPAC info");
211
    ModBranch($library);
211
    $library->store;
212
212
213
    my @results = GetItemsInfo( $biblionumber );
213
    my @results = GetItemsInfo( $biblionumber );
214
    ok( @results, 'GetItemsInfo returns results');
214
    ok( @results, 'GetItemsInfo returns results');
(-)a/t/db_dependent/Members/GetAllIssues.t (-2 / +2 lines)
Lines 8-16 use Test::MockModule; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
11
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
13
use Koha::Libraries;
14
use MARC::Record;
14
use MARC::Record;
15
15
16
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
Lines 25-31 $dbh->do(q|DELETE FROM biblio|); Link Here
25
$dbh->do(q|DELETE FROM categories|);
25
$dbh->do(q|DELETE FROM categories|);
26
26
27
my $branchcode = 'B';
27
my $branchcode = 'B';
28
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
28
Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
29
29
30
my $categorycode = 'C';
30
my $categorycode = 'C';
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
(-)a/t/db_dependent/Members/GetOverdues.t (-2 / +2 lines)
Lines 8-16 use Test::MockModule; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
11
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
13
use Koha::Libraries;
14
use MARC::Record;
14
use MARC::Record;
15
15
16
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
Lines 25-31 $dbh->do(q|DELETE FROM biblio|); Link Here
25
$dbh->do(q|DELETE FROM categories|);
25
$dbh->do(q|DELETE FROM categories|);
26
26
27
my $branchcode = 'B';
27
my $branchcode = 'B';
28
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
28
Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
29
29
30
my $categorycode = 'C';
30
my $categorycode = 'C';
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
(-)a/t/db_dependent/Members/GetPendingIssues.t (-2 / +2 lines)
Lines 8-16 use Test::MockModule; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
11
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
13
use Koha::Library;
14
use MARC::Record;
14
use MARC::Record;
15
15
16
my $dbh = C4::Context->dbh;
16
my $dbh = C4::Context->dbh;
Lines 25-31 $dbh->do(q|DELETE FROM biblio|); Link Here
25
$dbh->do(q|DELETE FROM categories|);
25
$dbh->do(q|DELETE FROM categories|);
26
26
27
my $branchcode = 'B';
27
my $branchcode = 'B';
28
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
28
Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
29
29
30
my $categorycode = 'C';
30
my $categorycode = 'C';
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
31
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
(-)a/t/db_dependent/Members/IssueSlip.t (-2 / +2 lines)
Lines 8-18 use Test::MockModule; Link Here
8
use C4::Biblio;
8
use C4::Biblio;
9
use C4::Items;
9
use C4::Items;
10
use C4::Members;
10
use C4::Members;
11
use C4::Branch;
12
use C4::Category;
11
use C4::Category;
13
use C4::Circulation;
12
use C4::Circulation;
14
13
15
use Koha::DateUtils qw( dt_from_string output_pref );
14
use Koha::DateUtils qw( dt_from_string output_pref );
15
use Koha::Library;
16
use DateTime::Duration;
16
use DateTime::Duration;
17
17
18
use MARC::Record;
18
use MARC::Record;
Lines 30-36 $dbh->do(q|DELETE FROM categories|); Link Here
30
$dbh->do(q|DELETE FROM letter|);
30
$dbh->do(q|DELETE FROM letter|);
31
31
32
my $branchcode = 'B';
32
my $branchcode = 'B';
33
ModBranch( { add => 1, branchcode => $branchcode, branchname => 'Branch' } );
33
Koha::Library->new( { branchcode => $branchcode, branchname => 'Branch' } )->store;
34
34
35
my $categorycode = 'C';
35
my $categorycode = 'C';
36
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
36
$dbh->do( "INSERT INTO categories(categorycode) VALUES(?)",
(-)a/t/db_dependent/RotatingCollections.t (-3 / +2 lines)
Lines 19-26 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 52;
20
use Test::More tests => 52;
21
use C4::Context;
21
use C4::Context;
22
use C4::Branch;
23
use C4::Biblio;
22
use C4::Biblio;
23
use Koha::Library;
24
24
25
BEGIN {
25
BEGIN {
26
    use_ok('C4::RotatingCollections');
26
    use_ok('C4::RotatingCollections');
Lines 173-179 is_deeply( Link Here
173
173
174
#Test TransferCollection
174
#Test TransferCollection
175
my $samplebranch = {
175
my $samplebranch = {
176
    add            => 1,
177
    branchcode     => 'SAB',
176
    branchcode     => 'SAB',
178
    branchname     => 'Sample Branch',
177
    branchname     => 'Sample Branch',
179
    branchaddress1 => 'sample adr1',
178
    branchaddress1 => 'sample adr1',
Lines 192-198 my $samplebranch = { Link Here
192
    branchnotes    => 'sample note',
191
    branchnotes    => 'sample note',
193
    opac_info      => 'sample opac',
192
    opac_info      => 'sample opac',
194
};
193
};
195
ModBranch($samplebranch);
194
Koha::Library->new($samplebranch)->store;
196
is( TransferCollection( $collection_id1, $samplebranch->{branchcode} ),
195
is( TransferCollection( $collection_id1, $samplebranch->{branchcode} ),
197
    1, "Collection1 has been transfered in the branch SAB" );
196
    1, "Collection1 has been transfered in the branch SAB" );
198
@collection1 = GetCollection($collection_id1);
197
@collection1 = GetCollection($collection_id1);
(-)a/t/db_dependent/Suggestions.t (-2 / +2 lines)
Lines 20-29 use Modern::Perl; Link Here
20
use C4::Context;
20
use C4::Context;
21
use C4::Members;
21
use C4::Members;
22
use C4::Letters;
22
use C4::Letters;
23
use C4::Branch;
24
use C4::Budgets qw( AddBudgetPeriod AddBudget );
23
use C4::Budgets qw( AddBudgetPeriod AddBudget );
25
24
26
use Koha::DateUtils qw( dt_from_string );
25
use Koha::DateUtils qw( dt_from_string );
26
use Koha::Library;
27
use Koha::Libraries;
27
use Koha::Libraries;
28
28
29
use DateTime::Duration;
29
use DateTime::Duration;
Lines 64-70 $dbh->do(q|INSERT INTO letter(module, code, content) VALUES ('suggestions', 'CHE Link Here
64
64
65
# Add CPL if missing.
65
# Add CPL if missing.
66
if (not defined Koha::Libraries->find('CPL')) {
66
if (not defined Koha::Libraries->find('CPL')) {
67
    ModBranch({add => 1, branchcode => 'CPL', branchname => 'Centerville'});
67
    Koha::Library->new({ branchcode => 'CPL', branchname => 'Centerville' })->store;
68
}
68
}
69
69
70
my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode='S';");
70
my $sth = $dbh->prepare("SELECT * FROM categories WHERE categorycode='S';");
(-)a/t/db_dependent/Template/Plugin/Branches.t (-4 / +3 lines)
Lines 3-9 use Modern::Perl; Link Here
3
use Test::More tests => 5;
3
use Test::More tests => 5;
4
4
5
use C4::Context;
5
use C4::Context;
6
use C4::Branch;
6
use Koha::Library;
7
use Koha::Template::Plugin::Branches;
7
use Koha::Template::Plugin::Branches;
8
8
9
my $dbh = C4::Context->dbh;
9
my $dbh = C4::Context->dbh;
Lines 11-23 $dbh->{AutoCommit} = 0; Link Here
11
$dbh->{RaiseError} = 1;
11
$dbh->{RaiseError} = 1;
12
12
13
for my $i ( 1 .. 5 ) {
13
for my $i ( 1 .. 5 ) {
14
    C4::Branch::ModBranch(
14
    Koha::Library->new(
15
{
15
{
16
        branchcode     => "test_br_$i",
16
        branchcode     => "test_br_$i",
17
        branchname     => "test_br_$i",
17
        branchname     => "test_br_$i",
18
        add => 1,
19
}
18
}
20
    );
19
    )->store;
21
20
22
}
21
}
23
22
(-)a/t/db_dependent/Utils/Datatables_Members.t (-3 / +3 lines)
Lines 20-31 use Modern::Perl; Link Here
20
use Test::More tests => 19;
20
use Test::More tests => 19;
21
21
22
use C4::Context;
22
use C4::Context;
23
use C4::Branch;
24
use C4::Members;
23
use C4::Members;
25
24
26
use C4::Members::Attributes;
25
use C4::Members::Attributes;
27
use C4::Members::AttributeTypes;
26
use C4::Members::AttributeTypes;
28
27
28
use Koha::Library;
29
29
use t::lib::Mocks;
30
use t::lib::Mocks;
30
31
31
use_ok( "C4::Utils::DataTables::Members" );
32
use_ok( "C4::Utils::DataTables::Members" );
Lines 42-48 my $categorycode = $categories[0]->categorycode; Link Here
42
# Add a new branch so we control what borrowers it has
43
# Add a new branch so we control what borrowers it has
43
my $branchcode   = "UNC";
44
my $branchcode   = "UNC";
44
my $branch_data = {
45
my $branch_data = {
45
    add            => 1,
46
    branchcode     => $branchcode,
46
    branchcode     => $branchcode,
47
    branchname     => 'Universidad Nacional de Cordoba',
47
    branchname     => 'Universidad Nacional de Cordoba',
48
    branchaddress1 => 'Haya de la Torre',
48
    branchaddress1 => 'Haya de la Torre',
Lines 52-58 my $branch_data = { Link Here
52
    branchstate    => 'Cordoba',
52
    branchstate    => 'Cordoba',
53
    branchcountry  => 'Argentina'
53
    branchcountry  => 'Argentina'
54
};
54
};
55
ModBranch( $branch_data );
55
Koha::Library->new( $branch_data )->store;
56
56
57
my %john_doe = (
57
my %john_doe = (
58
    cardnumber   => '123456',
58
    cardnumber   => '123456',
(-)a/t/db_dependent/Utils/Datatables_Virtualshelves.t (-4 / +2 lines)
Lines 21-29 use Test::More tests => 13; Link Here
21
21
22
use C4::Biblio;
22
use C4::Biblio;
23
use C4::Context;
23
use C4::Context;
24
use C4::Branch;
25
use C4::Members;
24
use C4::Members;
26
25
26
use Koha::Library;
27
use Koha::Virtualshelf;
27
use Koha::Virtualshelf;
28
use Koha::Virtualshelves;
28
use Koha::Virtualshelves;
29
29
Lines 42-52 my @categories = C4::Category->all; Link Here
42
my $categorycode = $categories[0]->categorycode;
42
my $categorycode = $categories[0]->categorycode;
43
my $branchcode   = "ABC";
43
my $branchcode   = "ABC";
44
my $branch_data = {
44
my $branch_data = {
45
    add            => 1,
46
    branchcode     => $branchcode,
45
    branchcode     => $branchcode,
47
    branchname     => 'my branchname',
46
    branchname     => 'my branchname',
48
};
47
};
49
ModBranch( $branch_data );
48
Koha::Library->new( $branch_data )->store;
50
49
51
my %john_doe = (
50
my %john_doe = (
52
    cardnumber   => '123456',
51
    cardnumber   => '123456',
53
- 

Return to bug 15629