6 use SGN::Test::Fixture;
8 use Test::WWW::Mechanize;
14 my $f = SGN::Test::Fixture->new();
15 my $schema = $f->bcs_schema;
17 my $mech = Test::WWW::Mechanize->new;
19 $mech->get_ok("http://localhost:3010//tools/label_designer/retrieve_longest_fields?data_type=Field%20Trials&source_id=139&data_level=plots");
20 my $response = decode_json $mech->content;
21 print STDERR Dumper $response;
23 my $expected_response = {
27 'trial_name' => 'Kasese solgs trial',
28 'block_number' => '10',
30 'location_name' => 'test_location',
33 'dry matter content percentage|CO_334:0000092' => '21.2',
34 'accession_name' => 'UG120054',
35 'fresh shoot weight measurement in kg|CO_334:0000016' => '13.5',
36 'pedigree' => 'NA/NA',
37 'plot_number' => 35667,
38 'fresh root weight|CO_334:0000012' => '15.37',
39 'accession_id' => 38926,
40 'plot_name' => 'KASESE_TP2013_1000'
49 is_deeply($response, $expected_response, 'retrieve longest fields test');
51 my $download_type = 'pdf';
52 my $data_type = 'Field Trials';
54 my $data_level = 'plots';
55 my $design_json = encode_json {
56 "page_format" => "US Letter PDF",
58 "page_height" => 790.7,
59 "left_margin" => 13.68,
61 "horizontal_gap" => 10,
63 "number_of_columns" => 3,
64 "number_of_rows" => 10,
65 "plot_filter" => 'all',
66 "copies_per_plot" => "1",
67 "sort_order_1" => "plot_number",
68 "label_format" => "1\" x 2 5/8\"",
77 "value" => "{plot_name}",
85 "height" => 56.140625,
87 "value" => "{accession_name}",
89 "font" => "Courier-Bold",
97 "value" => "{trial_name}",
105 "height" => 26.640625,
106 "width" => 146.53125,
107 "value" => "Plot: {plot_number}",
115 "height" => 26.640625,
116 "width" => 159.84375,
117 "value" => "NIR: 17-{Number:0001:1}",
125 # print STDERR Dumper $design_json;
127 $mech->post_ok('http://localhost:3010/tools/label_designer/download', [ 'download_type' => $download_type, 'data_type' => $data_type, 'source_id'=> $source_id, 'data_level' => $data_level, 'design_json' => $design_json ]);
128 $response = decode_json $mech->content;
129 print STDERR Dumper $response;
131 my $file = $response->{'filepath'};
132 my $pdf = CAM::PDF->new($file);
133 print STDERR "Page 1 text: " . Dumper $pdf->getPageText(1);
135 my $expected_text = "UG120054 Plot: 35667 NIR: 17-0001 UG130026 Plot: 35668 NIR: 17-0002 UG130106 Plot: 35669 NIR: 17-0003 UG130034 Plot: 35670 NIR: 17-0004 UG120062 Plot: 35671 NIR: 17-0005 UG130071 Plot: 35672 NIR: 17-0006 UG120251 Plot: 35673 NIR: 17-0007 UG130088 Plot: 35674 NIR: 17-0008 UG120022 Plot: 35675 NIR: 17-0009 UG120141 Plot: 35676 NIR: 17-0010 UG120161 Plot: 35677 NIR: 17-0011 UG130046 Plot: 35678 NIR: 17-0012 UG120017 Plot: 35679 NIR: 17-0013 UG120053 Plot: 35680 NIR: 17-0014 UG120239 Plot: 35681 NIR: 17-0015 UG130111 Plot: 35682 NIR: 17-0016 UG130011 Plot: 35683 NIR: 17-0017 UG130096 Plot: 35684 NIR: 17-0018 UG130105 Plot: 35685 NIR: 17-0019 UG130131 Plot: 35686 NIR: 17-0020 UG120163 Plot: 35687 NIR: 17-0021 UG120257 Plot: 35688 NIR: 17-0022 UG120027 Plot: 35689 NIR: 17-0023 UG120195 Plot: 35690 NIR: 17-0024 UG120240 Plot: 35691 NIR: 17-0025 UG130007 Plot: 35692 NIR: 17-0026 UG120300 Plot: 35693 NIR: 17-0027 UG120291 Plot: 35694 NIR: 17-0028 UG120196 Plot: 35695 NIR: 17-0029 UG130098 Plot: 35696 NIR: 17-0030\n";
136 is($pdf->getPageText(1), $expected_text, 'download pdf test');
139 $download_type = 'zpl';
140 $design_json = encode_json {
141 "page_format" => "Zebra printer file",
144 "copies_per_plot" => "1",
145 "sort_order_1" => "plot_number",
146 "label_format" => "1 1/4\" x 2\"",
147 "label_width" => 144,
148 "label_height" => 90,
149 "label_elements" => [
153 "height" => 67.734375,
155 "value" => "{accession_name}",
156 "type" => "ZebraText",
165 "value" => "{plot_name}",
175 "value" => "{trial_name}",
183 "height" => 26.640625,
184 "width" => 146.53125,
185 "value" => "Plot: {plot_number}",
195 "value" => "Plot: {plot_number}",
196 "type" => "ZebraText",
203 $mech->post_ok('http://localhost:3010/tools/label_designer/download', [ 'download_type' => $download_type, 'data_type' => $data_type, 'source_id'=> $source_id, 'data_level' => $data_level, 'design_json' => $design_json ]);
204 $response = decode_json $mech->content;
206 $file = $response->{'filepath'};
207 my $file_content = read_file($file);
208 #print STDERR "File Content is:\n$file_content";
209 $file_content = substr $file_content, 0, 399;
210 #print STDERR "Substring File Content is:\n$file_content";
211 my $expected_content = '^XA
213 ^FO53.71875,14.1328125^AA,54^FDUG120054^FS
214 ^FO40,70^BQ,,4^FDMA,KASESE_TP2013_666^FS
215 ^FO81,198^BCN,25,N,N,N^FD Kasese solgs trial^FS
216 ^FO167.5,110.875^AA,27^FDPlot: 35667^FS
220 ^FO53.71875,14.1328125^AA,54^FDUG130026^FS
221 ^FO40,70^BQ,,4^FDMA,KASESE_TP2013_667^FS
222 ^FO81,198^BCN,25,N,N,N^FD Kasese solgs trial^FS
223 ^FO167.5,110.875^AA,27^FDPlot: 35668^FS
225 is($file_content, $expected_content, 'download zpl test');