root/trunk/t/23-entry.t

Revision 5086, 4.3 kB (checked in by takayama, 9 days ago)

* Fixed for work.

  • Property svn:mime-type set to text/plain
Line 
1#!/usr/bin/perl
2# $Id: 23-entry.t 2670 2008-07-01 09:26:52Z takayama $
3use strict;
4use warnings;
5
6use lib 't/lib';
7use lib 'lib';
8use lib 'extlib';
9
10use Test::More tests => 41;
11
12use MT;
13use MT::Blog;
14use MT::Category;
15use MT::Comment;
16use MT::Entry;
17use MT::Placement;
18
19use vars qw( $DB_DIR $T_CFG );
20
21use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib';
22use MT::Test qw(:db :data);
23
24my $mt = MT->instance( Config => $T_CFG ) or die MT->errstr;
25isa_ok($mt, 'MT');
26
27my $blog = MT::Blog->load(1);
28isa_ok($blog, 'MT::Blog');
29
30my $entry = MT::Entry->load(1);
31isa_ok($entry, 'MT::Entry');
32is($entry->blog_id, $blog->id, 'blog id');
33is($entry->status, MT::Entry::RELEASE(), 'status');
34is($entry->status, 2, 'status 2');
35is($entry->title, 'A Rainy Day', 'title');
36is($entry->allow_comments, 1, 'allow_comments 1');
37is($entry->excerpt, 'A story of a stroll.', 'excerpt');
38is($entry->text, 'On a drizzly day last weekend,', 'text');
39is($entry->text_more, 'I took my grandpa for a walk.', 'text_more');
40
41is(MT::Entry::status_text(1), 'Draft', 'Draft');
42is(MT::Entry::status_text($entry->status), 'Publish', 'Publish');
43is(MT::Entry::status_int('Draft'), 1, 'Draft 1');
44is(MT::Entry::status_int('Publish'), 2, 'Publish 2');
45is(MT::Entry::status_int('Future'), 4, 'Future 4');
46
47my $author = $entry->author;
48isa_ok($author, 'MT::Author');
49is($author->name, 'Chuck D', 'name');
50
51## Test category, categories, and is_in_category
52my $cat = new MT::Category;
53$cat->blog_id($entry->blog_id);
54$cat->label('foo');
55$cat->description('bar');
56$cat->author_id($author->id);
57$cat->parent(0);
58$cat->save or die "Couldn't save category record 1: " . $cat->errstr;
59
60my $cat2 = new MT::Category;
61$cat2->blog_id($entry->blog_id);
62$cat2->label('foo2');
63$cat2->description('bar2');
64$cat2->author_id($author->id);
65$cat2->parent(0);
66$cat2->save or die "Couldn't save category record 1: " . $cat2->errstr;
67
68my $place = MT::Placement->new;
69$place->entry_id($entry->id);
70$place->blog_id($entry->blog_id);
71$place->category_id($cat->id);
72$place->is_primary(1);
73$place->save or die "Couldn't save placement record: " . $place->errstr;
74
75my $place2 = MT::Placement->new;
76$place2->entry_id($entry->id);
77$place2->blog_id($entry->blog_id);
78$place2->category_id($cat2->id);
79$place2->is_primary(0);
80$place2->save or die "Couldn't save placement record: " . $place2->errstr;
81
82$entry->clear_cache;
83my $category = $entry->category;
84ok ($category, "Primary category " . $category->label . " exists");
85
86my @categories = $entry->categories;
87ok(@categories, "Multiple cateogires exist ");
88
89## Test permalink, archive_url, archive_file
90is ($entry->permalink, 'http://narnia.na/nana/archives/1978/01/a-rainy-day.html', 'Permalink');
91is ($entry->archive_url, 'http://narnia.na/nana/archives/1978/01/a-rainy-day.html', 'Archive URL');
92is ($entry->archive_file, '1978/01/a-rainy-day.html', 'Archive file');
93
94## Test comments, comment_count
95ok ($entry->comment_count, "Entry comment_count exists");
96my @comments = @{$entry->comments};
97ok (@comments, "Multiple comments exist");
98is ($comments[0]->text, 'Postmodern false consciousness has always been firmly rooted in post-Freudian Lacanian neo-Marxist bojangles. Needless to say, this quickly and asymptotically approches a purpletacular jouissance of etic jumpinmypants.', 'Comment 1');
99is ($comments[1]->text, 'Comment reply for comment 11', 'Comment 2');
100is ($comments[2]->text, 'Comment reply for comment 1', 'Comment 3');
101
102## Test entry auto-generation
103$entry->excerpt('');
104is($entry->excerpt, '', 'excerpt empty');
105is($entry->get_excerpt, $entry->text . '...', 'get_excerpt');
106$blog->words_in_excerpt(3);
107$entry->cache_property('blog', undef, $blog);
108is($entry->get_excerpt, 'On a drizzly...', 'get_excerpt');
109$entry->convert_breaks('textile_2');
110$entry->text("Foo _bar_ baz");
111is($entry->get_excerpt, 'Foo bar baz...', 'get_excerpt');
112
113## Test TrackBack object generation
114$entry->allow_pings(1);
115ok($entry->save, 'save');
116my $tb = MT::Trackback->load({ entry_id => $entry->id });
117isa_ok($tb, 'MT::Trackback');
118is($tb->entry_id, $entry->id, 'entry_id');
119is($tb->description, $entry->get_excerpt, 'description');
120is($tb->title, $entry->title, 'title');
121is($tb->url, $entry->permalink, 'url');
122is($tb->is_disabled, 0, 'is_disabled');
123$entry->allow_pings(0);
124ok($entry->save, 'save');
125$tb = MT::Trackback->load({ entry_id => $entry->id });
126is($tb->is_disabled, 1, 'is_disabled');
Note: See TracBrowser for help on using the browser.