|
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 536-542
subtest 'Backend core methods' => sub {
Link Here
|
| 536 |
|
536 |
|
| 537 |
subtest 'Helpers' => sub { |
537 |
subtest 'Helpers' => sub { |
| 538 |
|
538 |
|
| 539 |
plan tests => 9; |
539 |
plan tests => 7; |
| 540 |
|
540 |
|
| 541 |
$schema->storage->txn_begin; |
541 |
$schema->storage->txn_begin; |
| 542 |
|
542 |
|
|
Lines 564-598
subtest 'Helpers' => sub {
Link Here
|
| 564 |
$config->set_series('getPrefixes', |
564 |
$config->set_series('getPrefixes', |
| 565 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
565 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 566 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
566 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 567 |
is($illrq_obj->getPrefix({ brw_cat => "C", branch => "CPL" }), "CBAR", |
|
|
| 568 |
"getPrefix: brw_cat"); |
| 569 |
$config->set_series('getPrefixes', |
| 570 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 571 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 572 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
567 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "CPL" }), "TEST", |
| 573 |
"getPrefix: branch"); |
568 |
"getPrefix: branch"); |
| 574 |
$config->set_series('getPrefixes', |
569 |
$config->set_series('getPrefixes', |
| 575 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
570 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 576 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
571 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
| 577 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "DEFAULT", |
572 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
| 578 |
"getPrefix: default"); |
573 |
"getPrefix: default"); |
| 579 |
$config->set_always('getPrefixes', {}); |
574 |
$config->set_always('getPrefixes', {}); |
| 580 |
is($illrq_obj->getPrefix({ brw_cat => "UNKNOWN", branch => "UNKNOWN" }), "", |
575 |
is($illrq_obj->getPrefix({ branch => "UNKNOWN" }), "", |
| 581 |
"getPrefix: the empty prefix"); |
576 |
"getPrefix: the empty prefix"); |
| 582 |
|
577 |
|
| 583 |
# id_prefix |
578 |
# id_prefix |
| 584 |
$config->set_series('getPrefixes', |
579 |
$config->set_series('getPrefixes', |
| 585 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
580 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 586 |
{ A => "ATEST", C => "CBAR", default => "DEFAULT" }); |
|
|
| 587 |
is($illrq_obj->id_prefix, "ATEST-", "id_prefix: brw_cat"); |
| 588 |
$config->set_series('getPrefixes', |
| 589 |
{ CPL => "TEST", TSL => "BAR", default => "DEFAULT" }, |
| 590 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
581 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 591 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
582 |
is($illrq_obj->id_prefix, "TEST-", "id_prefix: branch"); |
| 592 |
$config->set_series('getPrefixes', |
583 |
$config->set_series('getPrefixes', |
| 593 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
584 |
{ CPLT => "TEST", TSLT => "BAR", default => "DEFAULT" }, |
| 594 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
585 |
{ AB => "ATEST", CD => "CBAR", default => "DEFAULT" }); |
| 595 |
is($illrq_obj->id_prefix, "DEFAULT-", "id_prefix: default"); |
586 |
is($illrq_obj->id_prefix, "", "id_prefix: default"); |
| 596 |
|
587 |
|
| 597 |
# requires_moderation |
588 |
# requires_moderation |
| 598 |
$illrq_obj->status('NEW')->store; |
589 |
$illrq_obj->status('NEW')->store; |
|
Lines 804-862
subtest 'Checking Limits' => sub {
Link Here
|
| 804 |
|
795 |
|
| 805 |
$schema->storage->txn_rollback; |
796 |
$schema->storage->txn_rollback; |
| 806 |
}; |
797 |
}; |
| 807 |
|
|
|
| 808 |
subtest 'TO_JSON() tests' => sub { |
| 809 |
|
| 810 |
plan tests => 10; |
| 811 |
|
| 812 |
my $illreqmodule = Test::MockModule->new('Koha::Illrequest'); |
| 813 |
|
| 814 |
# Mock ->capabilities |
| 815 |
$illreqmodule->mock( 'capabilities', sub { return 'capable'; } ); |
| 816 |
|
| 817 |
# Mock ->metadata |
| 818 |
$illreqmodule->mock( 'metadata', sub { return 'metawhat?'; } ); |
| 819 |
|
| 820 |
$schema->storage->txn_begin; |
| 821 |
|
| 822 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 823 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 824 |
my $illreq = $builder->build_object( |
| 825 |
{ |
| 826 |
class => 'Koha::Illrequests', |
| 827 |
value => { |
| 828 |
branchcode => $library->branchcode, |
| 829 |
borrowernumber => $patron->borrowernumber |
| 830 |
} |
| 831 |
} |
| 832 |
); |
| 833 |
my $illreq_json = $illreq->TO_JSON; |
| 834 |
is( $illreq_json->{patron}, |
| 835 |
undef, '%embed not passed, no \'patron\' attribute' ); |
| 836 |
is( $illreq_json->{metadata}, |
| 837 |
undef, '%embed not passed, no \'metadata\' attribute' ); |
| 838 |
is( $illreq_json->{capabilities}, |
| 839 |
undef, '%embed not passed, no \'capabilities\' attribute' ); |
| 840 |
is( $illreq_json->{library}, |
| 841 |
undef, '%embed not passed, no \'library\' attribute' ); |
| 842 |
|
| 843 |
$illreq_json = $illreq->TO_JSON( |
| 844 |
{ patron => 1, metadata => 1, capabilities => 1, library => 1 } ); |
| 845 |
is( $illreq_json->{patron}->{firstname}, |
| 846 |
$patron->firstname, |
| 847 |
'%embed passed, \'patron\' attribute correct (firstname)' ); |
| 848 |
is( $illreq_json->{patron}->{surname}, |
| 849 |
$patron->surname, |
| 850 |
'%embed passed, \'patron\' attribute correct (surname)' ); |
| 851 |
is( $illreq_json->{patron}->{cardnumber}, |
| 852 |
$patron->cardnumber, |
| 853 |
'%embed passed, \'patron\' attribute correct (cardnumber)' ); |
| 854 |
is( $illreq_json->{metadata}, |
| 855 |
'metawhat?', '%embed passed, \'metadata\' attribute correct' ); |
| 856 |
is( $illreq_json->{capabilities}, |
| 857 |
'capable', '%embed passed, \'capabilities\' attribute correct' ); |
| 858 |
is( $illreq_json->{library}->{branchcode}, |
| 859 |
$library->branchcode, '%embed not passed, no \'library\' attribute' ); |
| 860 |
|
| 861 |
$schema->storage->txn_rollback; |
| 862 |
}; |