Bug 14778: Install fixtures for t/Biblio.t
[koha.git] / t / db_dependent / BackgroundJob.t
blob3cc5348bbf9b8f8bcbbacf7563d083cb03ddddcd
1 #!/usr/bin/perl
3 use Modern::Perl;
4 use C4::Auth;
5 use CGI qw ( -utf8 );
6 use Test::More tests => 18;
8 BEGIN {
9 use_ok('C4::BackgroundJob');
11 my $query = new CGI;
13 # Generate a session id
14 my $dbh = C4::Context->dbh;
15 $dbh->{AutoCommit} = 1;
16 $dbh->{RaiseError} = 1;
18 my $session = C4::Auth::get_session;
19 $session->flush;
20 my $sessionID = $session->id;
21 my $job;
22 ok( $job = C4::BackgroundJob->new($sessionID), "making job" );
23 ok( $job->id, "fetching id number" );
25 $job->name("George");
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" );
36 $job->size("56");
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' );
56 $job->clear;
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' );