Bugzilla – Attachment 64214 Details for
Bug 18789
Send a Koha::Patron object to the templates
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18789: add tests for is_adult and is_child
Bug-18789-add-tests-for-isadult-and-ischild.patch (text/plain), 3.84 KB, created by
Jonathan Druart
on 2017-06-12 16:59:31 UTC
(
hide
)
Description:
Bug 18789: add tests for is_adult and is_child
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2017-06-12 16:59:31 UTC
Size:
3.84 KB
patch
obsolete
>From a808ef8a18091dd38f31c7e050c238279f44ae9a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 1 Jun 2017 13:51:09 -0300 >Subject: [PATCH] Bug 18789: add tests for is_adult and is_child > >This patch add 2 methods to the Koha::Patron module: is_adult and >is_child. >That way the business logic is at only one place and covered by tests. >--- > Koha/Patron.pm | 10 +++++++ > t/db_dependent/Koha/Patrons.t | 69 ++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 78 insertions(+), 1 deletion(-) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 44afff85c1..dbbe114781 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -745,6 +745,16 @@ sub can { > return C4::Auth::haspermission( $self->userid, $flagsrequired ); > } > >+sub is_adult { >+ my ( $self ) = @_; >+ return $self->category->category_type =~ /^(A|I)$/ ? 1 : 0; >+} >+ >+sub is_child { >+ my( $self ) = @_; >+ return $self->category->category_type eq 'C' ? 1 : 0; >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Koha/Patrons.t b/t/db_dependent/Koha/Patrons.t >index 1b7c18dcce..8c734a2317 100644 >--- a/t/db_dependent/Koha/Patrons.t >+++ b/t/db_dependent/Koha/Patrons.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 23; >+use Test::More tests => 24; > use Test::Warn; > use DateTime; > >@@ -1001,6 +1001,73 @@ subtest 'account_locked' => sub { > $patron->delete; > }; > >+subtest 'is_child | is_adult' => sub { >+ plan tests => 8; >+ my $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { category_type => 'A' } >+ } >+ ); >+ my $patron_adult = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->categorycode } >+ } >+ ); >+ $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { category_type => 'I' } >+ } >+ ); >+ my $patron_adult_i = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->categorycode } >+ } >+ ); >+ $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { category_type => 'C' } >+ } >+ ); >+ my $patron_child = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->categorycode } >+ } >+ ); >+ $category = $builder->build_object( >+ { >+ class => 'Koha::Patron::Categories', >+ value => { category_type => 'O' } >+ } >+ ); >+ my $patron_other = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { categorycode => $category->categorycode } >+ } >+ ); >+ is( $patron_adult->is_adult, 1, 'Patron from category A should be considered adult' ); >+ is( $patron_adult_i->is_adult, 1, 'Patron from category I should be considered adult' ); >+ is( $patron_child->is_adult, 0, 'Patron from category C should not be considered adult' ); >+ is( $patron_other->is_adult, 0, 'Patron from category O should not be considered adult' ); >+ >+ is( $patron_adult->is_child, 0, 'Patron from category A should be considered child' ); >+ is( $patron_adult_i->is_child, 0, 'Patron from category I should be considered child' ); >+ is( $patron_child->is_child, 1, 'Patron from category C should not be considered child' ); >+ is( $patron_other->is_child, 0, 'Patron from category O should not be considered child' ); >+ >+ # Clean up >+ $patron_adult->delete; >+ $patron_adult_i->delete; >+ $patron_child->delete; >+ $patron_other->delete; >+}; >+ > $retrieved_patron_1->delete; > is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' ); > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18789
:
64211
|
64212
|
64213
|
64214
|
64215
|
64216
|
64218
|
64219
|
64221
|
64229
|
71301
|
71302
|
71303
|
71304
|
71305
|
71306
|
71307
|
71308
|
71309
|
71310
|
71311
|
71485
|
71486
|
71487
|
71488
|
71489
|
71490
|
71491
|
71492
|
71493
|
71494
|
71495
|
71496
|
71679
|
71680
|
71681
|
71682
|
71683
|
71684
|
71685
|
71686
|
71687
|
71688
|
71689
|
71690
|
71691
|
71713
|
71714
|
71715
|
71716
|
71717
|
71718
|
71719
|
71720
|
71721
|
71722
|
71723
|
71724
|
71725
|
71726
|
71727
|
71728
|
71729
|
71730
|
71731
|
71732
|
71733
|
71734
|
71735
|
71736
|
71827
|
71838
|
71841
|
73293
|
73890
|
75237