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

(-)a/C4/Branch.pm (-22 lines)
Lines 36-42 BEGIN { Link Here
36
		&GetBranchDetail
36
		&GetBranchDetail
37
		&ModBranch
37
		&ModBranch
38
		&GetBranchInfo
38
		&GetBranchInfo
39
		&GetBranchesInCategory
40
		&mybranch
39
		&mybranch
41
	);
40
	);
42
    @EXPORT_OK = qw( &onlymine &mybranch );
41
    @EXPORT_OK = qw( &onlymine &mybranch );
Lines 310-336 sub GetBranchDetail { Link Here
310
    return $sth->fetchrow_hashref();
309
    return $sth->fetchrow_hashref();
311
}
310
}
312
311
313
=head2 GetBranchesInCategory
314
315
  my $branches = GetBranchesInCategory($categorycode);
316
317
Returns a href:  keys %$branches eq (branchcode,branchname) .
318
319
=cut
320
321
sub GetBranchesInCategory {
322
    my ($categorycode) = @_;
323
	my @branches;
324
	my $dbh = C4::Context->dbh();
325
	my $sth=$dbh->prepare( "SELECT b.branchcode FROM branchrelations r, branches b 
326
							where r.branchcode=b.branchcode and r.categorycode=?");
327
    $sth->execute($categorycode);
328
	while (my $branch = $sth->fetchrow) {
329
		push @branches, $branch;
330
	}
331
	return( \@branches );
332
}
333
334
=head2 GetBranchInfo
312
=head2 GetBranchInfo
335
313
336
$results = GetBranchInfo($branchcode);
314
$results = GetBranchInfo($branchcode);
(-)a/t/db_dependent/Branch.t (-35 / +1 lines)
Lines 21-27 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 => 23;
24
use Test::More tests => 21;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
use Koha::Libraries;
27
use Koha::Libraries;
Lines 41-47 can_ok( Link Here
41
      GetBranchDetail
41
      GetBranchDetail
42
      ModBranch
42
      ModBranch
43
      GetBranchInfo
43
      GetBranchInfo
44
      GetBranchesInCategory
45
      mybranch
44
      mybranch
46
      )
45
      )
47
);
46
);
Lines 249-286 $b2->{issuing} = undef; Link Here
249
$b2->{categories} = \@cat;
248
$b2->{categories} = \@cat;
250
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
249
is_deeply( @$b2info[0], $b2, 'BRB has the category CAT1 and CAT2' );
251
250
252
#Test GetBranchesInCategory
253
my $brCat1 = GetBranchesInCategory( $cat1->{categorycode} );
254
my @b      = ( $b2->{branchcode} );
255
is_deeply( $brCat1, \@b, 'CAT1 has branch BRB' );
256
257
my $b3 = {
258
    add            => 1,
259
    branchcode     => 'BRC',
260
    branchname     => 'BranchC',
261
    branchaddress1 => 'adr1C',
262
    branchaddress2 => 'adr2C',
263
    branchaddress3 => 'adr3C',
264
    branchzip      => 'zipC',
265
    branchcity     => 'cityC',
266
    branchstate    => 'stateC',
267
    branchcountry  => 'countryC',
268
    branchphone    => 'phoneC',
269
    branchfax      => 'faxC',
270
    branchemail    => 'emailC',
271
    branchurl      => 'urlC',
272
    branchip       => 'ipC',
273
    branchprinter  => undef,
274
    branchnotes    => 'noteC',
275
    opac_info      => 'opacC',
276
    CAT1           => 1,
277
    CAT2           => 1
278
};
279
ModBranch($b3);
280
$brCat1 = GetBranchesInCategory( $cat1->{categorycode} );
281
push( @b, $b3->{branchcode} );
282
is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' );
283
284
#TODO later: test mybranchine and onlymine
251
#TODO later: test mybranchine and onlymine
285
# Actually we cannot mock C4::Context->userenv in unit tests
252
# Actually we cannot mock C4::Context->userenv in unit tests
286
253
287
- 

Return to bug 15629