1 package KohaTest::Acquisition;
2 use base qw( KohaTest );
15 sub testing_class { 'C4::Acquisition' };
18 sub methods : Test( 1 ) {
20 my @methods = qw( GetBasket
38 can_ok( $self->testing_class, @methods );
41 =head3 create_new_basket
43 creates a baseket by creating an order with no baseket number.
50 returns: baseket number, order number
56 sub create_new_basket {
59 $param{'authorizedby'} = $self->{'memberid'} unless exists $param{'authorizedby'};
60 $param{'invoice'} = 123 unless exists $param{'invoice'};
62 my $today = sprintf( '%04d-%02d-%02d',
63 localtime->year() + 1900,
67 # I actually think that this parameter is unused.
68 $param{'date'} = $today unless exists $param{'date'};
70 $self->add_biblios( add_items => 1 );
71 ok( scalar @{$self->{'biblios'}} > 0, 'we have added at least one biblio' );
73 my $rand = int(rand(10000));
74 my $basketno = NewBasket( $self->{'booksellerid'}, $param{'authorizedby'}, "Basket $rand");
75 # $basketnote, $basketbooksellernote, $basketcontractnumber );
76 # The following keys are used: "biblionumber", "title", "basketno", "quantity", "notes", "biblioitemnumber", "rrp", "ecost", "gst", "unitprice", "subscription", "sort1", "sort2", "booksellerinvoicenumber", "listprice", "budgetdate", "purchaseordernumber", "branchcode", "booksellerinvoicenumber", "bookfundid".
77 my $budget_id = AddBudget( { budget_name => "Budget $rand" } );
78 my ( undef, $ordernumber ) = NewOrder( {
79 basketno => $basketno,
80 budget_id => $budget_id,
81 biblionumber => $self->{'biblios'}[0],
83 bookfundid => $self->{'bookfundid'},
86 booksellerinvoicenumber => $param{'invoice'},
88 ok( $basketno, "my basket number is $basketno" );
89 ok( $ordernumber, "my order number is $ordernumber" );
91 my $order = GetOrder( $ordernumber );
92 is( $order->{'ordernumber'}, $ordernumber, 'got the right order' )
93 or diag( Data::Dumper->Dump( [ $order ], [ 'order' ] ) );
95 is( $order->{'budgetdate'}, $today, "the budget date is $today" );
97 # XXX should I stuff these in $self?
98 return ( $basketno, $ordernumber );
103 sub enable_independant_branches {
106 my $member = GetMember( 'borrowernumber' =>$self->{'memberid'} );
108 C4::Context::set_userenv( 0, # usernum
109 $self->{'memberid'}, # userid
111 undef, # userfirstname
113 $member->{'branchcode'}, # userbranch
116 undef, # emailaddress
117 undef, # branchprinter
120 # set a preference. There's surely a method for this, but I can't find it.
121 my $retval = C4::Context->dbh->do( q(update systempreferences set value = '1' where variable = 'IndependentBranches') );
122 ok( $retval, 'set the preference' );
124 ok( C4::Context->userenv, 'usernev' );
125 isnt( C4::Context->userenv->{flags}, 1, 'flag != 1' )
126 or diag( Data::Dumper->Dump( [ C4::Context->userenv ], [ 'userenv' ] ) );
128 is( C4::Context->userenv->{branch}, $member->{'branchcode'}, 'we have set the right branch in C4::Context: ' . $member->{'branchcode'} );
132 sub disable_independant_branches {
135 my $retval = C4::Context->dbh->do( q(update systempreferences set value = '0' where variable = 'IndependentBranches') );
136 ok( $retval, 'set the preference back' );