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 |
- |
|
|