Merge branch 'master' into topic/dt_feature_search
[sgn.git] / t / legacy / validate / gem.t
blobc645aa8de5a240a626077800a416240a4ccb297a
1 use strict;
2 use warnings;
4 use FindBin;
5 use lib 't/lib';
7 use Test::More;
9 use SGN::Test::WWW::Mechanize;
10 use SGN::Test qw/validate_urls/;
12 use CXGN::GEM::Schema;
14 ## define a %url hash
16 my %urls = ();
18 my $mech = SGN::Test::WWW::Mechanize->new;
20 ## This test are local test, so it will use the with_test_level function
22 $mech->with_test_level( local => sub {
24     ## First take variables for the test from the database ##
26     my @schema_list = ('gem', 'biosource', 'metadata', 'public');
27     my $schema_list = join(',', @schema_list);
29     my $dbh = $mech->context()->dbc()->dbh();
31     my $schema = $mech->context->dbic_schema('CXGN::GEM::Schema');
33     ## WWW. GEM SEARCH TEST ###
35     $urls{"gem search page for templates"} = "/search/direct_search.pl?search=template";
36     $urls{"gem search page for experiments"} = "/search/direct_search.pl?search=experiment";
37     $urls{"gem search page for platforms"} = "/search/direct_search.pl?search=platform";
38     
39     ## WWW. RESULT AND DETAIL PAGES ###
41     ## TEMPLATE ##
42     ## Take a template, an experiment name and a platform name
44     my ($template_row) = $schema->resultset('GeTemplate')
45                                 ->search( undef, 
46                                           { 
47                                               order_by => {-asc => 'template_id'}, 
48                                               rows     => 1, 
49                                           }
50                                         );
52     ## Now it will test the expected gem result web-page if there is at least one row 
53     ## in the database. If not, it will test the error page
55     if (defined $template_row) {
57         my $template_id = $template_row->get_column('template_id');
58         my $template_name = $template_row->get_column('template_name');
59         
60         $urls{'gem results page for templates'} = "/search/gem_template_search.pl?w616_template_parameters=$template_name";
61         $urls{'gem template page'} = "/gem/template.pl?id=$template_id";
62         $urls{'gem template page (name)'} = "/gem/template.pl?name=$template_name";     
63     }
65     ## EXPERIMENT ##
67     my ($experiment_row) = $schema->resultset('GeExperiment')
68                                 ->search( undef, 
69                                           { 
70                                               order_by => {-asc => 'experiment_id'}, 
71                                               rows     => 1, 
72                                           }
73                                         );
75     ## Now it will test the expected gem result web-page if there is at least one row 
76     ## in the database. If not, it will test the error page
78     if (defined $experiment_row) {
80         my $experiment_id = $experiment_row->get_column('experiment_id');
81         my $experiment_name = $experiment_row->get_column('experiment_name');
82         
83         my @exp_frags = split(/ /, $experiment_name);
84         my $partial_name = $exp_frags[0];
86         $urls{'gem results page for experiments'} = "/search/gem_experiment_search.pl?w932_experiment_parameters=$partial_name";
87         $urls{'gem experiment page'} = "/gem/experiment.pl?id=$experiment_id";
88         $urls{'gem experiment page (name)'} = "/gem/experiment.pl?name=$experiment_name";       
89     }
91     ## PLATFORM ##
93     my ($platform_row) = $schema->resultset('GePlatform')
94                                 ->search( undef, 
95                                           { 
96                                               order_by => {-asc => 'platform_id'}, 
97                                               rows     => 1, 
98                                           }
99                                         );
101     if (defined $platform_row) {
103         my $platform_id = $platform_row->get_column('platform_id');
104         my $platform_name = $platform_row->get_column('platform_name');
105         
106         my @plat_frags = split(/ /, $platform_name);
107         my $plat_partial_name = $plat_frags[0];
109         $urls{'gem results page for platform'} = "/search/gem_experiment_search.pl?w932_template_parameters=$plat_partial_name";
110         $urls{'gem platform page'} = "/gem/platform.pl?id=$platform_id";
111         $urls{'gem platform page (name)'} = "/gem/platform.pl?name=$platform_name";     
112     }
114     ## EXPERIMENTAL DESIGN ##
116     my ($experimental_design_row) = $schema->resultset('GeExperimentalDesign')
117                                 ->search( undef, 
118                                           { 
119                                               order_by => {-asc => 'experimental_design_id'}, 
120                                               rows     => 1, 
121                                           }
122                                         );
124     if (defined $experimental_design_row) {
126         my $expdesign_id = $experimental_design_row->get_column('experimental_design_id');
127         my $expdesign_name = $experimental_design_row->get_column('experimental_design_name');
129         $urls{'gem detail page for experimental design'} = "/gem/experimental_design.pl?id=$expdesign_id";
130         $urls{'gem detail page for experimental design (name)'} = "/gem/experimental_design.pl?name=$expdesign_name";   
131     }
133     ## TARGET ##
135     my ($target_row) = $schema->resultset('GeTarget')
136                                 ->search( undef, 
137                                           { 
138                                               order_by => {-asc => 'target_id'}, 
139                                               rows     => 1, 
140                                           }
141                                         );
143     if (defined $target_row) {
145         my $target_id = $target_row->get_column('target_id');
146         my $target_name = $target_row->get_column('target_name');
148         $urls{'gem detail page for target'} = "/gem/target.pl?id=$target_id";
149         $urls{'gem detail page for target (name)'} = "/gem/target.pl?name=$target_name";        
150     }
151     validate_urls(\%urls, $ENV{ITERATIONS} || 1 );
157 done_testing;