Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 91d06da8

Von Sven Schöling vor fast 2 Jahren hinzugefügt

  • ID 91d06da8db6fcd4b19c5a8af6690d1b01d1ce27e
  • Vorgänger 270c1a43
  • Nachfolger 34b81691

PriceRule: tests

Unterschiede anzeigen:

t/db/price_rule.t
1
use Test::More;
2

  
3
use strict;
4

  
5
use lib 't';
6
use utf8;
7

  
8
use Carp;
9
use Data::Dumper;
10
use Support::TestSetup;
11
use Test::Exception;
12

  
13
use SL::Dev::ALL qw(:ALL);
14
use SL::DB::PriceRule;
15
use SL::DB::CustomVariableConfig;
16

  
17
Support::TestSetup::login();
18

  
19
sub reset_db {
20
  SL::DB::Manager::PriceRule->delete_all(all => 1);
21
  SL::DB::Manager::CustomVariable->delete_all(all => 1);
22
  SL::DB::Manager::CustomVariableConfig->delete_all(all => 1);
23
  SL::DB::Manager::Order->delete_all(all => 1);
24

  
25
  $::request->{_cache} = {};
26
}
27

  
28
{
29
  reset_db();
30

  
31
  # cvar price rules.
32
  # a select cvar price rule for one specific value A
33
  # and an order where the part has exactly that cvar set to first A and then B
34

  
35
  my $cvar_config = SL::DB::CustomVariableConfig->new(
36
    module      => 'IC',
37
    name        => "test",
38
    description => "test",
39
    type        => "select",
40
    options     => "A##B##C##D",
41
    flags       => "editable=0",
42
    searchable  => 0,
43
    includeable => 0,
44
    included_by_default => 0,
45
  )->save->load;
46

  
47
  my $name = "price for test A";
48

  
49
  my $price_rule = SL::DB::PriceRule->new(
50
    name  => $name,
51
    price => 1,
52
    type  => "customer",
53
    items => [
54
      SL::DB::PriceRuleItem->new(
55
        custom_variable_configs => $cvar_config,
56
        value_text              => "A",
57
        type                    => "cvar",
58
      ),
59
    ],
60
  )->save;
61

  
62
  my $order = create_sales_order()->save->load;
63

  
64
  $order->items_sorted->[0]->part->cvar_by_name('test')->value("A");
65
  $order->items_sorted->[0]->part->cvar_by_name('test')->save;
66

  
67
  ok(1 == grep({ $_->{name} eq $name } @{ SL::DB::Manager::PriceRule->get_all_matching(record => $order, record_item => $order->items_sorted->[0]) }), "editable=0 price rule matches");
68

  
69
  $order->items_sorted->[0]->part->cvar_by_name('test')->value("B");
70
  $order->items_sorted->[0]->part->cvar_by_name('test')->save;
71

  
72
  ok(0 == grep({ $_->{name} eq $name } @{ SL::DB::Manager::PriceRule->get_all_matching(record => $order, record_item => $order->items_sorted->[0]) }), "editable=0 price rule does not match");
73
}
74

  
75
{
76
  reset_db();
77

  
78
  # now try the same, but with an editable cvar config
79

  
80
  my $cvar_config = SL::DB::CustomVariableConfig->new(
81
    module      => 'IC',
82
    name        => "test",
83
    description => "test2",
84
    type        => "select",
85
    options     => "A##B##C##D",
86
    flags       => "editable=1",
87
    searchable  => 0,
88
    includeable => 0,
89
    included_by_default => 0,
90
  )->save->load;
91

  
92
  my $name = "price for test A";
93

  
94
  my $price_rule = SL::DB::PriceRule->new(
95
    name  => $name,
96
    price => 1,
97
    type  => "customer",
98
    items => [
99
      SL::DB::PriceRuleItem->new(
100
        custom_variable_configs => $cvar_config,
101
        value_text              => "A",
102
        type                    => "cvar",
103
      ),
104
    ],
105
  )->save;
106

  
107
  my $order = create_sales_order()->save->load;
108
  my $item = $order->items_sorted->[0];
109

  
110
  $item->cvar_by_name('test')->value("A");
111
  $item->cvar_by_name('test')->save;
112

  
113
  ok(1 == grep({ $_->{name} eq $name } @{ SL::DB::Manager::PriceRule->get_all_matching(record => $order, record_item => $item) }), "editable=1 price rule matches");
114

  
115
  $item->cvar_by_name('test')->value("B");
116
  $item->cvar_by_name('test')->save;
117

  
118
  ok(0 == grep({ $_->{name} eq $name } @{ SL::DB::Manager::PriceRule->get_all_matching(record => $order, record_item => $item) }), "editable=1 price rule does not match");
119

  
120
}
121

  
122

  
123
done_testing();

Auch abrufbar als: Unified diff