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

(-)a/t/db_dependent/Budgets.t (-18 / +41 lines)
Lines 807-818 is( scalar @{$authCat}, 0, "GetBudgetAuthCats returns only non-empty sorting cat Link Here
807
807
808
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
808
subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub {
809
809
810
    plan tests => 12;
810
    plan tests => 16;
811
811
812
#Let's build an order, we need a couple things though
812
#Let's build an order, we need a couple things though
813
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
813
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
814
814
815
    my $spent_biblio = $builder->build({ source => 'Biblio' });
815
    my $spent_biblio = $builder->build({ source => 'Biblio' });
816
    my $item_1 = $builder->build({ source => 'Item', value => { biblionumber => $spent_biblio->{biblionumber} } });
817
    my $biblioitem_1 = $builder->build({ source => 'Biblioitem', value => { biblionumber => $spent_biblio->{biblionumber}, itemnumber => $item_1->{itemnumber} } });
816
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
818
    my $spent_basket = $builder->build({ source => 'Aqbasket', value => { is_standing => 0 } });
817
    my $spent_invoice = $builder->build({ source => 'Aqinvoice'});
819
    my $spent_invoice = $builder->build({ source => 'Aqinvoice'});
818
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
820
    my $spent_currency = $builder->build({ source => 'Currency', value => { active => 1, archived => 0, symbol => 'F', rate => 2, isocode => undef, currency => 'FOO' }  });
Lines 860-866 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
860
#Let's test some budget planning
862
#Let's test some budget planning
861
#Regression tests for bug 18736
863
#Regression tests for bug 18736
862
    #We need an item to test by BRANCHES
864
    #We need an item to test by BRANCHES
863
    my $item_1 = $builder->build({ source => 'Item' });
864
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
865
    my $order_item_1 = $builder->build({ source => 'AqordersItem', value => { ordernumber => $spent_order->{ordernumber}, itemnumber => $item_1->{itemnumber}  } });
865
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
866
    my $spent_fund = Koha::Acquisition::Funds->find( $spent_order->{budget_id} );
866
    my $cell = {
867
    my $cell = {
Lines 868-890 subtest 'GetBudgetSpent GetBudgetOrdered GetBudgetsPlanCell tests' => sub { Link Here
868
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
869
        cell_authvalue => $spent_order->{entrydate}, #normally this is just the year/month but full won't hurt us here
869
        budget_id => $spent_order->{budget_id},
870
        budget_id => $spent_order->{budget_id},
870
        budget_period_id => $spent_fund->budget_period_id,
871
        budget_period_id => $spent_fund->budget_period_id,
872
        sort1_authcat => $spent_order->{sort1_authcat},
873
        sort2_authcat => $spent_order->{sort1_authcat},
874
    };
875
    my $test_values = {
876
        'MONTHS' => {
877
            authvalue => $spent_order->{entrydate},
878
            expected_rounded => 9.85,
879
            expected_exact   => 9.8542,
880
        },
881
        'BRANCHES' => {
882
            authvalue => $item_1->{homebranch},
883
            expected_rounded => 9.85,
884
            expected_exact   => 9.8542,
885
        },
886
        'ITEMTYPES' => {
887
            authvalue => $biblioitem_1->{itemtype},
888
            expected_rounded => 78.80,
889
            expected_exact   => 78.8336,
890
        },
891
        'ELSE' => {
892
            authvalue => 'purposefully_bad_but_needs_to_be_good',
893
            expected_rounded => 0,
894
            expected_exact   => 0,
895
        },
871
    };
896
    };
872
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
873
    my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
874
    is ( $actual, '9.854200', "We expect this to be an exact order cost"); #really we should expect cost*quantity but we don't
875
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
876
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
877
    is ( $actual, '9.8500', "We expect this to be a rounded order cost"); #really we should expect cost*quantity but we don't
878
    $cell->{authcat} = 'BRANCHES';
879
    $cell->{authvalue} = $item_1->{homebranch};
880
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
881
    t::lib::Mocks::mock_preference('OrderPriceRounding','');
882
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
883
    is ( $actual, '9.854200', "We expect this to be full cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered
884
    t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
885
    ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
886
    is ( $actual, '9.8500', "We expect this to be rounded cost for items from the branch"); #here we rely on items having been created for each order, again quantity should be considered
887
897
898
    for my $authcat ( keys %$test_values ) {
899
        my $test_val         = $test_values->{$authcat};
900
        my $authvalue        = $test_val->{authvalue};
901
        my $expected_rounded = $test_val->{expected_rounded};
902
        my $expected_exact   = $test_val->{expected_exact};
903
        $cell->{authcat} = $authcat;
904
        $cell->{authvalue} = $authvalue;
905
        t::lib::Mocks::mock_preference('OrderPriceRounding','');
906
        my ( $actual ) = GetBudgetsPlanCell( $cell, undef, undef); #we are only testing the actual for now
907
        is ( $actual+0, $expected_exact, "We expect this to be an exact order cost ($authcat)"); #really we should expect cost*quantity but we don't
908
        t::lib::Mocks::mock_preference('OrderPriceRounding','nearest_cent');
909
        ( $actual ) = GetBudgetsPlanCell( $cell, undef, $spent_order); #we are only testing the actual for now
910
        is ( $actual+0, $expected_rounded, "We expect this to be a rounded order cost ($authcat)"); #really we should expect cost*quantity but we don't
911
    }
888
912
889
#Okay, now we can receive the order, giving the price as the user would
913
#Okay, now we can receive the order, giving the price as the user would
890
914
891
- 

Return to bug 18736