Lines 28-34
use Test::MockObject;
Link Here
|
28 |
use Test::MockModule; |
28 |
use Test::MockModule; |
29 |
use Test::Exception; |
29 |
use Test::Exception; |
30 |
|
30 |
|
31 |
use Test::More tests => 11; |
31 |
use Test::More tests => 10; |
32 |
|
32 |
|
33 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
34 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
Lines 523-529
subtest 'Backend core methods' => sub {
Link Here
|
523 |
|
523 |
|
524 |
subtest 'Helpers' => sub { |
524 |
subtest 'Helpers' => sub { |
525 |
|
525 |
|
526 |
plan tests => 9; |
526 |
plan tests => 7; |
527 |
|
527 |
|
528 |
$schema->storage->txn_begin; |
528 |
$schema->storage->txn_begin; |
529 |
|
529 |
|
Lines 551-585
subtest 'Helpers' => sub {
Link Here
|
551 |
$config->set_series('getPrefixes', |
551 |
$config->set_series('getPrefixes', |
552 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
552 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
553 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
553 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
554 |
is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR", |
|
|
555 |
"getPrefix: brw_cat"); |
556 |
$config->set_series('getPrefixes', |
557 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
558 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
559 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
554 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
560 |
"getPrefix: branch"); |
555 |
"getPrefix: branch"); |
561 |
$config->set_series('getPrefixes', |
556 |
$config->set_series('getPrefixes', |
562 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
557 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
563 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
558 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
564 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT", |
559 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
565 |
"getPrefix: default"); |
560 |
"getPrefix: default"); |
566 |
$config->set_always('getPrefixes', {}); |
561 |
$config->set_always('getPrefixes', {}); |
567 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "", |
562 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
568 |
"getPrefix: the empty prefix"); |
563 |
"getPrefix: the empty prefix"); |
569 |
|
564 |
|
570 |
# id_prefix |
565 |
# id_prefix |
571 |
$config->set_series('getPrefixes', |
566 |
$config->set_series('getPrefixes', |
572 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
567 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
573 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
|
|
574 |
is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat"); |
575 |
$config->set_series('getPrefixes', |
576 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
577 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
568 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
578 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
569 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
579 |
$config->set_series('getPrefixes', |
570 |
$config->set_series('getPrefixes', |
580 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
571 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
581 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
572 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
582 |
is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default"); |
573 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
583 |
|
574 |
|
584 |
# requires_moderation |
575 |
# requires_moderation |
585 |
$illrq_obj->status('NEW')->store; |
576 |
$illrq_obj->status('NEW')->store; |
Lines 791-849
subtest 'Checking Limits' => sub {
Link Here
|
791 |
|
782 |
|
792 |
$schema->storage->txn_rollback; |
783 |
$schema->storage->txn_rollback; |
793 |
}; |
784 |
}; |
794 |
|
|
|
795 |
subtest 'TO_JSON() tests' => sub { |
796 |
|
797 |
plan tests => 10; |
798 |
|
799 |
my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); |
800 |
|
801 |
# Mock ->capabilities |
802 |
$illreqmodule->mock( 'capabilities', sub { return 'capable'; } ); |
803 |
|
804 |
# Mock ->metadata |
805 |
$illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } ); |
806 |
|
807 |
$schema->storage->txn_begin; |
808 |
|
809 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
810 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
811 |
my $illreq = $builder->build_object( |
812 |
{ |
813 |
class => 'Koha::Illrequests', |
814 |
value => { |
815 |
branchcode => $library->branchcode, |
816 |
borrowernumber => $patron->borrowernumber |
817 |
} |
818 |
} |
819 |
); |
820 |
my $illreq_json = $illreq->TO_JSON; |
821 |
is( $illreq_json->{patron}, |
822 |
undef, '%embed not passed, no \'patron\' attribute' ); |
823 |
is( $illreq_json->{metadata}, |
824 |
undef, '%embed not passed, no \'metadata\' attribute' ); |
825 |
is( $illreq_json->{capabilities}, |
826 |
undef, '%embed not passed, no \'capabilities\' attribute' ); |
827 |
is( $illreq_json->{library}, |
828 |
undef, '%embed not passed, no \'library\' attribute' ); |
829 |
|
830 |
$illreq_json = $illreq->TO_JSON( |
831 |
{ patron => 1, metadata => 1, capabilities => 1, library => 1 } ); |
832 |
is( $illreq_json->{patron}->{firstname}, |
833 |
$patron->firstname, |
834 |
'%embed passed, \'patron\' attribute correct (firstname)' ); |
835 |
is( $illreq_json->{patron}->{surname}, |
836 |
$patron->surname, |
837 |
'%embed passed, \'patron\' attribute correct (surname)' ); |
838 |
is( $illreq_json->{patron}->{cardnumber}, |
839 |
$patron->cardnumber, |
840 |
'%embed passed, \'patron\' attribute correct (cardnumber)' ); |
841 |
is( $illreq_json->{metadata}, |
842 |
'metawhat?', '%embed passed, \'metadata\' attribute correct' ); |
843 |
is( $illreq_json->{capabilities}, |
844 |
'capable', '%embed passed, \'capabilities\' attribute correct' ); |
845 |
is( $illreq_json->{library}->{branchcode}, |
846 |
$library->branchcode, '%embed not passed, no \'library\' attribute' ); |
847 |
|
848 |
$schema->storage->txn_rollback; |
849 |
}; |