| 1 | #!/usr/bin/perl |
|---|
| 2 | # $Id: 23-entry.t 2670 2008-07-01 09:26:52Z takayama $ |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | |
|---|
| 6 | use lib 't/lib'; |
|---|
| 7 | use lib 'lib'; |
|---|
| 8 | use lib 'extlib'; |
|---|
| 9 | |
|---|
| 10 | use Test::More tests => 41; |
|---|
| 11 | |
|---|
| 12 | use MT; |
|---|
| 13 | use MT::Blog; |
|---|
| 14 | use MT::Category; |
|---|
| 15 | use MT::Comment; |
|---|
| 16 | use MT::Entry; |
|---|
| 17 | use MT::Placement; |
|---|
| 18 | |
|---|
| 19 | use vars qw( $DB_DIR $T_CFG ); |
|---|
| 20 | |
|---|
| 21 | use lib 't/lib', 'extlib', 'lib', '../lib', '../extlib'; |
|---|
| 22 | use MT::Test qw(:db :data); |
|---|
| 23 | |
|---|
| 24 | my $mt = MT->instance( Config => $T_CFG ) or die MT->errstr; |
|---|
| 25 | isa_ok($mt, 'MT'); |
|---|
| 26 | |
|---|
| 27 | my $blog = MT::Blog->load(1); |
|---|
| 28 | isa_ok($blog, 'MT::Blog'); |
|---|
| 29 | |
|---|
| 30 | my $entry = MT::Entry->load(1); |
|---|
| 31 | isa_ok($entry, 'MT::Entry'); |
|---|
| 32 | is($entry->blog_id, $blog->id, 'blog id'); |
|---|
| 33 | is($entry->status, MT::Entry::RELEASE(), 'status'); |
|---|
| 34 | is($entry->status, 2, 'status 2'); |
|---|
| 35 | is($entry->title, 'A Rainy Day', 'title'); |
|---|
| 36 | is($entry->allow_comments, 1, 'allow_comments 1'); |
|---|
| 37 | is($entry->excerpt, 'A story of a stroll.', 'excerpt'); |
|---|
| 38 | is($entry->text, 'On a drizzly day last weekend,', 'text'); |
|---|
| 39 | is($entry->text_more, 'I took my grandpa for a walk.', 'text_more'); |
|---|
| 40 | |
|---|
| 41 | is(MT::Entry::status_text(1), 'Draft', 'Draft'); |
|---|
| 42 | is(MT::Entry::status_text($entry->status), 'Publish', 'Publish'); |
|---|
| 43 | is(MT::Entry::status_int('Draft'), 1, 'Draft 1'); |
|---|
| 44 | is(MT::Entry::status_int('Publish'), 2, 'Publish 2'); |
|---|
| 45 | is(MT::Entry::status_int('Future'), 4, 'Future 4'); |
|---|
| 46 | |
|---|
| 47 | my $author = $entry->author; |
|---|
| 48 | isa_ok($author, 'MT::Author'); |
|---|
| 49 | is($author->name, 'Chuck D', 'name'); |
|---|
| 50 | |
|---|
| 51 | ## Test category, categories, and is_in_category |
|---|
| 52 | my $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 | |
|---|
| 60 | my $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 | |
|---|
| 68 | my $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 | |
|---|
| 75 | my $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; |
|---|
| 83 | my $category = $entry->category; |
|---|
| 84 | ok ($category, "Primary category " . $category->label . " exists"); |
|---|
| 85 | |
|---|
| 86 | my @categories = $entry->categories; |
|---|
| 87 | ok(@categories, "Multiple cateogires exist "); |
|---|
| 88 | |
|---|
| 89 | ## Test permalink, archive_url, archive_file |
|---|
| 90 | is ($entry->permalink, 'http://narnia.na/nana/archives/1978/01/a-rainy-day.html', 'Permalink'); |
|---|
| 91 | is ($entry->archive_url, 'http://narnia.na/nana/archives/1978/01/a-rainy-day.html', 'Archive URL'); |
|---|
| 92 | is ($entry->archive_file, '1978/01/a-rainy-day.html', 'Archive file'); |
|---|
| 93 | |
|---|
| 94 | ## Test comments, comment_count |
|---|
| 95 | ok ($entry->comment_count, "Entry comment_count exists"); |
|---|
| 96 | my @comments = @{$entry->comments}; |
|---|
| 97 | ok (@comments, "Multiple comments exist"); |
|---|
| 98 | is ($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'); |
|---|
| 99 | is ($comments[1]->text, 'Comment reply for comment 11', 'Comment 2'); |
|---|
| 100 | is ($comments[2]->text, 'Comment reply for comment 1', 'Comment 3'); |
|---|
| 101 | |
|---|
| 102 | ## Test entry auto-generation |
|---|
| 103 | $entry->excerpt(''); |
|---|
| 104 | is($entry->excerpt, '', 'excerpt empty'); |
|---|
| 105 | is($entry->get_excerpt, $entry->text . '...', 'get_excerpt'); |
|---|
| 106 | $blog->words_in_excerpt(3); |
|---|
| 107 | $entry->cache_property('blog', undef, $blog); |
|---|
| 108 | is($entry->get_excerpt, 'On a drizzly...', 'get_excerpt'); |
|---|
| 109 | $entry->convert_breaks('textile_2'); |
|---|
| 110 | $entry->text("Foo _bar_ baz"); |
|---|
| 111 | is($entry->get_excerpt, 'Foo bar baz...', 'get_excerpt'); |
|---|
| 112 | |
|---|
| 113 | ## Test TrackBack object generation |
|---|
| 114 | $entry->allow_pings(1); |
|---|
| 115 | ok($entry->save, 'save'); |
|---|
| 116 | my $tb = MT::Trackback->load({ entry_id => $entry->id }); |
|---|
| 117 | isa_ok($tb, 'MT::Trackback'); |
|---|
| 118 | is($tb->entry_id, $entry->id, 'entry_id'); |
|---|
| 119 | is($tb->description, $entry->get_excerpt, 'description'); |
|---|
| 120 | is($tb->title, $entry->title, 'title'); |
|---|
| 121 | is($tb->url, $entry->permalink, 'url'); |
|---|
| 122 | is($tb->is_disabled, 0, 'is_disabled'); |
|---|
| 123 | $entry->allow_pings(0); |
|---|
| 124 | ok($entry->save, 'save'); |
|---|
| 125 | $tb = MT::Trackback->load({ entry_id => $entry->id }); |
|---|
| 126 | is($tb->is_disabled, 1, 'is_disabled'); |
|---|