Lines 34-39
use Test::MockObject;
Link Here
|
34 |
use Test::MockModule; |
34 |
use Test::MockModule; |
35 |
use Test::Exception; |
35 |
use Test::Exception; |
36 |
use Test::Deep qw/ cmp_deeply ignore /; |
36 |
use Test::Deep qw/ cmp_deeply ignore /; |
|
|
37 |
use Test::Warn; |
38 |
use Carp::Always; |
37 |
|
39 |
|
38 |
use Test::More tests => 12; |
40 |
use Test::More tests => 12; |
39 |
|
41 |
|
Lines 810-816
subtest 'Censorship' => sub {
Link Here
|
810 |
|
812 |
|
811 |
subtest 'Checking out' => sub { |
813 |
subtest 'Checking out' => sub { |
812 |
|
814 |
|
813 |
plan tests => 16; |
815 |
plan tests => 17; |
814 |
|
816 |
|
815 |
$schema->storage->txn_begin; |
817 |
$schema->storage->txn_begin; |
816 |
|
818 |
|
Lines 821-827
subtest 'Checking out' => sub {
Link Here
|
821 |
} |
823 |
} |
822 |
}); |
824 |
}); |
823 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
825 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
824 |
my $biblio = $builder->build_object({ class => 'Koha::Biblios' }); |
826 |
my $biblio = $builder->build_sample_biblio(); |
825 |
my $patron = $builder->build_object({ |
827 |
my $patron = $builder->build_object({ |
826 |
class => 'Koha::Patrons', |
828 |
class => 'Koha::Patrons', |
827 |
value => { category_type => 'x' } |
829 |
value => { category_type => 'x' } |
Lines 864-883
subtest 'Checking out' => sub {
Link Here
|
864 |
inhouse => 1 |
866 |
inhouse => 1 |
865 |
}); |
867 |
}); |
866 |
# Too many items attached to biblio |
868 |
# Too many items attached to biblio |
867 |
my $item1 = $builder->build_object({ |
869 |
my $item1 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
868 |
class => 'Koha::Items', |
870 |
my $item2 = $builder->build_sample_item({ biblionumber => $biblio->biblionumber }); |
869 |
value => { |
|
|
870 |
biblionumber => $biblio->biblionumber, |
871 |
biblioitemnumber => 1 |
872 |
} |
873 |
}); |
874 |
my $item2 = $builder->build_object({ |
875 |
class => 'Koha::Items', |
876 |
value => { |
877 |
biblionumber => $biblio->biblionumber, |
878 |
biblioitemnumber => 2 |
879 |
} |
880 |
}); |
881 |
my $form_stage_two_items = $request->check_out({ |
871 |
my $form_stage_two_items = $request->check_out({ |
882 |
stage => 'form', |
872 |
stage => 'form', |
883 |
item_type => $itemtype->itemtype, |
873 |
item_type => $itemtype->itemtype, |
Lines 886-917
subtest 'Checking out' => sub {
Link Here
|
886 |
itemcount => 1 |
876 |
itemcount => 1 |
887 |
}); |
877 |
}); |
888 |
|
878 |
|
889 |
# Passed validation |
879 |
# Delete the items we created, so we can test that we can create one |
890 |
# |
880 |
$item1->delete; |
|
|
881 |
$item2->delete; |
882 |
|
891 |
# We need to mock the user environment for AddIssue |
883 |
# We need to mock the user environment for AddIssue |
892 |
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); |
884 |
t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); |
893 |
# |
885 |
# |
894 |
# Delete the items we created, so we can test that we can create one |
886 |
|
895 |
Koha::Items->find({ itemnumber => $item1->itemnumber })->delete; |
|
|
896 |
Koha::Items->find({ itemnumber => $item2->itemnumber })->delete; |
897 |
# Create a biblioitem |
898 |
my $biblioitem = $builder->build_object({ |
899 |
class => 'Koha::Biblioitems', |
900 |
value => { |
901 |
biblionumber => $biblio->biblionumber |
902 |
} |
903 |
}); |
904 |
# First we pass bad parameters to the item creation to test we're |
887 |
# First we pass bad parameters to the item creation to test we're |
905 |
# catching the failure of item creation |
888 |
# catching the failure of item creation |
906 |
# Note: This will generate a DBD::mysql error when running this test! |
889 |
my $form_stage_bad_branchcode; |
907 |
my $form_stage_bad_branchcode = $request->check_out({ |
890 |
warning_like { |
908 |
stage => 'form', |
891 |
$form_stage_bad_branchcode = $request->check_out({ |
909 |
item_type => $itemtype->itemtype, |
892 |
stage => 'form', |
910 |
branchcode => '---' |
893 |
item_type => $itemtype->itemtype, |
911 |
}); |
894 |
branchcode => '---' |
|
|
895 |
}); |
896 |
} qr/^DBD::mysql::st execute failed: Cannot add or update a child row: a foreign key constraint fails/, |
897 |
"Item creation fails on bad parameters"; |
898 |
|
912 |
is_deeply($form_stage_bad_branchcode->{value}->{errors}, { |
899 |
is_deeply($form_stage_bad_branchcode->{value}->{errors}, { |
913 |
item_creation => 1 |
900 |
item_creation => 1 |
914 |
}); |
901 |
},"We get expected failure of item creation"); |
|
|
902 |
|
915 |
# Now create a proper item |
903 |
# Now create a proper item |
916 |
my $form_stage_good_branchcode = $request->check_out({ |
904 |
my $form_stage_good_branchcode = $request->check_out({ |
917 |
stage => 'form', |
905 |
stage => 'form', |
Lines 927-933
subtest 'Checking out' => sub {
Link Here
|
927 |
NOT_FOR_LOAN => 1, |
915 |
NOT_FOR_LOAN => 1, |
928 |
itemtype_notforloan => $itemtype->itemtype |
916 |
itemtype_notforloan => $itemtype->itemtype |
929 |
} |
917 |
} |
930 |
} |
918 |
}, |
|
|
919 |
"We get expected error on notforloan of item" |
931 |
); |
920 |
); |
932 |
# Delete the item that was created |
921 |
# Delete the item that was created |
933 |
$biblio->items->delete; |
922 |
$biblio->items->delete; |
Lines 939-945
subtest 'Checking out' => sub {
Link Here
|
939 |
} |
928 |
} |
940 |
}); |
929 |
}); |
941 |
# We need to mock the user environment for AddIssue |
930 |
# We need to mock the user environment for AddIssue |
942 |
t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} }); |
931 |
t::lib::Mocks::mock_userenv({ branchcode => $library->branchcode }); |
943 |
my $form_stage_loanable = $request->check_out({ |
932 |
my $form_stage_loanable = $request->check_out({ |
944 |
stage => 'form', |
933 |
stage => 'form', |
945 |
item_type => $itemtype_loanable->itemtype, |
934 |
item_type => $itemtype_loanable->itemtype, |
946 |
- |
|
|