Merge branch 'master' into topic/dt_feature_search
[sgn.git] / t / legacy / integration / solpeople / login.t
blob6e01b521b85042dc78c2afd832b1996762ec3fc4
1 use strict;
2 use warnings;
4 use Test::More;
5 use lib 't/lib';
6 use SGN::Test::WWW::Mechanize;
8 my $m = SGN::Test::WWW::Mechanize->new();
10 plan skip_all => 'test requires at least "local" test level'
11   unless $m->can_test_level('local');
13 use_ok("CXGN::People::Person");
15 $m->get_ok('/');
17 my $dbh = $m->context->dbc->dbh();
19 # generate a new user for testing purposes
20 # (to be deleted right afterwards)
22 if( my $u_id = CXGN::People::Person->get_person_by_username( $dbh, "testusername" ) ) {
23     CXGN::People::Person->new( $dbh, $u_id )->hard_delete;
26 my $p = CXGN::People::Person->new($dbh);
27 $p->set_first_name("testfirstname");
28 $p->set_last_name("testlastname");
29 $p->set_organization("testorganization");
30 my $p_id = $p->store();
32 my $login = CXGN::People::Login->new( $dbh, $p_id );
33 $login->set_username("testusername");
34 $login->set_password("testpassword");
36 $login->set_user_type("user");
38 $login->store();
40 my $u_id = CXGN::People::Person->get_person_by_username( $dbh, "testusername" );
41 my $u = CXGN::People::Person->new( $dbh, $u_id );
42 END {
43     if( $u ) {
44         $u->hard_delete();
45         #$dbh->commit; #unless $u->get_dbh->dbh_param('AutoCommit');
46     }
49 is( $u->get_first_name(), "testfirstname", "Test first name test" );
51 # check basic login
53 $m->get_ok("/solpeople/top-level.pl");
54 $m->content_contains("Login");
56 my %form = (
57     form_name => 'login',
58     fields    => {
59         username => 'testusername',
60         pd       => 'testpassword',
61     },
62    );
64 $m->submit_form_ok( \%form, "Login form submission test" );
65 $m->content_contains("testfirstname");
67 $m->get_ok('/solpeople/top-level.pl');
69 $m->follow_link_ok({ url_regex => qr/personal-info\.pl/ });
71 $m->submit_form_ok({
72         form_number => 2,
73         fields => {
74             first_name         => "foo",
75             last_name          => "manchu",
76             research_interests => "Ketchup",
77             action             => "store",
78             sp_person_id       => $p_id,
79         },
80     },    "Can change info on personal-info.pl",
83 # check if logout works
85 $m->get_ok( "/solpeople/login.pl?logout=yes",
86             "Request logout page" );
88 $m->content_contains("You have successfully logged out");
90 # login as a curator
92 $login->set_user_type("curator");
93 $login->store();
95 $m->get("/solpeople/login.pl");
96 $m->submit_form_ok( \%form, "Login as curator form submission" );
97 $m->get_ok("/solpeople/top-level.pl");
98 $m->content_contains( "Curator Tools", "Curator tools presence test" );
100 $m->get_ok("/solpeople/login.pl?logout=yes");
101 $m->content_contains("You have successfully logged out");
103 # try logging in with wrong password
105 $form{fields}->{pd} = "blablabla"; # enter wrong password
106 $m->get_ok("/solpeople/login.pl");
107 $m->submit_form_ok( \%form, "Submit wrong password test" );
108 $m->content_contains("Incorrect username or password");
110 # delete the test user from the database (even if the test died)
112 END {
113     if( $dbh and  my $u_id = CXGN::People::Person->get_person_by_username( $dbh, "testusername" ) ) {
114         CXGN::People::Person->new( $dbh, $u_id )->hard_delete;
115     }
117 done_testing;