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

(-)a/C4/Branch.pm (-21 lines)
Lines 36-42 BEGIN { Link Here
36
		&GetBranchDetail
36
		&GetBranchDetail
37
		&get_branchinfos_of
37
		&get_branchinfos_of
38
		&ModBranch
38
		&ModBranch
39
		&CheckBranchCategorycode
40
		&GetBranchInfo
39
		&GetBranchInfo
41
		&GetCategoryTypes
40
		&GetCategoryTypes
42
		&GetBranchCategories
41
		&GetBranchCategories
Lines 490-515 sub ModBranchCategoryInfo { Link Here
490
        $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
489
        $sth->execute($data->{'categoryname'}, $data->{'codedescription'},$data->{'categorytype'},$data->{'show_in_pulldown'},uc( $data->{'categorycode'} ) );
491
    }
490
    }
492
}
491
}
493
494
=head2 CheckBranchCategorycode
495
496
$number_rows_affected = CheckBranchCategorycode($categorycode);
497
498
=cut
499
500
sub CheckBranchCategorycode {
501
502
    # check to see if the branchcode is being used in the database somewhere....
503
    my ($categorycode) = @_;
504
    my $dbh            = C4::Context->dbh;
505
    my $sth            =
506
      $dbh->prepare(
507
        "select count(*) from branchrelations where categorycode=?");
508
    $sth->execute($categorycode);
509
    my ($total) = $sth->fetchrow_array;
510
    return $total;
511
}
512
513
sub GetBranchesCount {
492
sub GetBranchesCount {
514
    my $dbh = C4::Context->dbh();
493
    my $dbh = C4::Context->dbh();
515
    my $query = "SELECT COUNT(*) AS branches_count FROM branches";
494
    my $query = "SELECT COUNT(*) AS branches_count FROM branches";
(-)a/t/db_dependent/Branch.t (-23 / +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 => 34;
24
use Test::More tests => 30;
25
25
26
use C4::Branch;
26
use C4::Branch;
27
use Koha::Libraries;
27
use Koha::Libraries;
Lines 42-48 can_ok( Link Here
42
      GetBranchDetail
42
      GetBranchDetail
43
      get_branchinfos_of
43
      get_branchinfos_of
44
      ModBranch
44
      ModBranch
45
      CheckBranchCategorycode
46
      GetBranchInfo
45
      GetBranchInfo
47
      GetCategoryTypes
46
      GetCategoryTypes
48
      GetBranchCategories
47
      GetBranchCategories
Lines 229-247 is( $cat2detail, undef, 'CAT2 doesnt exist' ); Link Here
229
$category = GetBranchCategory();
228
$category = GetBranchCategory();
230
is($category, undef, 'retrieve library category only if code is supplied (bug 10515)');
229
is($category, undef, 'retrieve library category only if code is supplied (bug 10515)');
231
230
232
#Test CheckBranchCategoryCode
233
my $check1 = CheckBranchCategorycode( $cat1->{categorycode} );
234
my $check2 = CheckBranchCategorycode( $cat2->{categorycode} );
235
like( $check1, '/^\d+$/', "CheckBranchCategorycode returns a number" );
236
237
$b2->{CAT1} = 1;
231
$b2->{CAT1} = 1;
238
ModBranch($b2);
232
ModBranch($b2);
239
is( GetBranchesCount(), $count + 2, 'BRB added' );
233
is( GetBranchesCount(), $count + 2, 'BRB added' );
240
is(
241
    CheckBranchCategorycode( $cat1->{categorycode} ),
242
    $check1 + 1,
243
    'BRB added to CAT1'
244
);
245
234
246
#Test GetBranchInfo
235
#Test GetBranchInfo
247
my $b1info = GetBranchInfo( $b1->{branchcode} );
236
my $b1info = GetBranchInfo( $b1->{branchcode} );
Lines 284-294 $b2 = { Link Here
284
};
273
};
285
ModBranch($b2);
274
ModBranch($b2);
286
$b2info = GetBranchInfo( $b2->{branchcode} );
275
$b2info = GetBranchInfo( $b2->{branchcode} );
287
is(
288
    CheckBranchCategorycode( $cat2->{categorycode} ),
289
    $check2 + 1,
290
    'BRB added to CAT2'
291
);
292
push( @cat, $cat2->{categorycode} );
276
push( @cat, $cat2->{categorycode} );
293
delete $b2->{CAT1};
277
delete $b2->{CAT1};
294
delete $b2->{CAT2};
278
delete $b2->{CAT2};
Lines 327-337 ModBranch($b3); Link Here
327
$brCat1 = GetBranchesInCategory( $cat1->{categorycode} );
311
$brCat1 = GetBranchesInCategory( $cat1->{categorycode} );
328
push( @b, $b3->{branchcode} );
312
push( @b, $b3->{branchcode} );
329
is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' );
313
is_deeply( $brCat1, \@b, 'CAT1 has branch BRB and BRC' );
330
is(
331
    CheckBranchCategorycode( $cat1->{categorycode} ),
332
    $check1 + 2,
333
    'BRC has been added to CAT1'
334
);
335
314
336
#Test GetCategoryTypes
315
#Test GetCategoryTypes
337
my @category_types = GetCategoryTypes();
316
my @category_types = GetCategoryTypes();
338
- 

Return to bug 15295