summaryrefslogtreecommitdiff
path: root/rt/t/lifecycles/moving.t
blob: 6e0d64bbf0c4f13de27b95c09bd60d5d920ad953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;

BEGIN {require 't/lifecycles/utils.pl'};

my $general = RT::Test->load_or_create_queue(
    Name => 'General',
);
ok $general && $general->id, 'loaded or created a queue';

my $delivery = RT::Test->load_or_create_queue(
    Name => 'delivery',
    Lifecycle => 'delivery',
);
ok $delivery && $delivery->id, 'loaded or created a queue';

my $tstatus = sub {
    DBIx::SearchBuilder::Record::Cachable->FlushCache;
    my $ticket = RT::Ticket->new( RT->SystemUser );
    $ticket->Load( $_[0] );
    return $ticket->Status;
};

diag "check moving without a map";
{
    my $ticket = RT::Ticket->new( RT->SystemUser );
    my ($id, $msg) = $ticket->Create(
        Queue => $general->id,
        Subject => 'test',
        Status => 'new',
    );
    ok $id, 'created a ticket';
    (my $status, $msg) = $ticket->SetQueue( $delivery->id );
    ok !$status, "couldn't change queue when there is no maps between schemas";
    is $ticket->Queue, $general->id, 'queue is steal the same';
    is $ticket->Status, 'new', 'status is steal the same';
}

diag "add partial map";
{
    my $schemas = RT->Config->Get('Lifecycles');
    $schemas->{'__maps__'} = {
        'default -> delivery' => {
            new => 'ordered',
        },
    };
    RT::Lifecycle->FillCache;
}

diag "check moving with a partial map";
{
    {
        my $ticket = RT::Ticket->new( RT->SystemUser );
        my ($id, $msg) = $ticket->Create(
            Queue => $general->id,
            Subject => 'test',
            Status => 'new',
        );
        ok $id, 'created a ticket';
        (my $status, $msg) = $ticket->SetQueue( $delivery->id );
        ok $status, "moved ticket between queues with different schemas";
        is $ticket->Queue, $delivery->id, 'queue has been changed'
            or diag "error: $msg";
        is $ticket->Status, 'ordered', 'status has been changed';
    }
    {
        my $ticket = RT::Ticket->new( RT->SystemUser );
        my ($id, $msg) = $ticket->Create(
            Queue => $general->id,
            Subject => 'test',
            Status => 'open',
        );
        ok $id, 'created a ticket';
        (my $status, $msg) = $ticket->SetQueue( $delivery->id );
        ok !$status, "couldn't change queue when map is not complete";
        is $ticket->Queue, $general->id, 'queue is steal the same';
        is $ticket->Status, 'open', 'status is steal the same';
    }
}

diag "one way map doesn't work backwards";
{
    my $ticket = RT::Ticket->new( RT->SystemUser );
    my ($id, $msg) = $ticket->Create(
        Queue => $delivery->id,
        Subject => 'test',
        Status => 'ordered',
    );
    ok $id, 'created a ticket';
    (my $status, $msg) = $ticket->SetQueue( $general->id );
    ok !$status, "couldn't change queue when there is no maps between schemas";
    is $ticket->Queue, $delivery->id, 'queue is steal the same';
    is $ticket->Status, 'ordered', 'status is steal the same';
}