js packs really should be served with a relative url
[sgn.git] / t / validate / gem.t
blobb14cb9038eb96971a0bc5e1ef7d4b402f1cb8efd
1 use strict;
2 use warnings;
4 use FindBin;
5 use lib 't/lib';
6 use SGN::Test qw/validate_urls/;
7 use Test::More;
9 use SGN::Test::WWW::Mechanize;
10 use CXGN::GEM::Schema;
12 ## define a %url hash
14 my %urls = ();
16 my $base_url = $ENV{SGN_TEST_SERVER};
17 my $mech = SGN::Test::WWW::Mechanize->new;
19 ## This test are local test, so it will use the with_test_level function
21 $mech->with_test_level( local => sub {
23     ## First take variables for the test from the database ##
25     my @schema_list = ('gem', 'biosource', 'metadata', 'public');
26     my $schema_list = join(',', @schema_list);
27     my $set_path = "SET search_path TO $schema_list";
29     my $dbh = $mech->context()->dbc()->dbh();
30     
31     my $schema = CXGN::GEM::Schema->connect( sub { $dbh }, 
32                                              {on_connect_do => $set_path} );
38     ## WWW. GEM SEARCH TEST ###
40     $urls{"gem search page for templates"} = "/search/direct_search.pl?search=template";
41     $urls{"gem search page for experiments"} = "/search/direct_search.pl?search=experiment";
42     $urls{"gem search page for platforms"} = "/search/direct_search.pl?search=platform";
43     
44     ## WWW. RESULT AND DETAIL PAGES ###
46     ## TEMPLATE ##
47     ## Take a template, an experiment name and a platform name
49     my ($template_row) = $schema->resultset('GeTemplate')
50                                 ->search( undef, 
51                                           { 
52                                               order_by => {-asc => 'template_id'}, 
53                                               rows     => 1, 
54                                           }
55                                         );
57     ## Now it will test the expected gem result web-page if there is at least one row 
58     ## in the database. If not, it will test the error page
60     if (defined $template_row) {
62         my $template_id = $template_row->get_column('template_id');
63         my $template_name = $template_row->get_column('template_name');
64         
65         $urls{'gem results page for templates'} = "/search/gem_template_search.pl?w616_template_parameters=$template_name";
66         $urls{'gem template page'} = "/gem/template.pl?id=$template_id";
67         $urls{'gem template page (name)'} = "/gem/template.pl?name=$template_name";     
68     }
70     ## EXPERIMENT ##
72     my ($experiment_row) = $schema->resultset('GeExperiment')
73                                 ->search( undef, 
74                                           { 
75                                               order_by => {-asc => 'experiment_id'}, 
76                                               rows     => 1, 
77                                           }
78                                         );
80     ## Now it will test the expected gem result web-page if there is at least one row 
81     ## in the database. If not, it will test the error page
83     if (defined $experiment_row) {
85         my $experiment_id = $experiment_row->get_column('experiment_id');
86         my $experiment_name = $experiment_row->get_column('experiment_name');
87         
88         my @exp_frags = split(/ /, $experiment_name);
89         my $partial_name = $exp_frags[0];
91         $urls{'gem results page for experiments'} = "/search/gem_experiment_search.pl?w932_experiment_parameters=$partial_name";
92         $urls{'gem experiment page'} = "/gem/experiment.pl?id=$experiment_id";
93         $urls{'gem experiment page (name)'} = "/gem/experiment.pl?name=$experiment_name";       
94     }
96     ## PLATFORM ##
98     my ($platform_row) = $schema->resultset('GePlatform')
99                                 ->search( undef, 
100                                           { 
101                                               order_by => {-asc => 'platform_id'}, 
102                                               rows     => 1, 
103                                           }
104                                         );
106     if (defined $platform_row) {
108         my $platform_id = $platform_row->get_column('platform_id');
109         my $platform_name = $platform_row->get_column('platform_name');
110         
111         my @plat_frags = split(/ /, $platform_name);
112         my $plat_partial_name = $plat_frags[0];
114         $urls{'gem results page for platform'} = "/search/gem_experiment_search.pl?w932_template_parameters=$plat_partial_name";
115         $urls{'gem platform page'} = "/gem/platform.pl?id=$platform_id";
116         $urls{'gem platform page (name)'} = "/gem/platform.pl?name=$platform_name";     
117     }
119     ## EXPERIMENTAL DESIGN ##
121     my ($experimental_design_row) = $schema->resultset('GeExperimentalDesign')
122                                 ->search( undef, 
123                                           { 
124                                               order_by => {-asc => 'experimental_design_id'}, 
125                                               rows     => 1, 
126                                           }
127                                         );
129     if (defined $experimental_design_row) {
131         my $expdesign_id = $experimental_design_row->get_column('experimental_design_id');
132         my $expdesign_name = $experimental_design_row->get_column('experimental_design_name');
134         $urls{'gem detail page for experimental design'} = "/gem/experimental_design.pl?id=$expdesign_id";
135         $urls{'gem detail page for experimental design (name)'} = "/gem/experimental_design.pl?name=$expdesign_name";   
136     }
138     ## TARGET ##
140     my ($target_row) = $schema->resultset('GeTarget')
141                                 ->search( undef, 
142                                           { 
143                                               order_by => {-asc => 'target_id'}, 
144                                               rows     => 1, 
145                                           }
146                                         );
148     if (defined $target_row) {
150         my $target_id = $target_row->get_column('target_id');
151         my $target_name = $target_row->get_column('target_name');
153         $urls{'gem detail page for target'} = "/gem/target.pl?id=$target_id";
154         $urls{'gem detail page for target (name)'} = "/gem/target.pl?name=$target_name";        
155     }
156     validate_urls(\%urls, $ENV{ITERATIONS} || 1 );
162 done_testing;