Lines 21-27
use File::Basename qw/basename/;
Link Here
|
21 |
use Koha::Database; |
21 |
use Koha::Database; |
22 |
use Koha::Illrequestattributes; |
22 |
use Koha::Illrequestattributes; |
23 |
use Koha::Illrequest::Config; |
23 |
use Koha::Illrequest::Config; |
|
|
24 |
use Koha::Biblios; |
24 |
use Koha::Patrons; |
25 |
use Koha::Patrons; |
|
|
26 |
use Koha::ItemTypes; |
27 |
use Koha::Items; |
28 |
use Koha::Libraries; |
25 |
use Koha::AuthorisedValueCategories; |
29 |
use Koha::AuthorisedValueCategories; |
26 |
use Koha::AuthorisedValues; |
30 |
use Koha::AuthorisedValues; |
27 |
use t::lib::Mocks; |
31 |
use t::lib::Mocks; |
Lines 30-36
use Test::MockObject;
Link Here
|
30 |
use Test::MockModule; |
34 |
use Test::MockModule; |
31 |
use Test::Exception; |
35 |
use Test::Exception; |
32 |
|
36 |
|
33 |
use Test::More tests => 11; |
37 |
use Test::More tests => 12; |
34 |
|
38 |
|
35 |
my $schema = Koha::Database->new->schema; |
39 |
my $schema = Koha::Database->new->schema; |
36 |
my $builder = t::lib::TestBuilder->new; |
40 |
my $builder = t::lib::TestBuilder->new; |
Lines 347-353
subtest 'Backend testing (mocks)' => sub {
Link Here
|
347 |
my $patron = $builder->build({ source => 'Borrower' }); |
351 |
my $patron = $builder->build({ source => 'Borrower' }); |
348 |
my $illrq = $builder->build_object({ |
352 |
my $illrq = $builder->build_object({ |
349 |
class => 'Koha::Illrequests', |
353 |
class => 'Koha::Illrequests', |
350 |
value => { borrowernumber => $patron->{borrowernumber} } |
|
|
351 |
}); |
354 |
}); |
352 |
|
355 |
|
353 |
$illrq->_backend($backend); |
356 |
$illrq->_backend($backend); |
Lines 408-414
subtest 'Backend testing (mocks)' => sub {
Link Here
|
408 |
name => 'Completed', |
411 |
name => 'Completed', |
409 |
ui_method_name => 'Mark completed', |
412 |
ui_method_name => 'Mark completed', |
410 |
method => 'mark_completed', |
413 |
method => 'mark_completed', |
411 |
next_actions => [ ], |
414 |
next_actions => [ 'CHK' ], |
412 |
ui_method_icon => 'fa-check', |
415 |
ui_method_icon => 'fa-check', |
413 |
}, |
416 |
}, |
414 |
"Dummy status graph for COMP."); |
417 |
"Dummy status graph for COMP."); |
Lines 773-778
subtest 'Censorship' => sub {
Link Here
|
773 |
$schema->storage->txn_rollback; |
776 |
$schema->storage->txn_rollback; |
774 |
}; |
777 |
}; |
775 |
|
778 |
|
|
|
779 |
subtest 'Checking out' => sub { |
780 |
|
781 |
plan tests => 16; |
782 |
|
783 |
$schema->storage->txn_begin; |
784 |
|
785 |
my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' }); |
786 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
787 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
788 |
my $patron = $builder->build_object({ |
789 |
class => 'Koha::Patrons', |
790 |
value => { category_type => 'x' } |
791 |
}); |
792 |
my $request = $builder->build_object({ |
793 |
class => 'Koha::Illrequests', |
794 |
value => { |
795 |
borrowernumber => $patron->borrowernumber, |
796 |
biblio_id => $biblio->biblionumber |
797 |
} |
798 |
}); |
799 |
|
800 |
# First test that calling check_out without a stage param returns |
801 |
# what's required to build the form |
802 |
my $no_stage = $request->check_out(); |
803 |
is($no_stage->{method}, 'check_out'); |
804 |
is($no_stage->{stage}, 'form'); |
805 |
isa_ok($no_stage->{value}, 'HASH'); |
806 |
isa_ok($no_stage->{value}->{itemtypes}, 'Koha::ItemTypes'); |
807 |
isa_ok($no_stage->{value}->{libraries}, 'Koha::Libraries'); |
808 |
isa_ok($no_stage->{value}->{statistical}, 'Koha::Patrons'); |
809 |
isa_ok($no_stage->{value}->{biblio}, 'Koha::Biblio'); |
810 |
|
811 |
# Now test that form validation works when we supply a 'form' stage |
812 |
# |
813 |
# No item_type |
814 |
my $form_stage_missing_params = $request->check_out({ |
815 |
stage => 'form' |
816 |
}); |
817 |
is_deeply($form_stage_missing_params->{value}->{errors}, { |
818 |
item_type => 1 |
819 |
}); |
820 |
# inhouse passed but not a valid patron |
821 |
my $form_stage_bad_patron = $request->check_out({ |
822 |
stage => 'form', |
823 |
item_type => $itemtype->itemtype, |
824 |
inhouse => 'I_DONT_EXIST' |
825 |
}); |
826 |
is_deeply($form_stage_bad_patron->{value}->{errors}, { |
827 |
inhouse => 1 |
828 |
}); |
829 |
# Too many items attached to biblio |
830 |
my $item1 = $builder->build_object({ |
831 |
class => 'Koha::Items', |
832 |
value => { |
833 |
biblionumber => $biblio->biblionumber, |
834 |
biblioitemnumber => 1 |
835 |
} |
836 |
}); |
837 |
my $item2 = $builder->build_object({ |
838 |
class => 'Koha::Items', |
839 |
value => { |
840 |
biblionumber => $biblio->biblionumber, |
841 |
biblioitemnumber => 2 |
842 |
} |
843 |
}); |
844 |
my $form_stage_two_items = $request->check_out({ |
845 |
stage => 'form', |
846 |
item_type => $itemtype->itemtype, |
847 |
}); |
848 |
is_deeply($form_stage_two_items->{value}->{errors}, { |
849 |
itemcount => 1 |
850 |
}); |
851 |
|
852 |
# Passed validation |
853 |
# |
854 |
# Delete the items we created, so we can test that we can create one |
855 |
Koha::Items->find({ itemnumber => $item1->itemnumber })->delete; |
856 |
Koha::Items->find({ itemnumber => $item2->itemnumber })->delete; |
857 |
# Create a biblioitem |
858 |
my $biblioitem = $builder->build_object({ |
859 |
class => 'Koha::Biblioitems', |
860 |
value => { |
861 |
biblionumber => $biblio->biblionumber |
862 |
} |
863 |
}); |
864 |
# First we pass bad parameters to the item creation to test we're |
865 |
# catching the failure of item creation |
866 |
# Note: This will generate a DBD::mysql error when running this test! |
867 |
my $form_stage_bad_branchcode = $request->check_out({ |
868 |
stage => 'form', |
869 |
item_type => $itemtype->itemtype, |
870 |
branchcode => '---' |
871 |
}); |
872 |
is_deeply($form_stage_bad_branchcode->{value}->{errors}, { |
873 |
item_creation => 1 |
874 |
}); |
875 |
# Now create a proper item |
876 |
my $form_stage_good_branchcode = $request->check_out({ |
877 |
stage => 'form', |
878 |
item_type => $itemtype->itemtype, |
879 |
branchcode => $library->branchcode |
880 |
}); |
881 |
# By default, this item should not be loanable, so check that we're |
882 |
# informed of that fact |
883 |
is_deeply( |
884 |
$form_stage_good_branchcode->{value}->{check_out_errors}, |
885 |
{ |
886 |
error => { |
887 |
NOT_FOR_LOAN => 1, |
888 |
itemtype_notforloan => $itemtype->itemtype |
889 |
} |
890 |
} |
891 |
); |
892 |
# Delete the item that was created |
893 |
$biblio->items->delete; |
894 |
# Now create an itemtype that is loanable |
895 |
my $itemtype_loanable = $builder->build_object({ |
896 |
class => 'Koha::ItemTypes', |
897 |
value => { |
898 |
notforloan => 0 |
899 |
} |
900 |
}); |
901 |
# We need to mock the user environment for AddIssue |
902 |
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); |
903 |
my $form_stage_loanable = $request->check_out({ |
904 |
stage => 'form', |
905 |
item_type => $itemtype_loanable->itemtype, |
906 |
branchcode => $library->branchcode |
907 |
}); |
908 |
is($form_stage_loanable->{stage}, 'done_check_out'); |
909 |
isa_ok($patron->checkouts, 'Koha::Checkouts'); |
910 |
is($patron->checkouts->count, 1); |
911 |
is($request->status, 'CHK'); |
912 |
|
913 |
$schema->storage->txn_rollback; |
914 |
}; |
915 |
|
776 |
subtest 'Checking Limits' => sub { |
916 |
subtest 'Checking Limits' => sub { |
777 |
|
917 |
|
778 |
plan tests => 30; |
918 |
plan tests => 30; |
779 |
- |
|
|