Merge branch 'master' into topic/secretom
[sgn.git] / t / validate / gem.t
blob28a40930515aa634d10ea2ac3c64beac96a9a353
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);
28     my $dbh = $mech->context()->dbc()->dbh();
30     my $schema = $mech->context->dbic_schema('CXGN::GEM::Schema');
32     ## WWW. GEM SEARCH TEST ###
34     $urls{"gem search page for templates"} = "/search/direct_search.pl?search=template";
35     $urls{"gem search page for experiments"} = "/search/direct_search.pl?search=experiment";
36     $urls{"gem search page for platforms"} = "/search/direct_search.pl?search=platform";
37     
38     ## WWW. RESULT AND DETAIL PAGES ###
40     ## TEMPLATE ##
41     ## Take a template, an experiment name and a platform name
43     my ($template_row) = $schema->resultset('GeTemplate')
44                                 ->search( undef, 
45                                           { 
46                                               order_by => {-asc => 'template_id'}, 
47                                               rows     => 1, 
48                                           }
49                                         );
51     ## Now it will test the expected gem result web-page if there is at least one row 
52     ## in the database. If not, it will test the error page
54     if (defined $template_row) {
56         my $template_id = $template_row->get_column('template_id');
57         my $template_name = $template_row->get_column('template_name');
58         
59         $urls{'gem results page for templates'} = "/search/gem_template_search.pl?w616_template_parameters=$template_name";
60         $urls{'gem template page'} = "/gem/template.pl?id=$template_id";
61         $urls{'gem template page (name)'} = "/gem/template.pl?name=$template_name";     
62     }
64     ## EXPERIMENT ##
66     my ($experiment_row) = $schema->resultset('GeExperiment')
67                                 ->search( undef, 
68                                           { 
69                                               order_by => {-asc => 'experiment_id'}, 
70                                               rows     => 1, 
71                                           }
72                                         );
74     ## Now it will test the expected gem result web-page if there is at least one row 
75     ## in the database. If not, it will test the error page
77     if (defined $experiment_row) {
79         my $experiment_id = $experiment_row->get_column('experiment_id');
80         my $experiment_name = $experiment_row->get_column('experiment_name');
81         
82         my @exp_frags = split(/ /, $experiment_name);
83         my $partial_name = $exp_frags[0];
85         $urls{'gem results page for experiments'} = "/search/gem_experiment_search.pl?w932_experiment_parameters=$partial_name";
86         $urls{'gem experiment page'} = "/gem/experiment.pl?id=$experiment_id";
87         $urls{'gem experiment page (name)'} = "/gem/experiment.pl?name=$experiment_name";       
88     }
90     ## PLATFORM ##
92     my ($platform_row) = $schema->resultset('GePlatform')
93                                 ->search( undef, 
94                                           { 
95                                               order_by => {-asc => 'platform_id'}, 
96                                               rows     => 1, 
97                                           }
98                                         );
100     if (defined $platform_row) {
102         my $platform_id = $platform_row->get_column('platform_id');
103         my $platform_name = $platform_row->get_column('platform_name');
104         
105         my @plat_frags = split(/ /, $platform_name);
106         my $plat_partial_name = $plat_frags[0];
108         $urls{'gem results page for platform'} = "/search/gem_experiment_search.pl?w932_template_parameters=$plat_partial_name";
109         $urls{'gem platform page'} = "/gem/platform.pl?id=$platform_id";
110         $urls{'gem platform page (name)'} = "/gem/platform.pl?name=$platform_name";     
111     }
113     ## EXPERIMENTAL DESIGN ##
115     my ($experimental_design_row) = $schema->resultset('GeExperimentalDesign')
116                                 ->search( undef, 
117                                           { 
118                                               order_by => {-asc => 'experimental_design_id'}, 
119                                               rows     => 1, 
120                                           }
121                                         );
123     if (defined $experimental_design_row) {
125         my $expdesign_id = $experimental_design_row->get_column('experimental_design_id');
126         my $expdesign_name = $experimental_design_row->get_column('experimental_design_name');
128         $urls{'gem detail page for experimental design'} = "/gem/experimental_design.pl?id=$expdesign_id";
129         $urls{'gem detail page for experimental design (name)'} = "/gem/experimental_design.pl?name=$expdesign_name";   
130     }
132     ## TARGET ##
134     my ($target_row) = $schema->resultset('GeTarget')
135                                 ->search( undef, 
136                                           { 
137                                               order_by => {-asc => 'target_id'}, 
138                                               rows     => 1, 
139                                           }
140                                         );
142     if (defined $target_row) {
144         my $target_id = $target_row->get_column('target_id');
145         my $target_name = $target_row->get_column('target_name');
147         $urls{'gem detail page for target'} = "/gem/target.pl?id=$target_id";
148         $urls{'gem detail page for target (name)'} = "/gem/target.pl?name=$target_name";        
149     }
150     validate_urls(\%urls, $ENV{ITERATIONS} || 1 );
156 done_testing;