start fixing test for multi cat phenotype upload.
[sgn.git] / t / unit_fixture / CXGN / Trial / TrialEntryNumbers.t
bloba7631811c9e59ffb732d0f44957c3b8e1596229c
1 use strict;
3 use Test::More;
4 use lib 't/lib';
5 use SGN::Test::Fixture;
7 use SGN::Model::Cvterm;
8 use CXGN::Trial::TrialDesign;
9 use CXGN::Trial::TrialCreate;
10 use CXGN::Trial::ParseUpload;
13 my $fix = SGN::Test::Fixture->new();
15 for my $extension ("xls", "xlsx") {
17     my $chado_schema = $fix->bcs_schema;
18     my $metadata_schema = $fix->metadata_schema;
19     my $phenome_schema = $fix->phenome_schema;
20     my $dbh = $fix->dbh;
22     #
23     # CREATE A TEST TRIAL
24     #
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();
39     ok(
40         my $design = $trial_design->get_design(),
41         "create trial design"
42     );
44     ok(
45         my $trial_create = CXGN::Trial::TrialCreate->new({
46             chado_schema      => $chado_schema,
47             dbh               => $dbh,
48             owner_id          => 41,
49             design            => $design,
50             program           => "test",
51             trial_year        => "2015",
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",
57             operator          => "janedoe"
58         }),
59         "create trial object"
60     );
62     my $save = $trial_create->save_trial();
63     ok(my $trial_id = $save->{'trial_id'}, "save trial");
66     #
67     # ADD TRIAL ENTRY NUMBERS
68     #
70     my $trial = CXGN::Trial->new({
71         bcs_schema      => $chado_schema,
72         metadata_schema => $metadata_schema,
73         phenome_schema  => $phenome_schema,
74         trial_id        => $trial_id
75     });
77     my $p = CXGN::Trial::ParseUpload->new({ filename => "t/data/trial/trial_entry_numbers_upload.$extension", chado_schema => $chado_schema });
78     $p->load_plugin("TrialEntryNumbers");
79     my $parsed_data = $p->parse();
80     my $errors = $p->get_parse_errors();
81     ok(!$errors, "no parse errors");
83     foreach my $id (keys %$parsed_data) {
84         $trial->set_entry_numbers($parsed_data->{$id});
85     }
87     my $entry_number_map = $trial->get_entry_numbers();
88     ok(!!$entry_number_map, "trial entry numbers exist");
91     #
92     # Remove Trial
93     #
94     $trial->delete_metadata();
95     $trial->delete_field_layout();
96     $trial->delete_project_entry();
98     $fix->clean_up_db();
100 done_testing();