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

(-)a/Koha/Illrequest.pm (-9 / +55 lines)
Lines 100-117 the API. Link Here
100
The interface's request method returned saying that the desired item is not
100
The interface's request method returned saying that the desired item is not
101
available for request.
101
available for request.
102
102
103
=head2 Class Methods
103
=head2 Class methods
104
104
105
=cut
105
=cut
106
106
107
=head3 type
108
109
=cut
110
111
sub _type {
112
    return 'Illrequest';
113
}
114
115
sub illrequestattributes {
107
sub illrequestattributes {
116
    my ( $self ) = @_;
108
    my ( $self ) = @_;
117
    return Koha::Illrequestattributes->_new_from_dbic(
109
    return Koha::Illrequestattributes->_new_from_dbic(
Lines 926-931 sub _censor { Link Here
926
    return $params;
918
    return $params;
927
}
919
}
928
920
921
=head3 TO_JSON
922
923
    $json = $illrequest->TO_JSON
924
925
Overloaded I<TO_JSON> method that takes care of inserting calculated values
926
into the unblessed representation of the object.
927
928
=cut
929
930
sub TO_JSON {
931
    my ( $self, $embed ) = @_;
932
933
    my $object = $self->SUPER::TO_JSON();
934
    $object->{id_prefix} = $self->id_prefix;
935
936
    if ( scalar (keys %$embed) ) {
937
        # Augment the request response with patron details if appropriate
938
        if ( $embed->{patron} ) {
939
            my $patron = $self->patron;
940
            $object->{patron} = {
941
                firstname  => $patron->firstname,
942
                surname    => $patron->surname,
943
                cardnumber => $patron->cardnumber
944
            };
945
        }
946
        # Augment the request response with metadata details if appropriate
947
        if ( $embed->{metadata} ) {
948
            $object->{metadata} = $self->metadata;
949
        }
950
        # Augment the request response with status details if appropriate
951
        if ( $embed->{capabilities} ) {
952
            $object->{capabilities} = $self->capabilities;
953
        }
954
        # Augment the request response with library details if appropriate
955
        if ( $embed->{branch} ) {
956
            $object->{branch} = Koha::Libraries->find(
957
                $self->branchcode
958
            )->TO_JSON;
959
        }
960
    }
961
962
    return $object;
963
}
964
965
=head2 Internal methods
966
967
=head3 _type
968
969
=cut
970
971
sub _type {
972
    return 'Illrequest';
973
}
974
929
=head1 AUTHOR
975
=head1 AUTHOR
930
976
931
Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
977
Alex Sassmannshausen <alex.sassmannshausen@ptfs-europe.com>
(-)a/t/db_dependent/Illrequests.t (-3 / +58 lines)
Lines 26-34 use Koha::Patrons; Link Here
26
use t::lib::Mocks;
26
use t::lib::Mocks;
27
use t::lib::TestBuilder;
27
use t::lib::TestBuilder;
28
use Test::MockObject;
28
use Test::MockObject;
29
use Test::MockModule;
29
use Test::Exception;
30
use Test::Exception;
30
31
31
use Test::More tests => 10;
32
use Test::More tests => 11;
32
33
33
my $schema = Koha::Database->new->schema;
34
my $schema = Koha::Database->new->schema;
34
my $builder = t::lib::TestBuilder->new;
35
my $builder = t::lib::TestBuilder->new;
Lines 41-46 subtest 'Basic object tests' => sub { Link Here
41
42
42
    $schema->storage->txn_begin;
43
    $schema->storage->txn_begin;
43
44
45
    Koha::Illrequests->search->delete;
44
    my $illrq = $builder->build({ source => 'Illrequest' });
46
    my $illrq = $builder->build({ source => 'Illrequest' });
45
    my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
47
    my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
46
48
Lines 789-792 subtest 'Checking Limits' => sub { Link Here
789
    $schema->storage->txn_rollback;
791
    $schema->storage->txn_rollback;
790
};
792
};
791
793
792
1;
794
subtest 'TO_JSON() tests' => sub {
795
796
    plan tests => 10;
797
798
    my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
799
800
    # Mock ->capabilities
801
    $illreqmodule->mock( 'capabilities', sub { return 'capable'; } );
802
803
    # Mock ->metadata
804
    $illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } );
805
806
    $schema->storage->txn_begin;
807
808
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
809
    my $patron  = $builder->build_object( { class => 'Koha::Patrons' } );
810
    my $illreq  = $builder->build_object(
811
        {
812
            class => 'Koha::Illrequests',
813
            value => {
814
                branchcode     => $library->branchcode,
815
                borrowernumber => $patron->borrowernumber
816
            }
817
        }
818
    );
819
    my $illreq_json = $illreq->TO_JSON;
820
    is( $illreq_json->{patron},
821
        undef, '%embed not passed, no \'patron\' attribute' );
822
    is( $illreq_json->{metadata},
823
        undef, '%embed not passed, no \'metadata\' attribute' );
824
    is( $illreq_json->{capabilities},
825
        undef, '%embed not passed, no \'capabilities\' attribute' );
826
    is( $illreq_json->{branch},
827
        undef, '%embed not passed, no \'branch\' attribute' );
828
829
    $illreq_json = $illreq->TO_JSON(
830
        { patron => 1, metadata => 1, capabilities => 1, branch => 1 } );
831
    is( $illreq_json->{patron}->{firstname},
832
        $patron->firstname,
833
        '%embed passed, \'patron\' attribute correct (firstname)' );
834
    is( $illreq_json->{patron}->{surname},
835
        $patron->surname,
836
        '%embed passed, \'patron\' attribute correct (surname)' );
837
    is( $illreq_json->{patron}->{cardnumber},
838
        $patron->cardnumber,
839
        '%embed passed, \'patron\' attribute correct (cardnumber)' );
840
    is( $illreq_json->{metadata},
841
        'metawhat?', '%embed passed, \'metadata\' attribute correct' );
842
    is( $illreq_json->{capabilities},
843
        'capable', '%embed passed, \'capabilities\' attribute correct' );
844
    is( $illreq_json->{branch}->{branchcode},
845
        $library->branchcode, '%embed not passed, no \'branch\' attribute' );
846
847
    $schema->storage->txn_rollback;
848
};
793
- 

Return to bug 7317