X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fdb_helper%2Facts_as_list.t;h=3b5b570eaf17fa57d2d336ba2df21bc82c252d87;hb=0eb8e2233994c12c3fc2f560bb1fac1428e9156e;hp=b91b18c0257367f4f06a7ad83e28610009d0344a;hpb=f12b3596807e5a46c6ed3e86c43e01492d2dc6c1;p=kivitendo-erp.git diff --git a/t/db_helper/acts_as_list.t b/t/db_helper/acts_as_list.t index b91b18c02..3b5b570ea 100644 --- a/t/db_helper/acts_as_list.t +++ b/t/db_helper/acts_as_list.t @@ -1,4 +1,4 @@ -use Test::More tests => 44; +use Test::More; use Test::Exception; use strict; @@ -9,9 +9,18 @@ use utf8; 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); @@ -139,19 +148,19 @@ test_positions "reoder_list called as class method", [ 1, undef, 1 ], [ 2, undef # Aus Liste entfernen reset_state(); get_item(3)->remove_from_list; -test_positions "remove_from_list on top", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, undef ], [ 4, 1, 1 ], [ 5, 1, 2 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; +test_positions "remove_from_list on top", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, -1 ], [ 4, 1, 1 ], [ 5, 1, 2 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; reset_state(); get_item(4)->remove_from_list; -test_positions "remove_from_list on middle", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, undef ], [ 5, 1, 2 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; +test_positions "remove_from_list on middle", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, -1 ], [ 5, 1, 2 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; reset_state(); get_item(5)->remove_from_list; -test_positions "remove_from_list on bottom", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, 2 ], [ 5, 1, undef ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; +test_positions "remove_from_list on bottom", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, 2 ], [ 5, 1, -1 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, 1 ]; reset_state(); get_item(8)->remove_from_list; -test_positions "remove_from_list on only item in list", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, 2 ], [ 5, 1, 3 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, undef ]; +test_positions "remove_from_list on only item in list", [ 1, undef, 1 ], [ 2, undef, 2 ], [ 3, 1, 1 ], [ 4, 1, 2 ], [ 5, 1, 3 ], [ 6, 4, 1 ], [ 7, 4, 2 ], [ 8, 2, -1 ]; reset_state(); $item = get_item(3); $item->remove_from_list; $item->delete; @@ -206,7 +215,18 @@ reset_state(); $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'); +is($item->get_previous_in_list->id, 3, 'Previous of 4 is 5'); +is($item->get_next_in_list->get_previous_in_list->id, 4, 'Previous of Next of 4 is 4'); +is($item->get_previous_in_list->get_next_in_list->id, 4, 'Next of Previous of 4 is 4'); +is($item->get_next_in_list->get_next_in_list, undef, 'Next of Next of 4 is undef'); +is($item->get_previous_in_list->get_previous_in_list, undef, 'Previous of Previous of 4 is undef'); # Parametervalidierung throws_ok { new_item()->move_position_up } qr/not.*been.*saved/i, 'move up not saved yet';