Bug 8216: Allow SIP modules to pass critic tests
[koha.git] / C4 / SIP / t / SIPtest.pm
index 9f0efeb..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';
 
@@ -69,7 +72,7 @@ our $user_fullname= 'Edna Acosta';
 our $user_homeaddr= '7896 Library Rd\.';
 our $user_email   = 'patron\@liblime\.com';
 our $user_phone   = '\(212\) 555-1212';
-our $user_birthday= '1980-04-24';
+our $user_birthday= '19800424';   # YYYYMMDD, ANSI X3.30
 our $user_ptype   = 'PT';
 our $user_inet    = 'Y';
 
@@ -80,7 +83,7 @@ our $user2_fullname= 'Jamie White';
 our $user2_homeaddr= '937 Library Rd\.';
 our $user2_email   = 'patron\@liblime\.com';
 our $user2_phone   = '\(212\) 555-1212';
-our $user2_birthday= '1950-04-22';
+our $user2_birthday= '19500422';    # YYYYMMDD, ANSI X3.30
 our $user2_ptype   = 'T';
 our $user2_inet    = 'Y';
 
@@ -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,14 +181,19 @@ 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);
        $resp =~ tr/\cM//d;
+       $resp =~ s/\015?\012$//;
        chomp($resp);
 
        if (!verify_cksum($resp)) {
@@ -224,7 +237,7 @@ sub one_msg {
     return;
 }
 
-sub api_auth() {
+sub api_auth {
        # AUTH
        $ENV{REMOTE_USER} = $username;
        my $query = CGI->new();
@@ -248,7 +261,7 @@ sub run_sip_tests {
     my ($sock, $seqno);
 
     $Sip::error_detection = 1;
-    $/ = "\r";
+    $/ = "\015\012";   # must use correct record separator
 
     $sock = new IO::Socket::INET(PeerAddr => $server,
                                 Type     => SOCK_STREAM);