Bugzilla – Attachment 58421 Details for
Bug 17792
Introduce Koha::Patron::Attribute(s)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17792: Add opac_editable and opac_display methods
Bug-17792-Add-opaceditable-and-opacdisplay-methods.patch (text/plain), 5.15 KB, created by
Tomás Cohen Arazi (tcohen)
on 2016-12-23 15:09:00 UTC
(
hide
)
Description:
Bug 17792: Add opac_editable and opac_display methods
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2016-12-23 15:09:00 UTC
Size:
5.15 KB
patch
obsolete
>From 6b8c96e991d3a5b4dc5572a91acafc1bd05fe33b Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 23 Dec 2016 12:05:35 -0300 >Subject: [PATCH] Bug 17792: Add opac_editable and opac_display methods > >This patch adds two methods to the Koha::Patron::Attribute: > >- opac_display >- opac_editable > >Both method just check the corresponding Koha::Patron::Attribute::Type >and return the values for those attributes. This is useful to avoid >checking that manually on the controller scripts. > >To test: >- Run: > $ prove t/db_dependent/Koha/Patron/Attributes.t >=> SUCCESS: Tests pass! >- Sign off :-D >--- > Koha/Patron/Attribute.pm | 30 +++++++++ > t/db_dependent/Koha/Patron/Attributes.t | 110 ++++++++++++++++++++++++++++++++ > 2 files changed, 140 insertions(+) > create mode 100644 t/db_dependent/Koha/Patron/Attributes.t > >diff --git a/Koha/Patron/Attribute.pm b/Koha/Patron/Attribute.pm >index 8bd43d2dfb..7643536b7c 100644 >--- a/Koha/Patron/Attribute.pm >+++ b/Koha/Patron/Attribute.pm >@@ -17,6 +17,8 @@ package Koha::Patron::Attribute; > > use Modern::Perl; > >+use Koha::Patron::Attribute::Types; >+ > use base qw(Koha::Object); > > =head1 NAME >@@ -29,6 +31,34 @@ Koha::Patron::Attribute - Koha Patron Attribute Object class > > =cut > >+=head3 opac_display >+ >+ my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... }); >+ if ( $attribute->opac_display ) { ... } >+ >+=cut >+ >+sub opac_display { >+ >+ my $self = shift; >+ >+ return Koha::Patron::Attribute::Types->find( $self->code )->opac_display; >+} >+ >+=head3 opac_editable >+ >+ my $attribute = Koha::Patron::Attribute->new({ code => 'a_code', ... }); >+ if ( $attribute->is_opac_editable ) { ... } >+ >+=cut >+ >+sub opac_editable { >+ >+ my $self = shift; >+ >+ return Koha::Patron::Attribute::Types->find( $self->code )->opac_editable; >+} >+ > =head3 _type > > =cut >diff --git a/t/db_dependent/Koha/Patron/Attributes.t b/t/db_dependent/Koha/Patron/Attributes.t >new file mode 100644 >index 0000000000..22e4d509a9 >--- /dev/null >+++ b/t/db_dependent/Koha/Patron/Attributes.t >@@ -0,0 +1,110 @@ >+#!/usr/bin/perl >+ >+# Copyright 2016 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+ >+use t::lib::TestBuilder; >+ >+use Koha::Database; >+use Koha::Patron::Attribute; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'opac_display() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron >+ = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $attribute_type_1 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { opac_display => 1 } >+ } >+ ); >+ >+ my $attribute_1 = Koha::Patron::Attribute->new( >+ { borrowernumber => $patron, >+ code => $attribute_type_1->{code}, >+ attribute => $patron >+ } >+ ); >+ is( $attribute_1->opac_display, 1, '->opac_display returns 1' ); >+ >+ my $attribute_type_2 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { opac_display => 0 } >+ } >+ ); >+ >+ my $attribute_2 = Koha::Patron::Attribute->new( >+ { borrowernumber => $patron, >+ code => $attribute_type_2->{code}, >+ attribute => $patron >+ } >+ ); >+ is( $attribute_2->opac_display, 0, '->opac_display returns 0' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'opac_editable() tests' => sub { >+ >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my $patron >+ = $builder->build( { source => 'Borrower' } )->{borrowernumber}; >+ my $attribute_type_1 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { opac_editable => 1 } >+ } >+ ); >+ >+ my $attribute_1 = Koha::Patron::Attribute->new( >+ { borrowernumber => $patron, >+ code => $attribute_type_1->{code}, >+ attribute => $patron >+ } >+ ); >+ is( $attribute_1->opac_editable, 1, '->opac_editable returns 1' ); >+ >+ my $attribute_type_2 = $builder->build( >+ { source => 'BorrowerAttributeType', >+ value => { opac_editable => 0 } >+ } >+ ); >+ >+ my $attribute_2 = Koha::Patron::Attribute->new( >+ { borrowernumber => $patron, >+ code => $attribute_type_2->{code}, >+ attribute => $patron >+ } >+ ); >+ is( $attribute_2->opac_editable, 0, '->opac_editable returns 0' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+1; >-- >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 17792
:
58350
|
58414
|
58421
|
59692
|
59693
|
61553
|
61554