Revision 5b6df6e8
Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt
t/part/assortment.t | ||
---|---|---|
1 |
use strict; |
|
2 |
use Test::More; |
|
3 |
|
|
4 |
use lib 't'; |
|
5 |
use Support::TestSetup; |
|
6 |
use Carp; |
|
7 |
use Test::Exception; |
|
8 |
use SL::DB::Unit; |
|
9 |
use SL::DB::Part; |
|
10 |
use Data::Dumper; |
|
11 |
|
|
12 |
Support::TestSetup::login(); |
|
13 |
|
|
14 |
clear_up(); |
|
15 |
reset_state(); |
|
16 |
|
|
17 |
is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3"); |
|
18 |
|
|
19 |
my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'as1' ); |
|
20 |
|
|
21 |
is( $assortment->part_type, 'assortment', 'assortment has correct part_type'); |
|
22 |
is( scalar @{$assortment->assortment_items}, 2, 'assortment has two parts' ); |
|
23 |
|
|
24 |
my $assortment_item = $assortment->assortment_items->[0]; |
|
25 |
is( $assortment_item->assortment->partnumber, 'as1', "assortment_item links back to correct assortment"); |
|
26 |
|
|
27 |
clear_up(); |
|
28 |
done_testing; |
|
29 |
|
|
30 |
sub reset_state { |
|
31 |
my %params = @_; |
|
32 |
|
|
33 |
my ($part1, $part2, $unit); |
|
34 |
|
|
35 |
# SL::DB::Manager::AssortmentItem->delete_all(all => 1); |
|
36 |
# SL::DB::Manager::Part->delete_all(all => 1); |
|
37 |
my ($part1, $part2, $unit, $assortment_part, $assortment_1, $assortment_2); |
|
38 |
|
|
39 |
my $unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; |
|
40 |
$part1 = SL::DB::Part->new_part( partnumber => '7777', |
|
41 |
description => "assortment part 1", |
|
42 |
unit => $unit->name, |
|
43 |
sellprice => '3.33', |
|
44 |
)->save; |
|
45 |
$part2 = $part1->clone_and_reset($part1); |
|
46 |
$part2->partnumber( $part1->partnumber + 1 ); |
|
47 |
$part2->description( "assortment part 2" ); |
|
48 |
$part2->save; |
|
49 |
|
|
50 |
my $assortment_part = SL::DB::Part->new_assortment( partnumber => 'as1', |
|
51 |
description => 'assortment', |
|
52 |
sellprice => '0', |
|
53 |
unit => $unit->name); |
|
54 |
my $assortment_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); |
|
55 |
my $assortment_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); |
|
56 |
$assortment_part->add_assortment_items($assortment_1, $assortment_2); |
|
57 |
$assortment_part->save or die "Couldn't save assortment"; |
|
58 |
|
|
59 |
}; |
|
60 |
|
|
61 |
sub clear_up { |
|
62 |
SL::DB::Manager::AssortmentItem->delete_all(all => 1); |
|
63 |
SL::DB::Manager::Part->delete_all( all => 1); |
|
64 |
}; |
|
65 |
|
|
66 |
|
|
67 |
1; |
Auch abrufbar als: Unified diff
Sortiment - Test für Sortimentsartikel