Rekonstruktion und usage-page
[kivitendo-erp.git] / t / lx-office.t
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006/2007
4 # Web http://www.lx-office.org
5 #
6 #=====================================================================
7 #
8 #  Author: Udo Spallek, Thomas Kasulke
9 #   Email: udono@gmx.net, tkasulke@linet-services.de
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24 #
25 # Main Test Module: 
26 # For collecting all the tests in nice Test::Harness environment.
27 # Study the README for Selenium Installation and testing process 
28 # and enjoy starting
29 # #perl t/lx-office.t
30 # against the unstable release
31 #======================================================================
32
33   use warnings FATAL => 'all';
34   use diagnostics;
35   use Carp;
36   use Test::Harness;
37
38   my %tests = ("all" => 't/selenium/TestAllTests.t',
39                "system" => 't/selenium/TestSystem.t',
40                "selling" => 't/selenium/TestSelling.t',
41                "masterdata" => 't/selenium/TestMasterData.t',
42                "testbed" => 't/selenium/TestCreateTestbed.t',
43                "admin" => 't/selenium/TestAdmin.t',
44                "accounting" => 't/selenium/TestAccounting.t',
45                "payments" => 't/selenium/TestPayments.t',
46                "printing" => 't/selenium/TestPrinting.t',
47                "programm" => 't/selenium/TestProgramm.t',
48                "reports" => 't/selenium/TestReports.t' );
49   my $testonly = 0;
50   my $nodb = 0;
51   my @totest;
52   
53   eval { require('t/lxtest.conf'); };
54   my %lxtest = %{ $lxtest } if ($lxtest);
55
56   sub usage
57   {
58     print "\n$0 --- creates testscenarios while using Selenium testcases for Lx-Office\n";
59     printf "\t\tusage: perl [PERLOPTIONS] $0 [--help] [OPTIONS] [ARGUMENTS]\n\t\t%s\n", "\xAF" x 6;
60     print "\t\t --help\t\tshow this usage\n\n";
61     printf "\t\toptions:\n\t\t%s\n", "\xAF" x 8;
62     print "\t\t  -masterdata\tonly runs testscripts for \"masterdata\"\n";
63     print "\t\t  -accounting\tonly runs testscripts for \"accounting\"\n";
64     print "\t\t  -system\tonly runs testscripts for \"system\"\n";
65     print "\t\t  -payments\tonly runs testscripts for \"payments\"\n";
66     print "\t\t  -programm\tonly runs testscripts for \"programm\"\n";
67     print "\t\t  -printing\tonly runs testscripts for \"printing\"\n";
68     print "\t\t  -reports\tonly runs testscripts for \"reports\"\n";
69     print "\t\t  -selling\tonly runs testscripts for \"selling\"\n";
70     print "\t\t  -purchase\tonly runs testscripts for \"purchase\"\n";
71     print "\t\t  -admin\tonly runs testscripts for \"administration\"\n";
72     print "\t\t  -testbed\tcreates a standardized test database\n";
73     print "\t\t  -nodb\t\tdoesn't create a db! Only use with \n\t\t\t\t--username, --userpasswd, --dbname, --dbport, --dbhost, --dbuser, --dbpasswd, --rootpasswd arguments!\n";
74     print "\t\t  -testsonly\tfinally shows all tests available only\n";
75     printf "\n\t\targuments:\n\t\t%s\n","\xAF" x 10;
76     print "\t\t  --username=\tuser login name\n";
77     print "\t\t  --userpasswd=\tuser login password\n";
78     print "\t\t  --dbname=\tname of used db (leave empty whether dbname is seleniumtestdatabase)\n";
79     print "\t\t  --dbport=\tport of used db (leave empty whether port is 5432)\n";
80     print "\t\t  --dbhost=\thost of used db (leave empty whether host is localhost [127.0.0.1])\n";
81     print "\t\t  --dbuser=\tdb username (leave empty whether name is postgres)\n";
82     print "\t\t  --dbpasswd=\tthe password for used db (leave empty while none)\n";
83     print "\t\t  --rootpasswd=\troot password for admin.pl login\n";
84     printf "\t\t  NOTE: Configuration in lxtest.conf will be temporaly overwritten by using this arguments!\n\t\t %s\n", "\xAF" x 6;
85     exit;
86   }
87   
88   while ( $#ARGV>=0 )
89   {
90     $_ = $ARGV[0];
91
92     if ( /^--help$/ ) { usage; last }
93     if ( /^-testonly$/) { $testonly = 1; shift; next }
94     if ( /^-nodb$/ ) { $nodb = 1; shift; next }
95     if ( /^-(masterdata)$/ ) { push @totest, $1; shift; next }
96     if ( /^-(system)$/ ) { push @totest, $1; shift; next }
97     if ( /^-(selling)$/ ) { push @totest, $1; shift; next }
98     if ( /^-(purchase)$/ ) { push @totest, $1; shift; next }
99     if ( /^-(testbed)$/ ) { push @totest, $1; shift; next }
100     if ( /^-(admin)$/ ) { push @totest, $1; shift; next }
101     if ( /^--username=(.*)$/ ) { $lxtest{testuserlogin} = $1; shift; next }
102     if ( /^--userpasswd=(.*)$/ ) { $lxtest{testuserpasswd} = $1; shift; next }
103     if ( /^--dbname=(.*)$/ ) { $lxtest{db} = $1; shift; next }
104     if ( /^--dbport=(.*)$/ ) { $lxtest{dbport} = $1; shift; next }
105     if ( /^--dbhost=(.*)$/ ) { $lxtest{dbhost} = $1; shift; next }
106     if ( /^--dbuser=(.*)$/ ) { $lxtest{dbuser} = $1; shift; next }
107     if ( /^--dbpasswd=(.*)$/ ) { $lxtest{dbpasswd} = $1; shift; next }
108     if ( /^--rootpasswd=(.*)$/ ) { $lxtest{rpw} = $1; shift; next }
109     if ( /^([A-Z].*)$/ ) { push @totest, shift; next }
110     if ( /^-/ ) {
111         print STDERR "$0: ERROR: unrecognized option '$_' ?\n";
112         usage;
113     }
114     last;
115   }
116   
117   open TEMPCONF, "+>/tmp/lxtest-temp.conf";
118   print TEMPCONF '$lxtest = {'."\n";
119   foreach (keys(%lxtest)) {
120     print TEMPCONF '"' . $_ . '" => "' . $lxtest{$_} . "\",\n";
121   }
122   print TEMPCONF '};';
123   close TEMPCONF;
124
125   my $testscriptdir = 't/selenium/testscripts/';
126   opendir(ROOT, $testscriptdir);
127   foreach my $dir ( readdir( ROOT ) ) {
128     if(-d $testscriptdir . $dir && $dir ne "begin" && $dir ne "end" && $dir ne "..") {
129       opendir(DIR, $testscriptdir . $dir . "/begin");
130       foreach ( readdir(DIR) ) {
131         $tests{ substr ( substr( $_, 4 ), 0, -2 ) } = $testscriptdir . ($dir eq "." ? "" : $dir . "/") . "begin/" . $_ if ( $_ =~ /^\w\d\d\d.*\.t$/ );
132       }
133       closedir(DIR);
134       opendir(DIR, $testscriptdir . $dir . "/end");
135       foreach (readdir(DIR)) {
136         $tests{ substr ( substr( $_, 4 ), 0, -2 ) } = $testscriptdir . ($dir eq "." ? "" : $dir . "/") . "end/" . $_ if ( $_ =~ /^\w\d\d\d.*\.t$/ );
137       }
138       closedir(DIR);
139     }
140   }
141   closedir(ROOT);
142   
143   push @totest, "all" if(!$totest[0]);
144   
145
146 ## Backendtests:
147 #  &runtests(
148 #  );  
149   
150
151 ## Frontendtests:
152   
153   foreach (@totest) {
154     &runtests(
155       $tests{$_},
156     ) if (!$testonly);
157   }
158   if($testonly) {
159     printf "\tFollowing testscripts are present:\n\t%s\n","\xAF" x 34;;
160     foreach (sort(keys(%tests))) {
161       print "\t\t" . $_ ."\n" if( /^[A-Z].*$/ );
162     }
163     printf "\n\t\%s\n\t%s\n","Be ensure, that usage is promitted by login and db status!","\xAF" x 58;
164   }
165
166 exit 1;