Bug 8216: Allow SIP modules to pass critic tests
[koha.git] / C4 / SIP / t / SIPtest.pm
index 193aa5b..d834c5b 100644 (file)
@@ -13,18 +13,19 @@ BEGIN {
        %EXPORT_TAGS = (
                auth  => [qw(&api_auth)],
                basic => [qw($datepat $textpat $login_test $sc_status_test
-                                               $instid $currency $server $username $password)],
+                                               $instid $instid2 $currency $server $username $password)],
+    # duplicate user1 and item1 as user2 and item2
+    # w/ tags like $user2_pin instead of $user_pin
                user1 => [qw($user_barcode  $user_pin  $user_fullname  $user_homeaddr  $user_email
                                                $user_phone  $user_birthday  $user_ptype  $user_inet)],
+        user2 => [qw($user2_barcode  $user._pin  $user2_fullname  $user2_homeaddr  $user2_email
+                        $user2_phone  $user2_birthday  $user2_ptype  $user2_inet)],
                item1 => [qw($item_barcode  $item_title  $item_owner )],
+        item2 => [qw($item2_barcode  $item2_title  $item2_owner )],
+    # we've got item3_* also
+        item3 => [qw($item3_barcode  $item3_title  $item3_owner )],
                diacritic => [qw($item_diacritic_barcode $item_diacritic_title $item_diacritic_owner)],
        );
-       # duplicate user1 and item1 as user2 and item2
-       # w/ tags like $user2_pin instead of $user_pin
-       foreach my $tag (qw(user item)) {
-               my @tags = @{$EXPORT_TAGS{$tag.'1'}};   # fresh array avoids side affect in map
-               push @{$EXPORT_TAGS{$tag.'2'}}, map {s/($tag)\_/${1}2_/;$_} @tags;
-       }
        # From perldoc Exporter
        # Add all the other ":class" tags to the ":all" class, deleting duplicates
        my %seen;
@@ -47,15 +48,17 @@ use Sip::Constants qw(:all);
 use C4::Auth qw(&check_api_auth);
 use C4::Context;
 
+# TODO: just read SIPconfig.xml and extract what we can....
 # 
 # Configuration parameters to run the test suite
 #
-our $instid   = 'CPL'; # 'UWOLS';
+our $instid   = 'CPL';  # branchcode
+our $instid2  = 'FPL';  # branchcode
 our $currency = 'USD'; # 'CAD';
 our $server   = 'localhost:6001';      # Address of the SIP server
 
-# SIP username and password to connect to the server.  See the
-# SIP config.xml for the correct values.
+# SIP username and password to connect to the server.
+# See SIPconfig.xml for the correct values.
 our $username = 'term1';
 our $password = 'term1';
 
@@ -94,6 +97,11 @@ our $item2_barcode = '502326000011';
 our $item2_title   = 'The biggest, smallest, fastest, tallest things you\'ve ever heard of /';
 our $item2_owner   = 'CPL';
 
+# A third valid item
+our $item3_barcode = '502326000240';
+our $item3_title   = 'The girl who owned a city /';
+our $item3_owner   = 'FPL';
+
 # An item with a diacritical in the title
 our $item_diacritic_barcode = '502326001030';
 our $item_diacritic_titlea  = 'Hari Poṭer u-geviʻa ha-esh /';
@@ -173,10 +181,14 @@ sub one_msg {
 
     # If reading or writing fails, then the server's dead,
     # so there's no point in continuing.
-    if (!write_msg({seqno => $seqno}, $test->{msg}, $sock)) {
-               BAIL_OUT("Write failure in $test->{id}");
-    } elsif (!($resp = <$sock>)) {
-               BAIL_OUT("Read failure in $test->{id}");
+    if ( !write_msg( { seqno => $seqno }, $test->{msg}, $sock ) ) {
+        BAIL_OUT("Write failure in $test->{id}");
+    }
+
+    my $rv = sysread( $sock, $resp, 10000000 ); # 10000000 is a big number
+
+    if ( !$rv ) {
+        BAIL_OUT("Read failure in $test->{id}");
     }
 
        chomp($resp);
@@ -225,7 +237,7 @@ sub one_msg {
     return;
 }
 
-sub api_auth() {
+sub api_auth {
        # AUTH
        $ENV{REMOTE_USER} = $username;
        my $query = CGI->new();