root/trunk/t/20-setup.t

Revision 4196, 4.3 kB (checked in by takayama, 3 months ago)

* Set svn keywords

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