Bug 27597: Remove leading colon in ES query
[koha-ffzg.git] / t / Koha / Script.t
old mode 100644 (file)
new mode 100755 (executable)
index 7c758f4..527ff24
 
 use Modern::Perl;
 
-use Test::More tests => 3;
+use Test::More tests => 4;
+use Test::Exception;
 
 BEGIN { use_ok('Koha::Script') }
 
+use File::Basename;
+
 use C4::Context;
 
 my $userenv = C4::Context->userenv;
@@ -33,11 +36,14 @@ is_deeply(
         'cardnumber'    => undef,
         'firstname'     => 'CLI',
         'branchname'    => undef,
-        'branchprinter' => undef,
         'emailaddress'  => undef,
         'number'        => undef,
         'shibboleth'    => undef,
-        'branch'        => undef
+        'branch'        => undef,
+        'desk_id'       => undef,
+        'desk_name'     => undef,
+        'register_id'   => undef,
+        'register_name' => undef,
     },
     "Context userenv set correctly with no flags"
 );
@@ -45,4 +51,39 @@ is_deeply(
 my $interface = C4::Context->interface;
 is( $interface, 'commandline', "Context interface set correctly with no flags" );
 
+subtest 'lock_exec() tests' => sub {
+
+    plan tests => 3;
+
+    # Launch the sleep script
+    my $pid = fork();
+    if ( $pid == 0 ) {
+        system( dirname(__FILE__) . '/sleep.pl 2>&1' );
+        exit;
+    }
+
+    sleep 1; # Make sure we start after the fork
+    my $command = dirname(__FILE__) . '/sleep.pl';
+    my $result  = `$command 2>&1`;
+
+    like( $result, qr{Unable to acquire the lock.*}, 'Exception found' );
+
+    $pid = fork();
+    if ( $pid == 0 ) {
+        system( dirname(__FILE__) . '/sleep.pl 2>&1' );
+        exit;
+    }
+
+    sleep 1; # Make sure we start after the fork
+    $command = dirname(__FILE__) . '/wait.pl';
+    $result  = `$command 2>&1`;
+
+    is( $result, 'YAY!', 'wait.pl successfully waits for the lock' );
+
+    throws_ok
+        { Koha::Script->new({ lock_name => 'blah' }); }
+        'Koha::Exceptions::MissingParameter',
+        'Not passing the "script" parameter makes it raise an exception';
+};
+
 1;