File: cf_set_initial.t

package info (click to toggle)
request-tracker5 5.0.7%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 80,216 kB
  • sloc: javascript: 191,898; perl: 87,146; sh: 1,412; makefile: 487; python: 37; php: 15
file content (103 lines) | stat: -rw-r--r-- 3,875 bytes parent folder | download | duplicates (2)
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
98
99
100
101
102
103
use strict;
use warnings;

use RT::Test tests => undef;
my ($baseurl, $m) = RT::Test->started_ok;

ok $m->login, 'logged in';

my $cf = RT::CustomField->new( RT->SystemUser );
my ($cfid, $msg) = $cf->Create(
    Name => 'Test Set Initial CF',
    Queue => '0',
    Type => 'FreeformSingle',
);

my $multi_cf = RT::CustomField->new( RT->SystemUser );
my ($multi_cfid) = $multi_cf->Create(
    Name => 'Multi Set Initial CF',
    Queue => '0',
    Type => 'FreeformMultiple',
);

my $tester = RT::Test->load_or_create_user( Name => 'tester', Password => '123456' );
RT::Test->set_rights(
    { Principal => $tester->PrincipalObj,
      Right => [qw(SeeQueue ShowTicket CreateTicket)],
    },
);
ok $m->login( $tester->Name, 123456, logout => 1), 'logged in';

diag "check that we have no CFs on the create"
    ." ticket page when user has no SetInitialCustomField right";
{
    $m->submit_form( form_name => "CreateTicketInQueue" );
    $m->content_lacks('Test Set Initial CF', 'has no CF input');
    $m->content_lacks('Multi Set Initial CF', 'has no CF input');

    my $form = $m->form_name("TicketCreate");
    my $edit_field = "Object-RT::Ticket--CustomField-$cfid-Value";
    ok !$form->find_input( $edit_field ), 'no form field on the page';
    my $multi_field = "Object-RT::Ticket--CustomField-$multi_cfid-Values";
    ok !$form->find_input( $multi_field ), 'no form field on the page';

    $m->submit_form(
        form_name => "TicketCreate",
        fields => { Subject => 'test' },
        button => 'SubmitTicket',
    );
    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");

    $m->content_lacks('Test Set Initial CF', 'has no CF on the page');
    $m->content_lacks('Multi Set Initial CF', 'has no CF on the page');
    $m->follow_link( text => 'Custom Fields');
    $m->content_lacks('Test Set Initial CF', 'has no CF field');
    $m->content_lacks('Multi Set Initial CF', 'has no CF field');
}

RT::Test->set_rights(
    { Principal => $tester->PrincipalObj,
      Right => [qw(SeeQueue ShowTicket CreateTicket SetInitialCustomField)],
    },
);

diag "check that we have the CF on the create"
    ." ticket page when user has SetInitialCustomField but no SeeCustomField";
{
    $m->submit_form( form_name => "CreateTicketInQueue" );
    $m->content_contains('Test Set Initial CF', 'has CF input');
    $m->content_contains('Multi Set Initial CF', 'has CF input');

    my $form = $m->form_name("TicketCreate");
    my $edit_field = "Object-RT::Ticket--CustomField-$cfid-Value";
    ok $form->find_input( $edit_field ), 'has form field on the page';
    my $multi_field = "Object-RT::Ticket--CustomField-$multi_cfid-Values";
    ok $form->find_input( $multi_field ), 'has form field on the page';

    $m->submit_form(
        form_name => "TicketCreate",
        fields => {
            $edit_field => 'yatta',
            $multi_field => 'hiro',
            Subject => 'test 2',
        },
        button => 'SubmitTicket',
    );
    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
    if (my ($id) = $m->content =~ /Ticket (\d+) created/) {
        my $ticket = RT::Ticket->new(RT->SystemUser);
        my ($ok, $msg) = $ticket->Load($id);
        ok($ok, "loaded ticket $id");
        is($ticket->Subject, 'test 2', 'subject is correct');
        is($ticket->FirstCustomFieldValue('Test Set Initial CF'), 'yatta', 'CF was set correctly');
        is($ticket->FirstCustomFieldValue('Multi Set Initial CF'), 'hiro', 'CF was set correctly');
    }

    $m->content_lacks('Test Set Initial CF', 'has no CF on the page');
    $m->content_lacks('Multi Set Initial CF', 'has no CF on the page');
    $m->follow_link( text => 'Custom Fields');
    $m->content_lacks('Test Set Initial CF', 'has no CF edit field');
    $m->content_lacks('Multi Set Initial CF', 'has no CF edit field');
}

done_testing;