5 use SGN::Test::Fixture;
8 use Test::WWW::Mechanize;
11 use SGN::Model::Cvterm;
12 use CXGN::Trial::TrialDesign;
13 use CXGN::Trial::TrialCreate;
16 my $fix = SGN::Test::Fixture->new();
17 my $chado_schema = $fix->bcs_schema;
18 my $metadata_schema = $fix->metadata_schema;
19 my $phenome_schema = $fix->phenome_schema;
26 my $ayt_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($chado_schema, 'Advanced Yield Trial', 'project_type')->cvterm_id();
28 my @stock_names = ('test_accession1', 'test_accession2', 'test_accession3', 'test_accession4', 'test_accession5');
30 my $trial_design = CXGN::Trial::TrialDesign->new();
31 $trial_design->set_trial_name("test_trial");
32 $trial_design->set_stock_list(\@stock_names);
33 $trial_design->set_plot_start_number(1);
34 $trial_design->set_plot_number_increment(1);
35 $trial_design->set_plot_layout_format("zigzag");
36 $trial_design->set_number_of_blocks(2);
37 $trial_design->set_design_type("RCBD");
38 $trial_design->calculate_design();
40 my $design = $trial_design->get_design(),
45 my $trial_create = CXGN::Trial::TrialCreate->new({
46 chado_schema => $chado_schema,
52 trial_description => "test description",
53 trial_location => "test_location",
54 trial_name => "subplot_test_trial",
55 trial_type=>$ayt_cvterm_id,
56 design_type => "RCBD",
62 my $save = $trial_create->save_trial();
63 ok(my $trial_id = $save->{'trial_id'}, "save trial");
67 # ADD SUBPLOTS TO PLOTS
70 my $trial = CXGN::Trial->new({
71 bcs_schema => $chado_schema,
72 metadata_schema => $metadata_schema,
73 phenome_schema => $phenome_schema,
76 $trial->create_subplot_entities('2');
78 my $tl = CXGN::Trial::TrialLayout->new({ schema => $chado_schema, trial_id => $trial_id, experiment_type => 'field_layout' });
79 my $d = $tl->get_design();
81 my @subplot_names = ();
82 my @subplot_names_flat = ();
83 foreach my $plot_num (keys %$d) {
84 push @subplot_names, $d->{$plot_num}->{'subplot_names'}
86 foreach my $subplot_name_arr_ref (@subplot_names) {
87 foreach (@$subplot_name_arr_ref) {
88 push @subplot_names_flat, $_;
92 #print STDERR Dumper \@subplot_names_flat;
93 # 5 plots/block * 2 blocks * 2 subplots/plot = 20 subplots
94 is(scalar(@subplot_names_flat), 20);
98 # ADD PLANTS TO SUBPLOTS
101 $trial->create_plant_subplot_entities(4);
102 $tl = CXGN::Trial::TrialLayout->new({ schema => $chado_schema, trial_id => $trial_id, experiment_type => 'field_layout' });
103 $d = $tl->get_design();
105 my @plant_names = ();
106 my @plant_names_flat = ();
107 foreach my $plot_num (keys %$d) {
108 push @plant_names, $d->{$plot_num}->{'plant_names'}
110 foreach my $plant_name_arr_ref (@plant_names) {
111 foreach (@$plant_name_arr_ref) {
112 push @plant_names_flat, $_;
116 # print STDERR Dumper \@plant_names_flat;
117 # 5 plots/block * 2 blocks * 2 subplots/plot * 4 plants/subplot = 80 plants
118 is(scalar(@plant_names_flat), 80);
124 $trial->delete_metadata();
125 $trial->delete_field_layout();
126 $trial->delete_project_entry();