-use Test::More tests => 50;
+use Test::More;
use Test::Exception;
use strict;
use Data::Dumper;
use Support::TestSetup;
-use_ok 'SL::DB::RequirementSpec';
-use_ok 'SL::DB::RequirementSpecItem';
-use_ok 'SL::DB::RequirementSpecTextBlock';
+eval {
+ require 'SL::DB::RequirementSpec';
+ require 'SL::DB::RequirementSpecItem';
+ require 'SL::DB::RequirementSpecTextBlock';
+ 1;
+} or my $skip = 'RequirementSpec is not available for this test';
+
+if ($skip) {
+ plan skip_all => $skip;
+} else {
+ plan tests => 48;
+}
sub reset_state {
"SL::DB::Manager::${_}"->delete_all(all => 1) for qw(RequirementSpecTextBlock RequirementSpecItem RequirementSpec);
$item = get_item(8); $item->remove_from_list; $item->parent_id(3); $item->add_to_list(position => 'first');
test_positions "add_to_list position 'first' in empty", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, 2 ], [ 5, 1, 3 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 3, 1 ];
+reset_state();
+$item = get_item(5); $item->add_to_list(position => 'after', reference => 3);
+test_positions "add_to_list without prior remove_from_list", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 5, 1, 2 ], [ 4, 1, 3 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ];
+
reset_state();
$item = get_item(4);
is($item->get_next_in_list->id, 5, 'Next of 4 is 5');