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

(-)a/t/db_dependent/Koha/Acquisition/Basket.t (-23 / +51 lines)
Lines 18-51 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 8;
21
22
use Koha::Database;
22
use Test::More tests => 3;
23
use t::lib::TestBuilder;
23
use t::lib::TestBuilder;
24
use t::lib::Mocks;
24
use t::lib::Mocks;
25
25
use C4::Acquisition;
26
use C4::Acquisition;
27
use Koha::Database;
26
28
27
use_ok('Koha::Acquisition::Basket');
29
use_ok('Koha::Acquisition::Basket');
28
use_ok('Koha::Acquisition::Baskets');
30
use_ok('Koha::Acquisition::Baskets');
29
31
30
my $schema = Koha::Database->schema;
32
my $schema  = Koha::Database->schema;
31
$schema->storage->txn_begin;
33
my $builder = t::lib::TestBuilder->new;
32
my $dbh = C4::Context->dbh;
34
35
subtest 'create_items + effective_create_items tests' => sub {
33
36
34
# Start transaction
37
    plan tests => 7;
35
$dbh->{RaiseError} = 1;
36
38
37
my $builder = t::lib::TestBuilder->new;
39
    $schema->storage->txn_begin;
38
my $basket = $builder->build_object({ class => 'Koha::Acquisition::Baskets', value => { create_items => undef } });
40
39
my $created_basketno = C4::Acquisition::NewBasket($basket->booksellerid, $basket->authorisedby, $basket->basketname,$basket->note, $basket->booksellernote, $basket->contractnumber, $basket->deliveryplace, $basket->billingplace, $basket->is_standing, $basket->create_items);
41
    my $basket = $builder->build_object(
40
my $created_basket = Koha::Acquisition::Baskets->find({ basketno => $created_basketno });
42
        {
41
is($created_basket->basketno, $created_basketno, "Basket created by NewBasket matches db basket");
43
            class => 'Koha::Acquisition::Baskets',
42
is( $basket->create_items, undef, "Create items value can be null");
44
            value => { create_items => undef }
43
t::lib::Mocks::mock_preference('AcqCreateItem', 'cataloguing');
45
        }
44
is( $basket->effective_create_items, "cataloguing","We use AcqCreateItem if basket create items is not set");
46
    );
45
C4::Acquisition::ModBasketHeader($basket->basketno, $basket->basketname, $basket->note, $basket->booksellernote, $basket->contractnumber, $basket->booksellerid, $basket->deliveryplace, $basket->billingplace, $basket->is_standing, "ordering");
47
    my $created_basketno = C4::Acquisition::NewBasket(
46
my $retrieved_basket = Koha::Acquisition::Baskets->find({ basketno => $basket->basketno });
48
        $basket->booksellerid,   $basket->authorisedby,
47
$basket->create_items("ordering");
49
        $basket->basketname,     $basket->note,
48
is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader");
50
        $basket->booksellernote, $basket->contractnumber,
49
is( $basket->create_items, "ordering", "Should be able to set with object methods");
51
        $basket->deliveryplace,  $basket->billingplace,
50
is_deeply($retrieved_basket->unblessed, $basket->unblessed, "Correct basket found and updated");
52
        $basket->is_standing,    $basket->create_items
51
is( $retrieved_basket->effective_create_items, "ordering","We use basket create items if it is set");
53
    );
54
    my $created_basket = Koha::Acquisition::Baskets->find($created_basketno);
55
    is( $created_basket->basketno, $created_basketno,
56
        "Basket created by NewBasket matches db basket" );
57
    is( $basket->create_items, undef, "Create items value can be null" );
58
59
    t::lib::Mocks::mock_preference( 'AcqCreateItem', 'cataloguing' );
60
    is( $basket->effective_create_items,
61
        "cataloguing",
62
        "We use AcqCreateItem if basket create items is not set" );
63
    C4::Acquisition::ModBasketHeader(
64
        $basket->basketno,       $basket->basketname,
65
        $basket->note,           $basket->booksellernote,
66
        $basket->contractnumber, $basket->booksellerid,
67
        $basket->deliveryplace,  $basket->billingplace,
68
        $basket->is_standing,    "ordering"
69
    );
70
    my $retrieved_basket = Koha::Acquisition::Baskets->find( $basket->basketno );
71
    $basket->create_items("ordering");
72
    is( $retrieved_basket->create_items, "ordering", "Should be able to set with ModBasketHeader" );
73
    is( $basket->create_items, "ordering", "Should be able to set with object methods" );
74
    is_deeply( $retrieved_basket->unblessed,
75
        $basket->unblessed, "Correct basket found and updated" );
76
    is( $retrieved_basket->effective_create_items,
77
        "ordering", "We use basket create items if it is set" );
78
79
    $schema->storage->txn_rollback;
80
};
52
- 

Return to bug 15685