Fetching contributors…
Cannot retrieve contributors at this time
165 lines (148 sloc) 4.33 KB
use strict;
use warnings;
use lib 't/lib';
use lib 'lib';
use lib 'extlib';
# $Id: 20-setup.t 2562 2008-06-12 05:12:23Z bchoate $
use Test::More qw(no_plan);
use MT;
use MT::Test;
use MT::Author;
use MT::Blog;
use MT::Category;
use MT::Comment;
use MT::Entry;
use MT::Permission;
use MT::Template;
use MT::TemplateMap;
use vars qw( $DB_DIR $T_CFG );
use lib 't';
my $mt;
require '';
if (-d $DB_DIR) {
system "rm -rf $DB_DIR";
mkdir $DB_DIR or die "Can't create dir '$DB_DIR': $!";
my $old = umask 0000;
chmod 0777, $DB_DIR or die "Can't chmod $DB_DIR: $!";
umask $old;
open my $fh, ">$T_CFG" or die "Can't open $T_CFG: $!";
print $fh <<CFG;
Database $DB_DIR/mt.db
ObjectDriver DBI::sqlite
PluginPath ../plugins
PluginPath plugins
TemplatePath ../tmpl
close $fh;
$mt = MT->new( Config => $T_CFG ) or die MT->errstr;
use MT::Test qw(:db);
my $BLOG_NAME = 'Fear of a Black Planet';
my $BLOG_DESC = 'Wherein Chuck D expounds on the plight of the black man in ' .
'a white man\'s world.';
my $BLOG_URL = '';
my $BLOG_PATH = '/opt/www/content/blog';
my $blog = MT::Blog->new;
isa_ok($blog, 'MT::Blog');
$blog->archive_url($BLOG_URL . 'bass-ment/');
$blog->archive_path($BLOG_PATH . 'bass-ment/');
my $test = $blog->save or die $blog->errstr;
ok($test, "saved $blog");
my $author = MT::Author->new;
isa_ok($author, 'MT::Author');
$author->name('Chuck D');
$test = $author->save or die $author->errstr;
ok($test, "saved $author");
my $perms = MT::Permission->new;
$test = $perms->save or die $perms->errstr;
ok($test, "saved $perms");
$entry = MT::Entry->new;
isa_ok($entry, 'MT::Entry');
$entry->title('Fight the Power');
$entry->excerpt('Fight the powers that be');
$entry->text('Elvis was a hero to most but he never meant shit to me');
$entry->text_more('straight up racist that sucker was simple and plain ' .
'mother fuck him and john wayne');
$test = $entry->save or die $entry->errstr;
ok($test, "saved $entry");
my $cat = MT::Category->new;
isa_ok($cat, 'MT::Category');
$test = $cat->save or die $cat->errstr;
ok($test, "saved Foo $cat");
$cat = MT::Category->new;
isa_ok($cat, 'MT::Category');
$test = $cat->save or die $cat->errstr;
ok($test, "saved Bar $cat");
my @arch_tmpl;
my $tmpl_list = require 'MT/';
for my $val (@$tmpl_list) {
my $obj = MT::Template->new;
foreach (keys %$val) {
$val->{$_} = $val->{$_}->() if ref($val->{$_}) eq 'CODE';
delete $val->{$_} unless $obj->has_column($_);
$test = $obj->save or die $obj->errstr;
ok($test, "saved $obj");
if ($val->{type} eq 'archive' || $val->{type} eq 'individual' ||
$val->{type} eq 'category') {
push @arch_tmpl, $obj;
for my $tmpl (@arch_tmpl) {
if ($tmpl->type eq 'archive') {
@at = qw( Daily Weekly Monthly );
} elsif ($tmpl->type eq 'category') {
@at = qw( Category );
} elsif ($tmpl->type eq 'individual') {
@at = qw( Individual );
for my $at (@at) {
my $map = MT::TemplateMap->new;
$test = $map->save or die $map->errstr;
ok($test, "saved $map");