root/branches/release-31/t/20-setup.t @ 1458

Revision 1458, 4.2 kB (checked in by mpaschal, 21 months ago)

This test has more tests when there are more default templates, so don't plan

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