File: 20-Common-CGI.t

package info (click to toggle)
lemonldap-ng 1.1.2-5%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,500 kB
  • sloc: perl: 22,090; makefile: 592; sh: 113; php: 6; sql: 5
file content (98 lines) | stat: -rw-r--r-- 2,917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl Lemonldap-NG-Manager.t'

#########################

# change 'tests => 1' to 'tests => last_test_to_print';
package My::Portal;

use strict;
use Test::More tests => 10;
use_ok('Lemonldap::NG::Common::CGI');

#our @ISA = qw('Lemonldap::NG::Common::CGI');
use base 'Lemonldap::NG::Common::CGI';

sub mySubtest {
    return 'OK1';
}

sub abort {
    shift;
    $, = '';
    print STDERR @_;
    die 'abort has been called';
}

sub quit {
    2;
}

our $param;

sub param {
    return $param;
}

sub soapfunc {
    return 'SoapOK';
}

our $buf;
our $lastpos = 0;

sub diff {
    my $str = $buf;
    $str =~ s/^.{$lastpos}//s if ($lastpos);
    $str =~ s/\r//gs;
    $lastpos = length $buf;
    return $str;
}

SKIP: {
    eval "use IO::String;";
    skip "IO::String not installed", 9 if ($@);
    tie *STDOUT, 'IO::String', $buf;

#########################

    # Insert your test code below, the Test::More module is use()ed here so read
    # its man page ( perldoc Test::More ) for help writing this test script.

    my $cgi;

    $ENV{SCRIPT_NAME}     = '/test.pl';
    $ENV{SCRIPT_FILENAME} = 't/20-Common-CGI.t';
    $ENV{REQUEST_METHOD}  = 'GET';
    $ENV{REQUEST_URI}     = '/';
    $ENV{QUERY_STRING}    = '';

    #$cgi = CGI->new;
    ok( ( $cgi = Lemonldap::NG::Common::CGI->new() ), 'New CGI' );
    bless $cgi, 'My::Portal';

    # Test header_public
    ok( $buf = $cgi->header_public('t/20-Common-CGI.t'), 'header_public' );
    ok( $buf =~ /Cache-control: public; must-revalidate; max-age=\d+\r?\n/s,
        'Cache-Control' );
    ok( $buf =~ /Last-modified: /s, 'Last-Modified' );

    # Test _sub mechanism
    ok( $cgi->_sub('mySubtest') eq 'OK1', '_sub mechanism 1' );
    $cgi->{mySubtest} = sub { return 'OK2' };
    ok( $cgi->_sub('mySubtest') eq 'OK2', '_sub mechanism 2' );

    # SOAP
    eval { require SOAP::Lite };
    skip "SOAP::Lite is not installed, so CGI SOAP functions will not work", 3
      if ($@);
    $ENV{HTTP_SOAPACTION} =
      'http://localhost/Lemonldap/NG/Common/CGI/SOAPService#soapfunc';
    $param =
'<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><soapfunc xmlns="http://localhost/Lemonldap/NG/Common/CGI/SOAPService"><var xsi:type="xsd:string">fr</var></soapfunc></soap:Body></soap:Envelope>';
    ok( $cgi->soapTest('soapfunc') == 2, 'SOAP call exit fine' );
    my $tmp = diff();
    ok( $tmp =~ /^Status: 200/s, 'HTTP response 200' );
    ok( $tmp =~ /<result xsi:type="xsd:string">SoapOK<\/result>/s,
        'result of SOAP call' );
}