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