View | Details | Raw Unified | Return to bug 23112
Collapse All | Expand All

(-)a/t/db_dependent/Illrequests.t (-4 / +143 lines)
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 247-253 subtest 'Backend testing (mocks)' => sub { Link Here
247
    my $patron = $builder->build({ source => 'Borrower' });
251
    my $patron = $builder->build({ source => 'Borrower' });
248
    my $illrq = $builder->build_object({
252
    my $illrq = $builder->build_object({
249
        class => 'Koha::Illrequests',
253
        class => 'Koha::Illrequests',
250
        value => { borrowernumber => $patron->{borrowernumber} }
251
    });
254
    });
252
255
253
    $illrq->_backend($backend);
256
    $illrq->_backend($backend);
Lines 308-314 subtest 'Backend testing (mocks)' => sub { Link Here
308
                  name           => 'Completed',
311
                  name           => 'Completed',
309
                  ui_method_name => 'Mark completed',
312
                  ui_method_name => 'Mark completed',
310
                  method         => 'mark_completed',
313
                  method         => 'mark_completed',
311
                  next_actions   => [ ],
314
                  next_actions   => [ 'CHK' ],
312
                  ui_method_icon => 'fa-check',
315
                  ui_method_icon => 'fa-check',
313
              },
316
              },
314
              "Dummy status graph for COMP.");
317
              "Dummy status graph for COMP.");
Lines 673-678 subtest 'Censorship' => sub { Link Here
673
    $schema->storage->txn_rollback;
676
    $schema->storage->txn_rollback;
674
};
677
};
675
678
679
subtest 'Checking out' => sub {
680
681
    plan tests => 16;
682
683
    $schema->storage->txn_begin;
684
685
    my $itemtype = $builder->build_object({ class => 'Koha::ItemTypes' });
686
    my $library = $builder->build_object({ class => 'Koha::Libraries' });
687
    my $biblio = $builder->build_object({ class => 'Koha::Biblios' });
688
    my $patron = $builder->build_object({
689
        class => 'Koha::Patrons',
690
        value => { category_type => 'x' }
691
    });
692
    my $request = $builder->build_object({
693
        class => 'Koha::Illrequests',
694
        value => {
695
            borrowernumber => $patron->borrowernumber,
696
            biblio_id      => $biblio->biblionumber
697
        }
698
    });
699
700
    # First test that calling check_out without a stage param returns
701
    # what's required to build the form
702
    my $no_stage = $request->check_out();
703
    is($no_stage->{method}, 'check_out');
704
    is($no_stage->{stage}, 'form');
705
    isa_ok($no_stage->{value}, 'HASH');
706
    isa_ok($no_stage->{value}->{itemtypes}, 'Koha::ItemTypes');
707
    isa_ok($no_stage->{value}->{libraries}, 'Koha::Libraries');
708
    isa_ok($no_stage->{value}->{statistical}, 'Koha::Patrons');
709
    isa_ok($no_stage->{value}->{biblio}, 'Koha::Biblio');
710
711
    # Now test that form validation works when we supply a 'form' stage
712
    #
713
    # No item_type
714
    my $form_stage_missing_params = $request->check_out({
715
        stage => 'form'
716
    });
717
    is_deeply($form_stage_missing_params->{value}->{errors}, {
718
        item_type => 1
719
    });
720
    # inhouse passed but not a valid patron
721
    my $form_stage_bad_patron = $request->check_out({
722
        stage     => 'form',
723
        item_type => $itemtype->itemtype,
724
        inhouse   => 'I_DONT_EXIST'
725
    });
726
    is_deeply($form_stage_bad_patron->{value}->{errors}, {
727
        inhouse => 1
728
    });
729
    # Too many items attached to biblio
730
    my $item1 = $builder->build_object({
731
        class => 'Koha::Items',
732
        value => {
733
            biblionumber => $biblio->biblionumber,
734
            biblioitemnumber => 1
735
        }
736
    });
737
    my $item2 = $builder->build_object({
738
        class => 'Koha::Items',
739
        value => {
740
            biblionumber => $biblio->biblionumber,
741
            biblioitemnumber => 2
742
        }
743
    });
744
    my $form_stage_two_items = $request->check_out({
745
        stage     => 'form',
746
        item_type => $itemtype->itemtype,
747
    });
748
    is_deeply($form_stage_two_items->{value}->{errors}, {
749
        itemcount => 1
750
    });
751
752
    # Passed validation
753
    #
754
    # Delete the items we created, so we can test that we can create one
755
    Koha::Items->find({ itemnumber => $item1->itemnumber })->delete;
756
    Koha::Items->find({ itemnumber => $item2->itemnumber })->delete;
757
    # Create a biblioitem
758
    my $biblioitem = $builder->build_object({
759
        class => 'Koha::Biblioitems',
760
        value => {
761
            biblionumber => $biblio->biblionumber
762
        }
763
    });
764
    # First we pass bad parameters to the item creation to test we're
765
    # catching the failure of item creation
766
    # Note: This will generate a DBD::mysql error when running this test!
767
    my $form_stage_bad_branchcode = $request->check_out({
768
        stage     => 'form',
769
        item_type => $itemtype->itemtype,
770
        branchcode => '---'
771
    });
772
    is_deeply($form_stage_bad_branchcode->{value}->{errors}, {
773
        item_creation => 1
774
    });
775
    # Now create a proper item
776
    my $form_stage_good_branchcode = $request->check_out({
777
        stage      => 'form',
778
        item_type  => $itemtype->itemtype,
779
        branchcode => $library->branchcode
780
    });
781
    # By default, this item should not be loanable, so check that we're
782
    # informed of that fact
783
    is_deeply(
784
        $form_stage_good_branchcode->{value}->{check_out_errors},
785
        {
786
            error => {
787
                NOT_FOR_LOAN => 1,
788
                itemtype_notforloan => $itemtype->itemtype
789
            }
790
        }
791
    );
792
    # Delete the item that was created
793
    $biblio->items->delete;
794
    # Now create an itemtype that is loanable
795
    my $itemtype_loanable = $builder->build_object({
796
        class => 'Koha::ItemTypes',
797
        value => {
798
            notforloan => 0
799
        }
800
    });
801
    # We need to mock the user environment for AddIssue
802
    t::lib::Mocks::mock_userenv({ branchcode => $library->{branchcode} });
803
    my $form_stage_loanable = $request->check_out({
804
        stage      => 'form',
805
        item_type  => $itemtype_loanable->itemtype,
806
        branchcode => $library->branchcode
807
    });
808
    is($form_stage_loanable->{stage}, 'done_check_out');
809
    isa_ok($patron->checkouts, 'Koha::Checkouts');
810
    is($patron->checkouts->count, 1);
811
    is($request->status, 'CHK');
812
813
    $schema->storage->txn_rollback;
814
};
815
676
subtest 'Checking Limits' => sub {
816
subtest 'Checking Limits' => sub {
677
817
678
    plan tests => 30;
818
    plan tests => 30;
679
- 

Return to bug 23112