3 use Test::More tests => 17;
4 use Test::WWW::Mechanize;
6 use_ok("CXGN::DB::Connection");
7 use_ok("CXGN::People::Person");
9 my $dbh = CXGN::DB::Connection->new();
11 my $m = Test::WWW::Mechanize->new();
13 my $server = $ENV{SGN_TEST_SERVER}
14 || die "Need SGN_TEST_SERVER environment variable set";
16 # generate a new user for testing purposes
17 # (to be deleted right afterwards)
19 if( my $u_id = CXGN::People::Person->get_person_by_username( $dbh, "testusername" ) ) {
20 CXGN::People::Person->new( $dbh, $u_id )->hard_delete;
23 my $p = CXGN::People::Person->new($dbh);
24 $p->set_first_name("testfirstname");
25 $p->set_last_name("testlastname");
26 my $p_id = $p->store();
28 my $login = CXGN::People::Login->new( $dbh, $p_id );
29 $login->set_username("testusername");
30 $login->set_password("testpassword");
31 $login->set_user_type("user");
37 my $u_id = CXGN::People::Person->get_person_by_username( $dbh, "testusername" );
38 my $u = CXGN::People::Person->new( $dbh, $u_id );
40 is( $u->get_first_name(), "testfirstname", "Test first name test" );
44 $m->get_ok("$server/solpeople/top-level.pl");
45 $m->content_contains("Login");
50 username => 'testusername',
55 $m->submit_form_ok( \%form, "Login form submission test" );
57 #$m->get_ok("$server/solpeople/top-level.pl");
59 #print STDERR $m->content();
60 $m->content_contains("testfirstname");
62 # check if logout works
64 $m->get_ok( "$server/solpeople/login.pl?logout=yes",
65 "Request logout page" );
67 $m->content_contains("You have successfully logged out");
71 $login->set_user_type("curator");
75 $m->get("$server/solpeople/login.pl");
76 $m->submit_form_ok( \%form, "Login as curator form submission" );
77 $m->get_ok("$server/solpeople/top-level.pl");
78 $m->content_contains( "Curator Tools", "Curator tools presence test" );
80 $m->get_ok("$server/solpeople/login.pl?logout=yes");
81 $m->content_contains("You have successfully logged out");
83 # try logging in with wrong password
85 $form{fields}->{pd} = "blablabla"; # enter wrong password
86 $m->get_ok("$server/solpeople/login.pl");
87 $m->submit_form_ok( \%form, "Submit wrong password test" );
88 $m->content_contains("Incorrect username or password");
91 # delete the test user from the database (even if the test died)
93 END { $u->hard_delete() if $u }