root/branches/release-38/t/20-setup.t @ 2247

Revision 2247, 4.3 kB (checked in by mpaschal, 19 months ago)

Add test for MT::CMS::Tags::list_tag_for
Add MT::Test helper to request that MT->instance be an App::CMS
Look for templates in the normal place during tests
Note test entry #1 vs upgrade issue

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