|
Lines 17-23
Link Here
|
| 17 |
|
17 |
|
| 18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
| 19 |
|
19 |
|
| 20 |
use Test::More tests => 4; |
20 |
use Test::More tests => 6; |
| 21 |
use t::lib::Mocks; |
21 |
use t::lib::Mocks; |
| 22 |
use t::lib::TestBuilder; |
22 |
use t::lib::TestBuilder; |
| 23 |
|
23 |
|
|
Lines 31-55
my $schema = Koha::Database->new->schema;
Link Here
|
| 31 |
$schema->storage->txn_begin; |
31 |
$schema->storage->txn_begin; |
| 32 |
|
32 |
|
| 33 |
my $builder = t::lib::TestBuilder->new; |
33 |
my $builder = t::lib::TestBuilder->new; |
| 34 |
|
|
|
| 35 |
my $nb_categories = Koha::Patron::Categories->count; |
34 |
my $nb_categories = Koha::Patron::Categories->count; |
| 36 |
|
35 |
|
| 37 |
# Create sample categories |
36 |
# Create sample categories |
| 38 |
my $category_1 = $builder->build( { source => 'Category' } ); |
37 |
my $category_1 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
| 39 |
my @categories = Koha::Template::Plugin::Categories->new->all->as_list; |
38 |
my @categories = Koha::Template::Plugin::Categories->new->all->as_list; |
| 40 |
is( scalar(@categories), 1 + $nb_categories, '->all returns all defined categories' ); |
39 |
is( scalar(@categories), 1 + $nb_categories, '->all returns all defined categories' ); |
| 41 |
|
40 |
|
| 42 |
my $category_2 = $builder->build( { source => 'Category' } ); |
41 |
my $category_2 = $builder->build_object( { class => 'Koha::Patron::Categories' } ); |
| 43 |
@categories = Koha::Template::Plugin::Categories->new->all->as_list; |
42 |
@categories = Koha::Template::Plugin::Categories->new->all->as_list; |
| 44 |
is( scalar(@categories), 2 + $nb_categories, '->all returns all defined categories' ); |
43 |
is( scalar(@categories), 2 + $nb_categories, '->all returns all defined categories' ); |
| 45 |
|
44 |
|
| 46 |
is( Koha::Template::Plugin::Categories->GetName( |
45 |
is( Koha::Template::Plugin::Categories->GetName( |
| 47 |
$category_1->{categorycode} |
46 |
$category_1->categorycode |
| 48 |
), |
47 |
), |
| 49 |
$category_1->{description}, |
48 |
$category_1->description, |
| 50 |
'->GetName returns the right description' |
49 |
'->GetName returns the right description' |
| 51 |
); |
50 |
); |
| 52 |
|
51 |
|
|
|
52 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 53 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 54 |
$category_1->library_limits( [ $library_1->branchcode ] ); |
| 55 |
$category_2->library_limits( [ $library_2->branchcode ] ); |
| 56 |
t::lib::Mocks::mock_userenv( { branchcode => $library_1->branchcode } ); |
| 57 |
my $limited = Koha::Template::Plugin::Categories->limited; |
| 58 |
is( $limited->search( { 'me.categorycode' => $category_1->categorycode } )->count, |
| 59 |
1, 'Category 1 is available from library 1' ); |
| 60 |
is( $limited->search( { 'me.categorycode' => $category_2->categorycode } )->count, |
| 61 |
0, 'Category 2 is not available from library 1' ); |
| 62 |
|
| 53 |
$schema->storage->txn_rollback; |
63 |
$schema->storage->txn_rollback; |
| 54 |
|
64 |
|
| 55 |
subtest 'can_any_reset_password() tests' => sub { |
65 |
subtest 'can_any_reset_password() tests' => sub { |
| 56 |
- |
|
|