8 use SGN::Test::Fixture;
11 my $t = SGN::Test::Fixture->new();
14 my $lists = CXGN::List::available_lists($t->dbh(), 41);
16 my @lists_sorted = sort { $a->[0] <=> $b->[0] } @$lists;
18 print STDERR Dumper \@lists_sorted;
19 is_deeply(\@lists_sorted, [
28 '0001-01-01 00:00:00',
33 'accessions_for_solgs_tests',
39 '0001-01-01 00:00:00',
44 'accessions_for_trial2',
50 '0001-01-01 00:00:00',
61 '0001-01-01 00:00:00',
66 'desynonymize_test_list',
72 '0001-01-01 00:00:00',
83 '0001-01-01 00:00:00',
94 '0001-01-01 00:00:00',
105 '0001-01-01 00:00:00',
106 '0001-01-01 00:00:00'
108 ], "check available lists initially");
110 my $list_id = CXGN::List::create_list($t->dbh(), 'test_list2', 'test_desc', 41);
112 #print STDERR "CREATED LIST WITH ID $list_id\n";
114 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id } );
116 my $name = $list->name();
117 is($name, "test_list2", "get list name");
119 $list->name("new_test_name");
120 is($list->name(), "new_test_name");
122 $list->description("new description");
123 is($list->description(), "new description", "description change");
125 $list->type("accessions");
126 is($list->type(), 'accessions', "list type test");
128 # check if name is actually stored
129 my $list2 = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id });
130 is($list2->name(), "new_test_name", "list name store test");
131 is($list2->description(), "new description", "description store change");
132 is($list2->type(), "accessions", "list type store");
133 is($list2->type_id(), 76451, "list type_id");
134 is($list2->owner(), 41, "list owner");
135 my $error = $list->add_element("bla");
136 ok(!$error, "adding an element to the list");
138 $error = $list->add_element("blabla");
139 ok(!$error, "adding another element");
141 $error = $list->add_element("blabla");
142 ok($error, "adding a duplicate element to the list");
144 is($list->list_size(), 2, "list size check 1");
146 ok($list->exists_element("blabla"), 'exists element check');
148 my $elements = $list->elements();
149 is_deeply($elements, [ 'bla', 'blabla' ], "retrieve list elements after add");
151 $error = $list->remove_element('blabla');
152 ok(!$error, "delete element from list");
154 $elements = $list->elements();
155 is_deeply($elements, [ 'bla' ], "retrieve list elements after delete");
157 is($list->list_size(), 1, "list size check after delete");
158 ok(!$list->exists_element("blabla"), 'exists element after delete');
160 my $lists = CXGN::List::available_lists($t->dbh(), 41);
162 #print STDERR Dumper($lists);
163 @lists_sorted = sort { $a->[0] <=> $b->[0] } @$lists;
165 foreach (@lists_sorted){
167 push @lists_minus_ids, $_;
169 print STDERR Dumper \@lists_minus_ids;
170 print STDERR Dumper $lists_minus_ids[6][6];
171 my $timestamp = $lists_minus_ids[6][6];
172 my $timestamp_mod = $lists_minus_ids[6][7];
173 is_deeply(\@lists_minus_ids, [
181 '0001-01-01 00:00:00',
182 '0001-01-01 00:00:00'
185 'accessions_for_solgs_tests',
191 '0001-01-01 00:00:00',
192 '0001-01-01 00:00:00'
195 'accessions_for_trial2',
201 '0001-01-01 00:00:00',
202 '0001-01-01 00:00:00'
211 '0001-01-01 00:00:00',
212 '0001-01-01 00:00:00'
215 'desynonymize_test_list',
221 '0001-01-01 00:00:00',
222 '0001-01-01 00:00:00'
231 '0001-01-01 00:00:00',
232 '0001-01-01 00:00:00'
251 '0001-01-01 00:00:00',
252 '0001-01-01 00:00:00'
261 '0001-01-01 00:00:00',
262 '0001-01-01 00:00:00'
265 "check available lists after additions");
269 $error = CXGN::List::delete_list($t->dbh(), 5);
271 my $lists = CXGN::List::available_lists($t->dbh(), 41);
273 #print STDERR Dumper($lists);
275 @lists_sorted = sort { $a->[0] <=> $b->[0] } @$lists;
276 @lists_sorted = sort { $a->[0] <=> $b->[0] } @$lists;
278 foreach (@lists_sorted){
280 push @lists_minus_ids, $_;
282 $timestamp_mod = $lists_minus_ids[5][7];
283 print STDERR Dumper \@lists_minus_ids;
284 is_deeply(\@lists_minus_ids, [
292 '0001-01-01 00:00:00',
293 '0001-01-01 00:00:00'
296 'accessions_for_trial2',
302 '0001-01-01 00:00:00',
303 '0001-01-01 00:00:00'
312 '0001-01-01 00:00:00',
313 '0001-01-01 00:00:00'
316 'desynonymize_test_list',
322 '0001-01-01 00:00:00',
323 '0001-01-01 00:00:00'
332 '0001-01-01 00:00:00',
333 '0001-01-01 00:00:00'
352 '0001-01-01 00:00:00',
353 '0001-01-01 00:00:00'
362 '0001-01-01 00:00:00',
363 '0001-01-01 00:00:00'
366 , "check available lists after deletion");
370 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id });
371 my $items = $list->retrieve_elements_with_ids($list_id);
372 $error = $list->update_element_by_id($items->[0]->[0], 'updated name');
373 ok(!$error, 'test update item');
374 $items = $list->retrieve_elements_with_ids($list_id);
375 #print STDERR Dumper $items;
379 push @items_stripped, $_->[1];
381 is_deeply(\@items_stripped, [
383 ], 'check updated list item');
385 my $space1 = $list->add_element(" bla1");
386 ok($list->exists_element("bla1"), 'remove leading space element check');
387 ok(!$list->exists_element(" bla1"), 'leading space removed from element');
390 my $space2 = $list->add_element("bla2 ");
391 ok($list->exists_element("bla2"), 'remove trailing space element check');
392 ok(!$list->exists_element("bla2 "), 'trailing space removed from element');
394 my $space3 = $list->add_element(" bla3 ");
395 ok($list->exists_element("bla3"), 'remove trailing and leading spaces element check');
396 ok(!$list->exists_element(" bla3 "), 'trailing and leading spaces removed from element');
398 my $space4 = $list->add_element(" ");
399 ok($space4 eq "Empty list elements are not allowed", 'element with only spaces cannot be added');
402 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id } );
403 ok($list->add_bulk(['item1','item2','item1','item20','item1001','item01','item10','item010','it1num', 'it2num']), 'test add bulk');
404 ok($list->sort_items('ASC'), "sort ascending list");
405 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id } );
406 $items = $list->elements;
407 print STDERR Dumper $items;
422 ], 'check asc ordered items');
424 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id } );
425 ok($list->sort_items('DESC'), "sort descending list");
426 my $list = CXGN::List->new( { dbh => $t->dbh(), list_id => $list_id } );
427 $items = $list->elements;
428 print STDERR Dumper $items;
443 ], 'check desc ordered items');