From 6aa22559321048325c264e092b00be8f4c86f072 Mon Sep 17 00:00:00 2001 From: Werner Hahn Date: Fri, 22 Sep 2017 02:10:56 +0200 Subject: [PATCH] WebshopApi: SL/Dev/Shop --- SL/Dev/ALL.pm | 3 +- SL/Dev/Shop.pm | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 SL/Dev/Shop.pm diff --git a/SL/Dev/ALL.pm b/SL/Dev/ALL.pm index aa0e8ba15..b702b0f5b 100644 --- a/SL/Dev/ALL.pm +++ b/SL/Dev/ALL.pm @@ -8,10 +8,11 @@ use SL::Dev::CustomerVendor; use SL::Dev::Inventory; use SL::Dev::Record; use SL::Dev::Payment; +use SL::Dev::Shop; sub import { no strict "refs"; - for (qw(Part CustomerVendor Inventory Record Payment)) { + for (qw(Part CustomerVendor Inventory Record Payment Shop)) { Exporter::export_to_level("SL::Dev::$_", 1, @_); } } diff --git a/SL/Dev/Shop.pm b/SL/Dev/Shop.pm new file mode 100644 index 000000000..857a1c470 --- /dev/null +++ b/SL/Dev/Shop.pm @@ -0,0 +1,77 @@ +package SL::Dev::Shop; + +use strict; +use base qw(Exporter); +use Data::Dumper; +our @EXPORT_OK = qw(new_shop new_shop_part new_shop_order); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); + +use SL::DB::Shop; + +sub new_shop { + my (%params) = @_; + + my $shop = SL::DB::Shop->new( + description => delete $params{description} || 'testshop', + %params + ); + return $shop; +} + +sub new_shop_part { + my (%params) = @_; + + my $part = delete $params{part}; + my $shop = delete $params{shop}; + + my $shop_part = SL::DB::ShopPart->new( + part => $part, + shop => $shop, + %params + )->save; + return $shop_part; +} + +sub new_shop_order { + my (%params) = @_; + + my $shop_order = SL::DB::ShopOrder->new( + shop => $params{shop}, + %params + ); + return $shop_order; +} + + +1; + +__END__ + +=head1 NAME + +SL::Dev::Shop - create shop objects for testing, with minimal defaults + +=head1 FUNCTIONS + +=head2 C + +Creates a new shop object. + + my $shop = SL::Dev::Shop::create_shop(); + +Add a part as a shop part to the shop: + + my $part = SL::Dev::Part::create_part(); + $shop->add_shop_parts( SL::DB::ShopPart->new(part => $part, shop_description => 'Simply the best part!' ) ); + $shop->save; + + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +G. Richardson Egrichardson@kivitendo-premium.deE + +=cut -- 2.20.1