Bug 9259: Use is instead of is_deeply
[koha.git] / t / db_dependent / BackgroundJob.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4 use C4::Auth;
5 use CGI qw ( -utf8 );
6 use Test::More tests => 18;
7
8 BEGIN {
9     use_ok('C4::BackgroundJob');
10 }
11 my $query = new CGI;
12
13 # Generate a session id
14 my $dbh     = C4::Context->dbh;
15 $dbh->{AutoCommit} = 1;
16 $dbh->{RaiseError} = 1;
17
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" );
24
25 $job->name("George");
26 is( $job->name, "George", "testing name" );
27
28 $job->invoker("enjoys");
29 is( $job->invoker, "enjoys", "testing invoker" );
30
31 $job->progress("testing");
32 is( $job->progress, "testing", "testing progress" );
33
34 ok( $job->status, "testing status" );
35
36 $job->size("56");
37 is( $job->size, "56", "testing size" );
38
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' );
43
44 $job->set( { size => 666 } );
45 is( $job->size, "56", '->set() does not scribble over private object data' );
46
47 $job->finish("finished");
48 is( $job->status, 'completed', "testing finished" );
49
50 ok( $job->results );    #Will return undef unless finished
51
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' );