| 1 | #!/usr/bin/perl |
|---|
| 2 | use strict; |
|---|
| 3 | use warnings; |
|---|
| 4 | |
|---|
| 5 | use lib 't/lib'; |
|---|
| 6 | use lib 'lib'; |
|---|
| 7 | use lib 'extlib'; |
|---|
| 8 | |
|---|
| 9 | # $Id$ |
|---|
| 10 | |
|---|
| 11 | use Test::More qw(no_plan); |
|---|
| 12 | |
|---|
| 13 | use MT; |
|---|
| 14 | use MT::Author; |
|---|
| 15 | use MT::Blog; |
|---|
| 16 | use MT::Category; |
|---|
| 17 | use MT::Comment; |
|---|
| 18 | use MT::Entry; |
|---|
| 19 | use MT::Permission; |
|---|
| 20 | use MT::Template; |
|---|
| 21 | use MT::TemplateMap; |
|---|
| 22 | |
|---|
| 23 | use vars qw( $DB_DIR $T_CFG ); |
|---|
| 24 | use lib 't'; |
|---|
| 25 | |
|---|
| 26 | my $mt; |
|---|
| 27 | BEGIN { |
|---|
| 28 | require 'test-common.pl'; |
|---|
| 29 | if (-d $DB_DIR) { |
|---|
| 30 | system "rm -rf $DB_DIR"; |
|---|
| 31 | } |
|---|
| 32 | mkdir $DB_DIR or die "Can't create dir '$DB_DIR': $!"; |
|---|
| 33 | my $old = umask 0000; |
|---|
| 34 | chmod 0777, $DB_DIR or die "Can't chmod $DB_DIR: $!"; |
|---|
| 35 | umask $old; |
|---|
| 36 | open my $fh, ">$T_CFG" or die "Can't open $T_CFG: $!"; |
|---|
| 37 | print $fh <<CFG; |
|---|
| 38 | Database $DB_DIR/mt.db |
|---|
| 39 | ObjectDriver DBI::sqlite |
|---|
| 40 | PluginPath ../plugins |
|---|
| 41 | PluginPath plugins |
|---|
| 42 | CFG |
|---|
| 43 | close $fh; |
|---|
| 44 | $mt = MT->new( Config => $T_CFG ) or die MT->errstr; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | use MT::Test qw(:db); |
|---|
| 48 | |
|---|
| 49 | my $BLOG_NAME = 'Fear of a Black Planet'; |
|---|
| 50 | my $BLOG_DESC = 'Wherein Chuck D expounds on the plight of the black man in ' . |
|---|
| 51 | 'a white man\'s world.'; |
|---|
| 52 | my $BLOG_URL = 'http://www.black-planet.org/'; |
|---|
| 53 | my $BLOG_PATH = '/opt/www/content/blog'; |
|---|
| 54 | |
|---|
| 55 | my $blog = MT::Blog->new; |
|---|
| 56 | isa_ok($blog, 'MT::Blog'); |
|---|
| 57 | $blog->name($BLOG_NAME); |
|---|
| 58 | $blog->description($BLOG_DESC); |
|---|
| 59 | $blog->site_url($BLOG_URL); |
|---|
| 60 | $blog->archive_url($BLOG_URL . 'bass-ment/'); |
|---|
| 61 | $blog->site_path($BLOG_PATH); |
|---|
| 62 | $blog->archive_path($BLOG_PATH . 'bass-ment/'); |
|---|
| 63 | $blog->archive_type('Monthly,Daily,Weekly,Individual,Category'); |
|---|
| 64 | $blog->archive_type_preferred('Monthly'); |
|---|
| 65 | $blog->days_on_index(7); |
|---|
| 66 | $blog->words_in_excerpt(40); |
|---|
| 67 | $blog->file_extension('html'); |
|---|
| 68 | $blog->convert_paras(1); |
|---|
| 69 | $blog->convert_paras_comments(1); |
|---|
| 70 | $blog->sanitize_spec(0); |
|---|
| 71 | $blog->ping_weblogs(0); |
|---|
| 72 | $blog->ping_blogs(0); |
|---|
| 73 | $blog->server_offset(0); |
|---|
| 74 | $blog->allow_comments_default(1); |
|---|
| 75 | $blog->language('en'); |
|---|
| 76 | $blog->sort_order_posts('descend'); |
|---|
| 77 | $blog->sort_order_comments('ascend'); |
|---|
| 78 | $blog->status_default(1); |
|---|
| 79 | my $test = $blog->save or die $blog->errstr; |
|---|
| 80 | ok($test, "saved $blog"); |
|---|
| 81 | |
|---|
| 82 | my $author = MT::Author->new; |
|---|
| 83 | isa_ok($author, 'MT::Author'); |
|---|
| 84 | $author->name('Chuck D'); |
|---|
| 85 | $author->set_password('bass'); |
|---|
| 86 | $author->type(1); |
|---|
| 87 | $test = $author->save or die $author->errstr; |
|---|
| 88 | ok($test, "saved $author"); |
|---|
| 89 | |
|---|
| 90 | my $perms = MT::Permission->new; |
|---|
| 91 | $perms->author_id($author->id); |
|---|
| 92 | $perms->blog_id($blog->id); |
|---|
| 93 | $perms->set_full_permissions; |
|---|
| 94 | $test = $perms->save or die $perms->errstr; |
|---|
| 95 | ok($test, "saved $perms"); |
|---|
| 96 | |
|---|
| 97 | my($entry); |
|---|
| 98 | $entry = MT::Entry->new; |
|---|
| 99 | isa_ok($entry, 'MT::Entry'); |
|---|
| 100 | $entry->blog_id($blog->id); |
|---|
| 101 | $entry->status(2); |
|---|
| 102 | $entry->author_id($author->id); |
|---|
| 103 | $entry->title('Fight the Power'); |
|---|
| 104 | $entry->allow_comments(1); |
|---|
| 105 | $entry->excerpt('Fight the powers that be'); |
|---|
| 106 | $entry->text('Elvis was a hero to most but he never meant shit to me'); |
|---|
| 107 | $entry->text_more('straight up racist that sucker was simple and plain ' . |
|---|
| 108 | 'mother fuck him and john wayne'); |
|---|
| 109 | $test = $entry->save or die $entry->errstr; |
|---|
| 110 | ok($test, "saved $entry"); |
|---|
| 111 | |
|---|
| 112 | my $cat = MT::Category->new; |
|---|
| 113 | isa_ok($cat, 'MT::Category'); |
|---|
| 114 | $cat->blog_id($blog->id); |
|---|
| 115 | $cat->label('Foo'); |
|---|
| 116 | $test = $cat->save or die $cat->errstr; |
|---|
| 117 | ok($test, "saved Foo $cat"); |
|---|
| 118 | |
|---|
| 119 | $cat = MT::Category->new; |
|---|
| 120 | isa_ok($cat, 'MT::Category'); |
|---|
| 121 | $cat->blog_id($blog->id); |
|---|
| 122 | $cat->label('Bar'); |
|---|
| 123 | $test = $cat->save or die $cat->errstr; |
|---|
| 124 | ok($test, "saved Bar $cat"); |
|---|
| 125 | |
|---|
| 126 | my @arch_tmpl; |
|---|
| 127 | my $tmpl_list = require 'MT/default-templates.pl'; |
|---|
| 128 | for my $val (@$tmpl_list) { |
|---|
| 129 | my $obj = MT::Template->new; |
|---|
| 130 | foreach (keys %$val) { |
|---|
| 131 | $val->{$_} = $val->{$_}->() if ref($val->{$_}) eq 'CODE'; |
|---|
| 132 | delete $val->{$_} unless $obj->has_column($_); |
|---|
| 133 | } |
|---|
| 134 | $obj->set_values($val); |
|---|
| 135 | $obj->blog_id($blog->id); |
|---|
| 136 | $test = $obj->save or die $obj->errstr; |
|---|
| 137 | ok($test, "saved $obj"); |
|---|
| 138 | if ($val->{type} eq 'archive' || $val->{type} eq 'individual' || |
|---|
| 139 | $val->{type} eq 'category') { |
|---|
| 140 | push @arch_tmpl, $obj; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | for my $tmpl (@arch_tmpl) { |
|---|
| 145 | my(@at); |
|---|
| 146 | if ($tmpl->type eq 'archive') { |
|---|
| 147 | @at = qw( Daily Weekly Monthly ); |
|---|
| 148 | } elsif ($tmpl->type eq 'category') { |
|---|
| 149 | @at = qw( Category ); |
|---|
| 150 | } elsif ($tmpl->type eq 'individual') { |
|---|
| 151 | @at = qw( Individual ); |
|---|
| 152 | } |
|---|
| 153 | for my $at (@at) { |
|---|
| 154 | my $map = MT::TemplateMap->new; |
|---|
| 155 | $map->archive_type($at); |
|---|
| 156 | $map->is_preferred(1); |
|---|
| 157 | $map->template_id($tmpl->id); |
|---|
| 158 | $map->blog_id($tmpl->blog_id); |
|---|
| 159 | $test = $map->save or die $map->errstr; |
|---|
| 160 | ok($test, "saved $map"); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|