diff options
author | Perl Tidy <perltidy@bugzilla.org> | 2018-12-05 21:38:52 +0100 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-12-05 23:49:08 +0100 |
commit | 8ec8da0491ad89604700b3e29a227966f6d84ba1 (patch) | |
tree | 9d270f173330ca19700e0ba9f2ee931300646de1 /qa/t/webservice_bug_comments.t | |
parent | a7bb5a65b71644d9efce5fed783ed545b9336548 (diff) | |
download | bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.gz bugzilla-8ec8da0491ad89604700b3e29a227966f6d84ba1.tar.xz |
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'qa/t/webservice_bug_comments.t')
-rw-r--r-- | qa/t/webservice_bug_comments.t | 228 |
1 files changed, 128 insertions, 100 deletions
diff --git a/qa/t/webservice_bug_comments.t b/qa/t/webservice_bug_comments.t index ccc0c6d34..f3f834f85 100644 --- a/qa/t/webservice_bug_comments.t +++ b/qa/t/webservice_bug_comments.t @@ -21,46 +21,50 @@ my ($config, @clients) = get_rpc_clients(); # These gets populated when we call Bug.add_comment. our $creation_time; our %comments = ( - public_comment_public_bug => 0, - public_comment_private_bug => 0, - private_comment_public_bug => 0, - private_comment_private_bug => 0, + public_comment_public_bug => 0, + public_comment_private_bug => 0, + private_comment_public_bug => 0, + private_comment_private_bug => 0, ); sub test_comments { - my ($comments_returned, $call, $t, $rpc) = @_; + my ($comments_returned, $call, $t, $rpc) = @_; - my $comment = $comments_returned->[0]; - ok($comment->{bug_id}, "bug_id exists"); - # FIXME: At some point we should test attachment_id here. + my $comment = $comments_returned->[0]; + ok($comment->{bug_id}, "bug_id exists"); - if ($t->{args}->{comment_ids}) { - my $expected_id = $t->{args}->{comment_ids}->[0]; - is($comment->{id}, $expected_id, "comment id is correct"); + # FIXME: At some point we should test attachment_id here. - my %reverse_map = reverse %comments; - my $expected_text = $reverse_map{$expected_id}; - is($comment->{text}, $expected_text, "comment has the correct text"); + if ($t->{args}->{comment_ids}) { + my $expected_id = $t->{args}->{comment_ids}->[0]; + is($comment->{id}, $expected_id, "comment id is correct"); - my $priv_login = $rpc->bz_config->{PRIVATE_BUG_USER . '_user_login'}; - is($comment->{creator}, $priv_login, "comment creator is correct"); + my %reverse_map = reverse %comments; + my $expected_text = $reverse_map{$expected_id}; + is($comment->{text}, $expected_text, "comment has the correct text"); + my $priv_login = $rpc->bz_config->{PRIVATE_BUG_USER . '_user_login'}; + is($comment->{creator}, $priv_login, "comment creator is correct"); - my $creation_day; - if ($rpc->isa('QA::RPC::XMLRPC')) { - $creation_day = $creation_time->ymd(''); - } - else { - $creation_day = $creation_time->ymd; - } - like($comment->{time}, qr/^\Q${creation_day}\ET\d\d:\d\d:\d\d/, - "comment time has the right format"); + + my $creation_day; + if ($rpc->isa('QA::RPC::XMLRPC')) { + $creation_day = $creation_time->ymd(''); } else { - foreach my $field (qw(id text creator time)) { - ok(defined $comment->{$field}, "$field is defined"); - } + $creation_day = $creation_time->ymd; + } + like( + $comment->{time}, + qr/^\Q${creation_day}\ET\d\d:\d\d:\d\d/, + "comment time has the right format" + ); + } + else { + foreach my $field (qw(id text creator time)) { + ok(defined $comment->{$field}, "$field is defined"); } + } } ################ @@ -68,16 +72,19 @@ sub test_comments { ################ sub post_bug_success { - my ($call, $t) = @_; - my @bugs = values %{ $call->result->{bugs} }; - is(scalar @bugs, 1, "Got exactly one bug"); - my @comments = map { @{ $_->{comments} } } @bugs; - test_comments(\@comments, @_); + my ($call, $t) = @_; + my @bugs = values %{$call->result->{bugs}}; + is(scalar @bugs, 1, "Got exactly one bug"); + my @comments = map { @{$_->{comments}} } @bugs; + test_comments(\@comments, @_); } foreach my $rpc (@clients) { - $rpc->bz_run_tests(tests => STANDARD_BUG_TESTS, method => 'Bug.comments', - post_success => \&post_bug_success); + $rpc->bz_run_tests( + tests => STANDARD_BUG_TESTS, + method => 'Bug.comments', + post_success => \&post_bug_success + ); } #################### @@ -87,89 +94,110 @@ foreach my $rpc (@clients) { # First, create comments using add_comment. my @add_comment_tests; foreach my $key (keys %comments) { - $key =~ /^([a-z]+)_comment_(\w+)$/; - my $is_private = ($1 eq 'private' ? 1 : 0); - my $bug_alias = $2; - push(@add_comment_tests, { args => { id => $bug_alias, comment => $key, - private => $is_private }, - test => "Add comment: $key", - user => PRIVATE_BUG_USER }); + $key =~ /^([a-z]+)_comment_(\w+)$/; + my $is_private = ($1 eq 'private' ? 1 : 0); + my $bug_alias = $2; + push( + @add_comment_tests, + { + args => {id => $bug_alias, comment => $key, private => $is_private}, + test => "Add comment: $key", + user => PRIVATE_BUG_USER + } + ); } # Set the comment id for each comment that we add, so we can test getting # them back, later. sub post_add { - my ($call, $t) = @_; - my $key = $t->{args}->{comment}; - $comments{$key} = $call->result->{id}; + my ($call, $t) = @_; + my $key = $t->{args}->{comment}; + $comments{$key} = $call->result->{id}; } $creation_time = DateTime->now(); + # We only need to create these comments once, with one of the interfaces. $clients[0]->bz_run_tests( - tests => \@add_comment_tests, method => 'Bug.add_comment', - post_success => \&post_add); + tests => \@add_comment_tests, + method => 'Bug.add_comment', + post_success => \&post_add +); # Now check access on each private and public comment my @comment_tests = ( - # Logged-out user - { args => { comment_ids => [$comments{'public_comment_public_bug'}] }, - test => 'Logged-out user can access public comment on public bug by id', - }, - { args => { comment_ids => [$comments{'private_comment_public_bug'}] }, - test => 'Logged-out user cannot access private comment on public bug', - error => 'is private', - }, - { args => { comment_ids => [$comments{'public_comment_private_bug'}] }, - test => 'Logged-out user cannot access comments by id on private bug', - error => 'You are not authorized to access', - }, - { args => { comment_ids => [$comments{'private_comment_private_bug'}] }, - test => 'Logged-out user cannot access private comment on private bug', - error => 'You are not authorized to access', - }, - - # Logged-in, unprivileged user. - { user => 'unprivileged', - args => { comment_ids => [$comments{'public_comment_public_bug'}] }, - test => 'Logged-in user can see a public comment on a public bug by id', - }, - { user => 'unprivileged', - args => { comment_ids => [$comments{'private_comment_public_bug'}] }, - test => 'Logged-in user cannot access private comment on public bug', - error => 'is private', - }, - { user => 'unprivileged', - args => { comment_ids => [$comments{'public_comment_private_bug'}] }, - test => 'Logged-in user cannot access comments by id on private bug', - error => "You are not authorized to access", - }, - { user => 'unprivileged', - args => { comment_ids => [$comments{'private_comment_private_bug'}] }, - test => 'Logged-in user cannot access private comment on private bug', - error => "You are not authorized to access", - }, - - # User who can see private bugs and private comments - { user => PRIVATE_BUG_USER, - args => { comment_ids => [$comments{'private_comment_public_bug'}] }, - test => PRIVATE_BUG_USER . ' can see private comment on public bug', - }, - { user => PRIVATE_BUG_USER, - args => { comment_ids => [$comments{'private_comment_private_bug'}] }, - test => PRIVATE_BUG_USER . ' can see private comment on private bug', - }, + + # Logged-out user + { + args => {comment_ids => [$comments{'public_comment_public_bug'}]}, + test => 'Logged-out user can access public comment on public bug by id', + }, + { + args => {comment_ids => [$comments{'private_comment_public_bug'}]}, + test => 'Logged-out user cannot access private comment on public bug', + error => 'is private', + }, + { + args => {comment_ids => [$comments{'public_comment_private_bug'}]}, + test => 'Logged-out user cannot access comments by id on private bug', + error => 'You are not authorized to access', + }, + { + args => {comment_ids => [$comments{'private_comment_private_bug'}]}, + test => 'Logged-out user cannot access private comment on private bug', + error => 'You are not authorized to access', + }, + + # Logged-in, unprivileged user. + { + user => 'unprivileged', + args => {comment_ids => [$comments{'public_comment_public_bug'}]}, + test => 'Logged-in user can see a public comment on a public bug by id', + }, + { + user => 'unprivileged', + args => {comment_ids => [$comments{'private_comment_public_bug'}]}, + test => 'Logged-in user cannot access private comment on public bug', + error => 'is private', + }, + { + user => 'unprivileged', + args => {comment_ids => [$comments{'public_comment_private_bug'}]}, + test => 'Logged-in user cannot access comments by id on private bug', + error => "You are not authorized to access", + }, + { + user => 'unprivileged', + args => {comment_ids => [$comments{'private_comment_private_bug'}]}, + test => 'Logged-in user cannot access private comment on private bug', + error => "You are not authorized to access", + }, + + # User who can see private bugs and private comments + { + user => PRIVATE_BUG_USER, + args => {comment_ids => [$comments{'private_comment_public_bug'}]}, + test => PRIVATE_BUG_USER . ' can see private comment on public bug', + }, + { + user => PRIVATE_BUG_USER, + args => {comment_ids => [$comments{'private_comment_private_bug'}]}, + test => PRIVATE_BUG_USER . ' can see private comment on private bug', + }, ); sub post_comments { - my ($call) = @_; - my @comments = values %{ $call->result->{comments} }; - is(scalar @comments, 1, "Got exactly one comment"); - test_comments(\@comments, @_); + my ($call) = @_; + my @comments = values %{$call->result->{comments}}; + is(scalar @comments, 1, "Got exactly one comment"); + test_comments(\@comments, @_); } foreach my $rpc (@clients) { - $rpc->bz_run_tests(tests => \@comment_tests, method => 'Bug.comments', - post_success => \&post_comments); + $rpc->bz_run_tests( + tests => \@comment_tests, + method => 'Bug.comments', + post_success => \&post_comments + ); } |