[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2425] trunk/t



Revision: 2425
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2425&view=rev
Author:   einhverfr
Date:     2008-12-09 23:03:14 +0000 (Tue, 09 Dec 2008)

Log Message:
-----------
LWP tests added

Modified Paths:
--------------
    trunk/t/63-lwp.t
    trunk/t/data/62-request-data

Modified: trunk/t/63-lwp.t
===================================================================
--- trunk/t/63-lwp.t	2008-12-05 18:30:17 UTC (rev 2424)
+++ trunk/t/63-lwp.t	2008-12-09 23:03:14 UTC (rev 2425)
@@ -1 +1,57 @@
-use Test::More skip_all => 'nothing implemented yet';
+use Test::More;
+use LWP;
+use LedgerSMB::Sysconfig;
+use HTTP::Cookies;
+
+if (!$ENV{'LSMB_TEST_LWP'}){
+	plan skipall => 'LWP Test not enabled!'
+} else {
+	plan 'no_plan';
+}
+
+my $host = $ENV{LSMB_BASE_URL} || 'http://localhost/ledger-smb/';
+if ($host !~ /\/$/){
+	$host .= "/";
+};
+$host =~ /http:\/\/([^\/]*)\//;
+$hostname = $1;
+print STDERR "hostname $hostname\n";
+my $db = $ENV{LSMB_TEST_NEW_DB} || $ENV{PGDATABASE};
+do 't/data/62-request-data'; # Import test case oashes
+my $browser = LWP::UserAgent->new( );
+$browser->credentials("$hostname:80", 'LedgerSMB', $ENV{LSMB_USER} => $ENV{LSMB_PASS});
+
+# cookie setup
+my $cookie = HTTP::Cookies->new(
+	"$LedgerSMB::Sysconfig::cookie_name" => "1:1:$db"
+);
+$browser->cookie_jar($cookie);
+
+for my $test (@$test_request_data){
+	next if $test->{_skip_lwp};
+	my $argstr = "";
+        my $module = "";
+	for $key (keys %$test){
+		if ($key eq 'module'){
+			$module = $test->{"$key"}
+		}
+		elsif ($key !~ /^\_/){
+			$argstr .= "&" . "$key=".$test->{"$key"};
+		}
+	}
+	$argstr =~ s/^&//;
+	my $url="$host$module?$argstr&company=$db";
+	my $response = $browser->get($url);
+	ok($response->is_success(), "$test->{_test_id} RESPONSE 200")
+		|| print STDERR "# " .$response->status_line() . ":$url\n";
+	if ($test->{format} eq 'PDF'){
+		cmp_ok($response->header('content-type'), 'eq', 
+			'application/pdf', "$test->{_test_id} PDF sent");
+	} else {
+		like($response->header('content-type'), qr/^text\/html/,
+			"$test->{_test_id} HTML sent");
+	}
+	if (ref($lwp_tests->{"$test->{_test_id}"}) eq 'CODE'){
+		&$lwp_tests->{"$test->{_test_id}"};
+	}
+}

Modified: trunk/t/data/62-request-data
===================================================================
--- trunk/t/data/62-request-data	2008-12-05 18:30:17 UTC (rev 2424)
+++ trunk/t/data/62-request-data	2008-12-09 23:03:14 UTC (rev 2425)
@@ -1,4 +1,5 @@
 use Test::More;
+our $lwp_tests = {};
 our $test_request_data = [
 	# AR/AP Transaction Screen Tests
 	{


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.