|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use RT::Test::Assets tests => undef; |
| 5 | + |
| 6 | +my $catalog = create_catalog( Name => 'Test Catalog'); |
| 7 | +ok $catalog && $catalog->id, "Created catalog"; |
| 8 | + |
| 9 | +for my $name (qw/SingleTestCustomRole MultipleTestCustomRole/) { |
| 10 | + my $role = RT::CustomRole->new( RT->SystemUser ); |
| 11 | + my ( $ok, $msg ) = $role->Create( |
| 12 | + Name => $name, |
| 13 | + MaxValues => $name =~ /Single/ ? 1 : 0, |
| 14 | + LookupType => RT::Asset->CustomFieldLookupType, |
| 15 | + ); |
| 16 | + ok( $ok, "Created custom role: $msg" ); |
| 17 | + |
| 18 | + ( $ok, $msg ) = $role->AddToObject( $catalog->Id ); |
| 19 | + ok( $ok, "Added role to catalog: $msg" ); |
| 20 | +} |
| 21 | + |
| 22 | +# Create a test asset |
| 23 | +my $asset = RT::Asset->new( RT->SystemUser ); |
| 24 | +my ($id, $msg) = $asset->Create( |
| 25 | + Name => 'Thinkpad T420s', |
| 26 | + Description => 'Laptop', |
| 27 | + Catalog => $catalog->Name, |
| 28 | +); |
| 29 | +ok $id, "Created: $msg"; |
| 30 | + |
| 31 | +my ( $baseurl, $m ) = RT::Test->started_ok; |
| 32 | +ok $m->login, 'logged in as root'; |
| 33 | + |
| 34 | +# Test that custom role is visible by default |
| 35 | +$m->get_ok( "/Asset/Create.html?Catalog=" . $catalog->Id ); |
| 36 | +$m->content_contains( $_, "Custom roles are visible on Create page by default" ) |
| 37 | + for qw/SingleTestCustomRole MultipleTestCustomRole/; |
| 38 | + |
| 39 | +$m->get_ok( "/Asset/Display.html?id=" . $asset->Id ); |
| 40 | +$m->content_contains( $_, "Custom roles are visible on display page by default" ) |
| 41 | + for qw/SingleTestCustomRole MultipleTestCustomRole/; |
| 42 | + |
| 43 | +diag( 'Test hiding custom roles with page layout configuration' ); |
| 44 | + |
| 45 | +# Configure page layout to hide custom role in People widget |
| 46 | +my %layout = ( |
| 47 | + 'RT::Asset' => { |
| 48 | + 'Create' => { |
| 49 | + 'Default' => [ |
| 50 | + { 'Elements' => [ |
| 51 | + [ { Name => 'People', |
| 52 | + HiddenRoles => ['MultipleTestCustomRole'], |
| 53 | + }, |
| 54 | + 'Submit' |
| 55 | + ], |
| 56 | + [ 'Basics', ] |
| 57 | + ] |
| 58 | + } |
| 59 | + ] |
| 60 | + }, |
| 61 | + 'Display' => { |
| 62 | + 'Default' => [ |
| 63 | + { 'Layout' => 'col-12', |
| 64 | + 'Elements' => [ |
| 65 | + [ |
| 66 | + { Name => 'People', |
| 67 | + HiddenRoles => [ 'SingleTestCustomRole', 'MultipleTestCustomRole' ] |
| 68 | + }, |
| 69 | + ] |
| 70 | + ] |
| 71 | + } |
| 72 | + ] |
| 73 | + }, |
| 74 | + } |
| 75 | +); |
| 76 | + |
| 77 | +my $config = RT::Configuration->new( RT->SystemUser ); |
| 78 | +( my $ret, $msg ) = $config->Create( Name => 'PageLayouts', Content => \%layout ); |
| 79 | +ok( $ret, 'Updated config' ); |
| 80 | + |
| 81 | + |
| 82 | +$m->get_ok( '/Asset/Create.html?Catalog=' . $catalog->Id ); |
| 83 | +$m->text_contains( 'SingleTestCustomRole', 'SingleTestCustomRole still appears on page in People widget' ); |
| 84 | +$m->text_lacks( 'MultipleTestCustomRole', 'MultipleTestCustomRole is now hidden' ); |
| 85 | + |
| 86 | +$m->get_ok( '/Asset/Display.html?id=' . $asset->Id ); |
| 87 | +$m->text_lacks( 'TestCustomRole', 'TestCustomRoles are hidden' ); |
| 88 | + |
| 89 | +done_testing(); |
0 commit comments