| 1 | #!/usr/bin/perl |
|---|
| 2 | # $Id$ |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use lib 't/lib'; |
|---|
| 7 | use lib 'lib'; |
|---|
| 8 | use lib 'extlib'; |
|---|
| 9 | |
|---|
| 10 | use Test::More tests => 54; |
|---|
| 11 | |
|---|
| 12 | use MT; |
|---|
| 13 | use MT::Author; |
|---|
| 14 | use vars qw( $DB_DIR $T_CFG ); |
|---|
| 15 | |
|---|
| 16 | use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; |
|---|
| 17 | |
|---|
| 18 | use MT::Test qw(:db :data); |
|---|
| 19 | |
|---|
| 20 | my $mt = MT->new( Config => $T_CFG ) or die MT->errstr; |
|---|
| 21 | isa_ok($mt, 'MT'); |
|---|
| 22 | |
|---|
| 23 | { |
|---|
| 24 | my $author = MT::Author->load({ name => 'Chuck D' }); |
|---|
| 25 | isa_ok($author, 'MT::Author'); |
|---|
| 26 | ok($author->is_valid_password('bass'), 'bass is valid'); |
|---|
| 27 | ok(!$author->is_valid_password('wrong'), 'wrong is invalid'); |
|---|
| 28 | |
|---|
| 29 | ok($author->can_create_blog, 'can create blog'); |
|---|
| 30 | ok($author->can_view_log, 'can view log'); |
|---|
| 31 | ok($author->can_manage_plugins, 'can manage plugins'); |
|---|
| 32 | |
|---|
| 33 | # Superuser Chuck D should have permission to do anything, on any blog |
|---|
| 34 | my $perm = $author->blog_perm(1); |
|---|
| 35 | ok($perm, "$author->blog_perm(1)") || die; |
|---|
| 36 | ok($author->can_edit_entry(1), 'can_edit_entry(1)'); |
|---|
| 37 | ok($author->can_edit_entry(2), 'can_edit_entry(2)'); |
|---|
| 38 | ok($perm->can_comment, 'can_comment'); |
|---|
| 39 | ok($perm->can_post, 'can_post'); |
|---|
| 40 | ok($perm->can_create_post, 'can_create_post'); |
|---|
| 41 | ok($perm->can_publish_post, 'can_publish_post'); |
|---|
| 42 | ok($perm->can_upload, 'can_upload'); |
|---|
| 43 | ok($perm->can_edit_all_posts, 'can_edit_all_posts'); |
|---|
| 44 | ok($perm->can_manage_pages, 'can_manage_pages'); |
|---|
| 45 | ok($perm->can_edit_templates, 'can_edit_templates'); |
|---|
| 46 | ok($perm->can_edit_tags, 'can_edit_tags'); |
|---|
| 47 | ok($perm->can_edit_config, 'can_edit_config'); |
|---|
| 48 | ok($perm->can_set_publish_paths, 'can_set_publish_paths'); |
|---|
| 49 | ok($perm->can_rebuild, 'can_rebuild'); |
|---|
| 50 | ok($perm->can_send_notifications, 'can_send_notifications'); |
|---|
| 51 | ok($perm->can_edit_categories, 'can_edit_categories'); |
|---|
| 52 | ok($perm->can_edit_notifications, 'can_edit_notifications'); |
|---|
| 53 | ok($perm->can_administer_blog, 'can_administer_blog'); |
|---|
| 54 | ok($perm->can_edit_assets, 'can_edit_assets'); |
|---|
| 55 | ok($perm->can_save_image_defaults, 'can_save_image_defaults'); |
|---|
| 56 | ok($perm->can_manage_feedback, 'can_manage_feedback'); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | { |
|---|
| 60 | my $author = MT::Author->load({ name => 'Bob D' }); |
|---|
| 61 | $author = MT::Author->load($author->id); # silly ruse to force caching.... |
|---|
| 62 | isa_ok($author, 'MT::Author'); |
|---|
| 63 | |
|---|
| 64 | # Non-superuser Bob D should only have selected permissions |
|---|
| 65 | my $perm = $author->blog_perm(1); |
|---|
| 66 | ok($perm, "$author->blog_perm(1)") || die; |
|---|
| 67 | ok( ! $author->can_create_blog, 'can_create_blog' ); |
|---|
| 68 | ok( ! $author->can_view_log, 'can_view_log' ); |
|---|
| 69 | ok( ! $author->can_manage_plugins, 'can manage plugins'); |
|---|
| 70 | ok( ! $author->can_edit_entry(1), 'can_edit_entry(1)' ); |
|---|
| 71 | ok( $author->can_edit_entry(2), 'can_edit_entry(2)' ); |
|---|
| 72 | ok( $perm->can_post, 'can_post' ); |
|---|
| 73 | ok( $perm->can_create_post, 'can_create_post'); |
|---|
| 74 | ok( $perm->can_publish_post, 'can_publish_post'); |
|---|
| 75 | ok( ! $perm->can_upload, 'can_upload' ); |
|---|
| 76 | ok( ! $perm->can_edit_all_posts, 'can_edit_all_posts' ); |
|---|
| 77 | ok( ! $perm->can_manage_pages, 'can_manage_pages'); |
|---|
| 78 | ok( $perm->can_edit_templates, 'can_edit_templates' ); |
|---|
| 79 | ok( ! $perm->can_edit_tags, 'can_edit_tags'); |
|---|
| 80 | ok( ! $perm->can_edit_config, 'can_edit_config' ); |
|---|
| 81 | ok( ! $perm->can_set_publish_paths, 'can_set_publish_paths'); |
|---|
| 82 | ok( ! $perm->can_rebuild, 'can_rebuild' ); |
|---|
| 83 | ok( ! $perm->can_send_notifications, 'can_send_notifications' ); |
|---|
| 84 | ok( ! $perm->can_edit_categories, 'can_edit_categories' ); |
|---|
| 85 | ok( ! $perm->can_edit_notifications, 'can_edit_notifications' ); |
|---|
| 86 | ok( ! $perm->can_administer_blog, 'can_administer_blog' ); |
|---|
| 87 | ok( ! $perm->can_edit_assets, 'can_edit_assets'); |
|---|
| 88 | ok( ! $perm->can_save_image_defaults, 'can_save_image_defaults'); |
|---|
| 89 | ok( ! $perm->can_manage_feedback, 'can_manage_feedback'); |
|---|
| 90 | } |
|---|