| 1 | #!/usr/bin/perl |
|---|
| 2 | # $Id: 22-author.t 1927 2008-04-16 15:36:30Z mpaschal $ |
|---|
| 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 => 64; |
|---|
| 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), 'Chuck D can edit entry #1'); |
|---|
| 37 | ok($author->can_edit_entry(2), 'Chuck D 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 | diag('meta field tests'); |
|---|
| 61 | |
|---|
| 62 | my $author = MT::Author->load({ name => 'Chuck D' }); |
|---|
| 63 | ok(eval { $author->widgets(); 1 }, 'Author obj has widgets accessor'); |
|---|
| 64 | ok(!defined $author->widgets, "Author's widgets are undefined by default"); |
|---|
| 65 | ok(!defined $author->favorite_blogs, "Author's favorite blogs are undefined by default"); |
|---|
| 66 | |
|---|
| 67 | # same as in MT::CMS::Dashboard, but that's not necessary |
|---|
| 68 | my $default_widgets = { |
|---|
| 69 | 'blog_stats' => |
|---|
| 70 | { param => { tab => 'entry' }, order => 1, set => 'main' }, |
|---|
| 71 | 'this_is_you-1' => { order => 1, set => 'sidebar' }, |
|---|
| 72 | 'mt_shortcuts' => { order => 2, set => 'sidebar' }, |
|---|
| 73 | 'mt_news' => { order => 3, set => 'sidebar' }, |
|---|
| 74 | }; |
|---|
| 75 | |
|---|
| 76 | my $fav_blogs = [1, 7]; # not actually a blog #7, but meh |
|---|
| 77 | |
|---|
| 78 | ok($author->widgets($default_widgets), "Author's widgets can be set"); |
|---|
| 79 | ok($author->favorite_blogs($fav_blogs), "Author's favorite blogs can be set"); |
|---|
| 80 | ok($author->save(), "Author with modified widgets can be saved"); |
|---|
| 81 | |
|---|
| 82 | require MT::ObjectDriver::Driver::Cache::RAM; |
|---|
| 83 | MT::ObjectDriver::Driver::Cache::RAM->clear_cache(); |
|---|
| 84 | |
|---|
| 85 | $author = MT::Author->load({ name => 'Chuck D' }); |
|---|
| 86 | |
|---|
| 87 | ok($author->widgets, "Modified author has widgets"); |
|---|
| 88 | is_deeply($author->widgets, $default_widgets, "Author's widgets survived being saved accurately"); |
|---|
| 89 | |
|---|
| 90 | ok($author->favorite_blogs, "Modified author has favorite blogs"); |
|---|
| 91 | is_deeply($author->favorite_blogs, $fav_blogs, "Author's favorite blogs survived being saved accurately"); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | { |
|---|
| 95 | my $author = MT::Author->load({ name => 'Bob D' }); |
|---|
| 96 | $author = MT::Author->load($author->id); # silly ruse to force caching.... |
|---|
| 97 | isa_ok($author, 'MT::Author'); |
|---|
| 98 | |
|---|
| 99 | # Non-superuser Bob D should only have selected permissions |
|---|
| 100 | my $perm = $author->blog_perm(1); |
|---|
| 101 | ok($perm, "$author->blog_perm(1)") || die; |
|---|
| 102 | ok( ! $author->can_create_blog, 'can_create_blog' ); |
|---|
| 103 | ok( ! $author->can_view_log, 'can_view_log' ); |
|---|
| 104 | ok( ! $author->can_manage_plugins, 'can manage plugins'); |
|---|
| 105 | ok( ! $author->can_edit_entry(1), 'Bob D can edit entry #1' ); |
|---|
| 106 | ok( $author->can_edit_entry(2), 'Bob D can edit entry #2' ); |
|---|
| 107 | ok( $perm->can_post, 'can_post' ); |
|---|
| 108 | ok( $perm->can_create_post, 'can_create_post'); |
|---|
| 109 | ok( $perm->can_publish_post, 'can_publish_post'); |
|---|
| 110 | ok( $perm->can_upload, 'Bob D can *not* upload files' ); |
|---|
| 111 | ok( ! $perm->can_edit_all_posts, 'Bob D can *not* edit all posts' ); |
|---|
| 112 | ok( ! $perm->can_manage_pages, 'can_manage_pages'); |
|---|
| 113 | ok( ! $perm->can_edit_templates, 'Bob D can *not* edit templates' ); |
|---|
| 114 | ok( ! $perm->can_edit_tags, 'can_edit_tags'); |
|---|
| 115 | ok( ! $perm->can_edit_config, 'can_edit_config' ); |
|---|
| 116 | ok( ! $perm->can_set_publish_paths, 'can_set_publish_paths'); |
|---|
| 117 | ok( ! $perm->can_rebuild, 'can_rebuild' ); |
|---|
| 118 | ok( $perm->can_send_notifications, 'Bob D can send notifications' ); |
|---|
| 119 | ok( ! $perm->can_edit_categories, 'can_edit_categories' ); |
|---|
| 120 | ok( ! $perm->can_edit_notifications, 'can_edit_notifications' ); |
|---|
| 121 | ok( ! $perm->can_administer_blog, 'can_administer_blog' ); |
|---|
| 122 | ok( ! $perm->can_edit_assets, 'can_edit_assets'); |
|---|
| 123 | ok( ! $perm->can_save_image_defaults, 'can_save_image_defaults'); |
|---|
| 124 | ok( ! $perm->can_manage_feedback, 'can_manage_feedback'); |
|---|
| 125 | } |
|---|