first pass RT4 merge, RT#13852
[freeside.git] / rt / t / articles / class.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 24;
7
8 use_ok 'RT::Articles';
9 use_ok 'RT::Classes';
10 use_ok 'RT::Class';
11
12 my $root = RT::CurrentUser->new('root');
13 ok ($root->Id, "Loaded root");
14 my $cl = RT::Class->new($root);
15 ok (UNIVERSAL::isa($cl, 'RT::Class'), "the new class is a class");
16
17 my ($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
18
19 ok ($id, $msg);
20
21 # no duplicate class names should be allowed
22 ($id, $msg) = $cl->Create(Name => 'Test-'.$$, Description => 'A test class');
23
24 ok (!$id, $msg);
25
26 #class name should be required
27
28 ($id, $msg) = $cl->Create(Name => '', Description => 'A test class');
29
30 ok (!$id, $msg);
31
32
33
34 $cl->Load('Test-'.$$);
35 ok($cl->id, "Loaded the class we want");
36
37
38
39 # Create a new user. make sure they can't create a class
40
41 my $u= RT::User->new(RT->SystemUser);
42 $u->Create(Name => "ArticlesTest".time, Privileged => 1);
43 ok ($u->Id, "Created a new user");
44
45 # Make sure you can't create a group with no acls
46 $cl = RT::Class->new($u);
47 ok (UNIVERSAL::isa($cl, 'RT::Class'), "the new class is a class");
48
49 ($id, $msg) = $cl->Create(Name => 'Test-nobody'.$$, Description => 'A test class');
50
51
52 ok (!$id, $msg. "- Can not create classes as a random new user - " .$u->Id);
53 $u->PrincipalObj->GrantRight(Right =>'AdminClass', Object => RT->System);
54 ($id, $msg) = $cl->Create(Name => 'Test-nobody-'.$$, Description => 'A test class');
55
56 ok ($id, $msg. "- Can create classes as a random new user after ACL grant");
57
58 # now check the Web UI
59
60 my ($url, $m) = RT::Test->started_ok;
61 ok($m->login);
62 $m->get_ok("$url/Admin/Articles/Classes/Modify.html?Create=1");
63 $m->content_contains('Create a Class', 'found title');
64 $m->submit_form_ok({
65     form_number => 3,
66     fields => { Name => 'Test Redirect' },
67 });
68 $m->content_contains('Object created', 'found results');
69 $m->content_contains('Modify the Class Test Redirect', 'found title');
70 $m->form_number(3);
71 $m->untick( 'Include-Name', 1 );
72 $m->field( 'Description', 'Test Description' );
73 $m->submit();
74 $m->content_like(qr/Description changed from.*no value.*to .*Test Description/,'description changed');
75 $m->form_number(3);
76 is($m->current_form->find_input('Include-Name')->value,undef,'Disabled Including Names for this Class');