root/branches/release-35/t/20-setup.t @ 1927

Revision 1927, 4.2 kB (checked in by mpaschal, 20 months ago)

Land the new implementation of metadata based on narrow tables
BugzID: 68749

  • 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
42CFG
43    close $fh;
44    $mt = MT->new( Config => $T_CFG ) or die MT->errstr;
45}
46
47use MT::Test qw(:db);
48
49my $BLOG_NAME = 'Fear of a Black Planet';
50my $BLOG_DESC = 'Wherein Chuck D expounds on the plight of the black man in ' .
51                'a white man\'s world.';
52my $BLOG_URL = 'http://www.black-planet.org/';
53my $BLOG_PATH = '/opt/www/content/blog';
54
55my $blog = MT::Blog->new;
56isa_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);
79my $test = $blog->save or die $blog->errstr;
80ok($test, "saved $blog");
81
82my $author = MT::Author->new;
83isa_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;
88ok($test, "saved $author");
89
90my $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;
95ok($test, "saved $perms");
96
97my($entry);
98$entry = MT::Entry->new;
99isa_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;
110ok($test, "saved $entry");
111
112my $cat = MT::Category->new;
113isa_ok($cat, 'MT::Category');
114$cat->blog_id($blog->id);
115$cat->label('Foo');
116$test = $cat->save or die $cat->errstr;
117ok($test, "saved Foo $cat");
118
119$cat = MT::Category->new;
120isa_ok($cat, 'MT::Category');
121$cat->blog_id($blog->id);
122$cat->label('Bar');
123$test = $cat->save or die $cat->errstr;
124ok($test, "saved Bar $cat");
125
126my @arch_tmpl;
127my $tmpl_list = require 'MT/default-templates.pl';
128for 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
144for 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}
Note: See TracBrowser for help on using the browser.