3 use RT::Test tests => undef;
5 my $root = RT::Test->load_or_create_user( Name => 'root', );
6 my $user_foo = RT::Test->load_or_create_user(
8 Password => 'password',
10 my $user_bar = RT::Test->load_or_create_user( Name => 'bar' );
11 my $user_baz = RT::Test->load_or_create_user( Name => 'baz' );
12 $user_baz->SetDisabled(1);
14 my ( $baseurl, $m ) = RT::Test->started_ok;
16 ok( $m->login, 'logged in' );
19 { query => 'id = ' . $user_foo->id },
20 [ $user_foo->id . ': foo' ],
26 query => 'Name = ' . $user_foo->Name,
30 [ "id\tName", $user_foo->id . "\tfoo" ],
31 'search by name with customized fields'
36 { query => 'foo = 3' },
37 ['Invalid field specification: foo'],
42 { query => 'id foo 3' },
43 ['Invalid operator specification: foo'],
48 { query => 'password = foo' },
49 ['Invalid field specification: password'],
50 "can't search password"
54 { query => '', orderby => 'id' },
55 [ $root->id . ': root', $user_foo->id . ': foo', $user_bar->id . ': bar', ],
60 { query => '', orderby => 'name' },
61 [ $user_bar->id . ': bar', $user_foo->id . ': foo', $root->id . ': root' ],
66 { query => '', orderby => '+name' },
67 [ $user_bar->id . ': bar', $user_foo->id . ': foo', $root->id . ': root' ],
72 { query => '', orderby => '-name' },
73 [ $root->id . ': root', $user_foo->id . ': foo', $user_bar->id . ': bar' ],
78 { query => 'Disabled = 0', orderby => 'id' },
79 [ $root->id . ': root', $user_foo->id . ': foo', $user_bar->id . ': bar', ],
84 { query => 'Disabled = 1', orderby => 'id' },
85 [ $user_baz->id . ': baz', ],
89 ok( $m->login( 'foo', 'password', logout => 1 ), 'logged in as foo' );
91 { query => 'id = ' . $user_foo->id },
92 [ 'Permission denied' ],
93 "can't search without permission"
97 local $Test::Builder::Level = $Test::Builder::Level + 1;
100 my $name = shift || 'search users';
102 my $uri = URI->new("$baseurl/REST/1.0/search/user");
103 $uri->query_form(%$query);
106 my @lines = split /\n/, $m->content;
107 shift @lines; # header
108 shift @lines; # empty line
110 is_deeply( \@lines, $expected, $name );