6 use Test
::More tests
=> 18;
9 use_ok
('C4::BackgroundJob');
13 # Generate a session id
14 my $dbh = C4
::Context
->dbh;
15 $dbh->{AutoCommit
} = 0;
16 $dbh->{RaiseError
} = 1;
18 my $session = C4
::Auth
::get_session
;
20 my $sessionID = $session->id;
22 ok
( $job = C4
::BackgroundJob
->new($sessionID), "making job" );
23 ok
( $job->id, "fetching id number" );
26 is
( $job->name, "George", "testing name" );
28 $job->invoker("enjoys");
29 is
( $job->invoker, "enjoys", "testing invoker" );
31 $job->progress("testing");
32 is
( $job->progress, "testing", "testing progress" );
34 ok
( $job->status, "testing status" );
37 is
( $job->size, "56", "testing size" );
39 ok
( C4
::BackgroundJob
->fetch( $sessionID, $job->id ), "testing fetch" );
40 $job->set( { key1
=> 'value1', key2
=> 'value2' } );
41 is
( $job->get('key1'), 'value1', 'fetched extra value for key key1' );
42 is
( $job->get('key2'), 'value2', 'fetched extra value for key key2' );
44 $job->set( { size
=> 666 } );
45 is
( $job->size, "56", '->set() does not scribble over private object data' );
47 $job->finish("finished");
48 is
( $job->status, 'completed', "testing finished" );
50 ok
( $job->results ); #Will return undef unless finished
52 my $second_job = C4
::BackgroundJob
->new( $sessionID, "making new job" );
53 $session = C4
::Auth
::get_session
( $job->{sessionID
} );
54 is
( ref( $session->param( 'job_' . $job->id ) ), "C4::BackgroundJob", 'job_$jobid should be a C4::BackgroundJob for uncleared job 1' );
55 is
( ref( $session->param( 'job_' . $second_job->id ) ), "C4::BackgroundJob", 'job_$jobid should be a C4::BackgroundJob for uncleared job 2' );
57 $session = C4
::Auth
::get_session
( $job->{sessionID
} );
58 is
( $session->param( 'job_' . $job->id ), undef, 'After clearing it, job 1 should not exist anymore in the session' );
59 is
( ref( $session->param( 'job_' . $second_job->id ) ), "C4::BackgroundJob", 'After clear on job 1, job 2 should still be a C4::BackgroundJob' );