root/branches/feature-narrow-tables/t/22-author.t @ 1867

Revision 1867, 4.9 kB (checked in by mpaschal, 20 months ago)

Test favorite_blogs metadata too

  • Property svn:mime-type set to text/plain
  • Property svn:keywords set to Author Date Id Revision
Line 
1#!/usr/bin/perl
2# $Id$
3use strict;
4use warnings;
5
6use lib 't/lib';
7use lib 'lib';
8use lib 'extlib';
9
10use Test::More tests => 64;
11
12use MT;
13use MT::Author;
14use vars qw( $DB_DIR $T_CFG );
15
16use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib';
17
18use MT::Test qw(:db :data);
19
20my $mt = MT->new( Config => $T_CFG ) or die MT->errstr;
21isa_ok($mt, 'MT');
22
23{
24my $author = MT::Author->load({ name => 'Chuck D' });
25isa_ok($author, 'MT::Author');
26ok($author->is_valid_password('bass'), 'bass is valid');
27ok(!$author->is_valid_password('wrong'), 'wrong is invalid');
28
29ok($author->can_create_blog, 'can create blog');
30ok($author->can_view_log, 'can view log');
31ok($author->can_manage_plugins, 'can manage plugins');
32
33# Superuser Chuck D should have permission to do anything, on any blog
34my $perm = $author->blog_perm(1);
35ok($perm, "$author->blog_perm(1)") || die;
36ok($author->can_edit_entry(1), 'Chuck D can edit entry #1');
37ok($author->can_edit_entry(2), 'Chuck D can edit entry #2');
38ok($perm->can_comment, 'can_comment');
39ok($perm->can_post, 'can_post');
40ok($perm->can_create_post, 'can_create_post');
41ok($perm->can_publish_post, 'can_publish_post');
42ok($perm->can_upload, 'can_upload');
43ok($perm->can_edit_all_posts, 'can_edit_all_posts');
44ok($perm->can_manage_pages, 'can_manage_pages');
45ok($perm->can_edit_templates, 'can_edit_templates');
46ok($perm->can_edit_tags, 'can_edit_tags');
47ok($perm->can_edit_config, 'can_edit_config');
48ok($perm->can_set_publish_paths, 'can_set_publish_paths');
49ok($perm->can_rebuild, 'can_rebuild');
50ok($perm->can_send_notifications, 'can_send_notifications');
51ok($perm->can_edit_categories, 'can_edit_categories');
52ok($perm->can_edit_notifications, 'can_edit_notifications');
53ok($perm->can_administer_blog, 'can_administer_blog');
54ok($perm->can_edit_assets, 'can_edit_assets');
55ok($perm->can_save_image_defaults, 'can_save_image_defaults');
56ok($perm->can_manage_feedback, 'can_manage_feedback');
57}
58
59{
60diag('meta field tests');
61
62my $author = MT::Author->load({ name => 'Chuck D' });
63ok(eval { $author->widgets(); 1 }, 'Author obj has widgets accessor');
64ok(!defined $author->widgets, "Author's widgets are undefined by default");
65ok(!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
76my $fav_blogs = [1, 7];  # not actually a blog #7, but meh
77
78ok($author->widgets($default_widgets), "Author's widgets can be set");
79ok($author->favorite_blogs($fav_blogs), "Author's favorite blogs can be set");
80ok($author->save(), "Author with modified widgets can be saved");
81
82require MT::ObjectDriver::Driver::Cache::RAM;
83MT::ObjectDriver::Driver::Cache::RAM->clear_cache();
84
85$author = MT::Author->load({ name => 'Chuck D' });
86
87ok($author->widgets, "Modified author has widgets");
88is_deeply($author->widgets, $default_widgets, "Author's widgets survived being saved accurately");
89
90ok($author->favorite_blogs, "Modified author has favorite blogs");
91is_deeply($author->favorite_blogs, $fav_blogs, "Author's favorite blogs survived being saved accurately");
92}
93
94{
95my $author = MT::Author->load({ name => 'Bob D' });
96$author = MT::Author->load($author->id);  # silly ruse to force caching....
97isa_ok($author, 'MT::Author');
98
99# Non-superuser Bob D should only have selected permissions
100my $perm = $author->blog_perm(1);
101ok($perm, "$author->blog_perm(1)") || die;
102ok( ! $author->can_create_blog, 'can_create_blog' );
103ok( ! $author->can_view_log, 'can_view_log' );
104ok( ! $author->can_manage_plugins, 'can manage plugins');
105ok( ! $author->can_edit_entry(1), 'Bob D can edit entry #1' );
106ok(   $author->can_edit_entry(2), 'Bob D can edit entry #2' );
107ok(   $perm->can_post, 'can_post' );
108ok(   $perm->can_create_post, 'can_create_post');
109ok(   $perm->can_publish_post, 'can_publish_post');
110ok(   $perm->can_upload, 'Bob D can *not* upload files' );
111ok( ! $perm->can_edit_all_posts, 'Bob D can *not* edit all posts' );
112ok( ! $perm->can_manage_pages, 'can_manage_pages');
113ok( ! $perm->can_edit_templates, 'Bob D can *not* edit templates' );
114ok( ! $perm->can_edit_tags, 'can_edit_tags');
115ok( ! $perm->can_edit_config, 'can_edit_config' );
116ok( ! $perm->can_set_publish_paths, 'can_set_publish_paths');
117ok( ! $perm->can_rebuild, 'can_rebuild' );
118ok(   $perm->can_send_notifications, 'Bob D can send notifications' );
119ok( ! $perm->can_edit_categories, 'can_edit_categories' );
120ok( ! $perm->can_edit_notifications, 'can_edit_notifications' );
121ok( ! $perm->can_administer_blog, 'can_administer_blog' );
122ok( ! $perm->can_edit_assets, 'can_edit_assets');
123ok( ! $perm->can_save_image_defaults, 'can_save_image_defaults');
124ok( ! $perm->can_manage_feedback, 'can_manage_feedback');
125}
Note: See TracBrowser for help on using the browser.