| 1 | # $Id$ |
|---|
| 2 | |
|---|
| 3 | BEGIN { unshift @INC, 't/' } |
|---|
| 4 | |
|---|
| 5 | use lib 't/lib'; |
|---|
| 6 | use lib 'lib'; |
|---|
| 7 | use lib 'extlib'; |
|---|
| 8 | |
|---|
| 9 | use Test; |
|---|
| 10 | use XMLRPC::Lite; |
|---|
| 11 | use MT; |
|---|
| 12 | use MT::Blog; |
|---|
| 13 | use MT::Author; |
|---|
| 14 | use MT::Entry; |
|---|
| 15 | use MT::Util qw( format_ts ); |
|---|
| 16 | use strict; |
|---|
| 17 | |
|---|
| 18 | BEGIN { plan tests => 85 } |
|---|
| 19 | |
|---|
| 20 | for (my $i = 0; $i < 85; $i++) |
|---|
| 21 | { |
|---|
| 22 | skip(1); |
|---|
| 23 | } |
|---|
| 24 | exit(0); |
|---|
| 25 | |
|---|
| 26 | use vars qw( $DB_DIR $T_CFG $BASE ); |
|---|
| 27 | require 'test-common.pl'; |
|---|
| 28 | my $mt = MT->new( Config => $T_CFG ) or die MT->errstr; |
|---|
| 29 | |
|---|
| 30 | my $script = "$BASE/t/mt-test-rpc.cgi"; |
|---|
| 31 | |
|---|
| 32 | open my $fh, ">$script" or die $!; |
|---|
| 33 | print $fh <<SCRIPT; |
|---|
| 34 | #!/usr/bin/perl -w |
|---|
| 35 | use strict; |
|---|
| 36 | |
|---|
| 37 | use XMLRPC::Transport::HTTP; |
|---|
| 38 | use File::Spec; |
|---|
| 39 | |
|---|
| 40 | use lib File::Spec->catdir('$BASE', 'lib'); |
|---|
| 41 | |
|---|
| 42 | use MT::XMLRPCServer; |
|---|
| 43 | |
|---|
| 44 | \$MT::XMLRPCServer::MT_DIR = File::Spec->catfile('$BASE', 't'); |
|---|
| 45 | |
|---|
| 46 | local \$SIG{__WARN__} = sub { }; |
|---|
| 47 | my \$server = XMLRPC::Transport::HTTP::CGI->new; |
|---|
| 48 | \$server->dispatch_to('blogger', 'metaWeblog', 'mt'); |
|---|
| 49 | \$server->handle; |
|---|
| 50 | SCRIPT |
|---|
| 51 | close $fh; |
|---|
| 52 | chmod 0755, $script; |
|---|
| 53 | |
|---|
| 54 | # TODO: get this script 'running' |
|---|
| 55 | |
|---|
| 56 | my $rpc = XMLRPC::Lite->new; |
|---|
| 57 | $rpc->proxy("http://localhost/mt-test-rpc.cgi"); |
|---|
| 58 | |
|---|
| 59 | my $som; |
|---|
| 60 | |
|---|
| 61 | my $blog = MT::Blog->load(1); |
|---|
| 62 | |
|---|
| 63 | $som = $rpc->call('blogger.getUsersBlogs', '', 'Chuck D', 'bass'); |
|---|
| 64 | ok($som && $som->result); |
|---|
| 65 | ok(scalar @{ $som->result }, 1); |
|---|
| 66 | ok($som->result->[0]{url}, $blog->site_url); |
|---|
| 67 | ok($som->result->[0]{blogid}, $blog->id); |
|---|
| 68 | ok($som->result->[0]{blogName}, $blog->name); |
|---|
| 69 | |
|---|
| 70 | my $author = MT::Author->load({ name => 'Chuck D' }); |
|---|
| 71 | |
|---|
| 72 | $som = $rpc->call('blogger.getUserInfo', '', 'Chuck D', 'bass'); |
|---|
| 73 | ok($som && $som->result); |
|---|
| 74 | ok($som->result->{userid}, $author->id); |
|---|
| 75 | ok($som->result->{firstname}, (split /\s+/, $author->name)[0]); |
|---|
| 76 | ok($som->result->{lastname}, (split /\s+/, $author->name)[1]); |
|---|
| 77 | ok($som->result->{nickname}, $author->nickname || ''); |
|---|
| 78 | ok($som->result->{email}, $author->email || ''); |
|---|
| 79 | ok($som->result->{url}, $author->url || ''); |
|---|
| 80 | |
|---|
| 81 | $som = $rpc->call('blogger.getUserInfo', '', 'Chuck D', 'wrong'); |
|---|
| 82 | ok(!$som->result); |
|---|
| 83 | ok($som->fault); |
|---|
| 84 | ok($som->faultstring, 'Invalid login'); |
|---|
| 85 | ok($som->faultcode, 1); |
|---|
| 86 | |
|---|
| 87 | $som = $rpc->call('blogger.getUsersBlogs', '', 'Chuck D', 'wrong'); |
|---|
| 88 | ok(!$som->result); |
|---|
| 89 | ok($som->fault); |
|---|
| 90 | ok($som->faultstring, 'Invalid login'); |
|---|
| 91 | ok($som->faultcode, 1); |
|---|
| 92 | |
|---|
| 93 | my $entry1 = MT::Entry->load(1); |
|---|
| 94 | ok($entry1); |
|---|
| 95 | |
|---|
| 96 | $som = $rpc->call('blogger.getRecentPosts', '', $blog->id, 'Chuck D', 'bass', 2); |
|---|
| 97 | ok($som && $som->result); |
|---|
| 98 | ok(scalar @{ $som->result }, 1); |
|---|
| 99 | ok($som->result->[0]{userid}, $author->id); |
|---|
| 100 | ok($som->result->[0]{postid}, $entry1->id); |
|---|
| 101 | ok($som->result->[0]{dateCreated}, format_ts("%Y%m%dT%H:%M:%S", $entry1->created_on)); |
|---|
| 102 | ok($som->result->[0]{content}, $entry1->text); |
|---|
| 103 | |
|---|
| 104 | $som = $rpc->call('metaWeblog.getRecentPosts', $blog->id, 'Chuck D', 'bass', 2); |
|---|
| 105 | ok($som && $som->result); |
|---|
| 106 | ok(scalar @{ $som->result }, 1); |
|---|
| 107 | ok($som->result->[0]{userid}, $author->id); |
|---|
| 108 | ok($som->result->[0]{postid}, $entry1->id); |
|---|
| 109 | ok($som->result->[0]{dateCreated}, format_ts("%Y%m%dT%H:%M:%S", $entry1->created_on)); |
|---|
| 110 | ok($som->result->[0]{description}, $entry1->text); |
|---|
| 111 | ok($som->result->[0]{title}, $entry1->title); |
|---|
| 112 | ok($som->result->[0]{link}, $entry1->permalink); |
|---|
| 113 | ok($som->result->[0]{permaLink}, $entry1->permalink); |
|---|
| 114 | ok($som->result->[0]{mt_excerpt}, $entry1->excerpt); |
|---|
| 115 | ok($som->result->[0]{mt_text_more}, $entry1->text_more); |
|---|
| 116 | ok($som->result->[0]{mt_allow_comments}, $entry1->allow_comments); |
|---|
| 117 | ok($som->result->[0]{mt_allow_pings}, $entry1->allow_pings || 0); |
|---|
| 118 | ok($som->result->[0]{mt_convert_breaks}, $entry1->convert_breaks || ''); |
|---|
| 119 | ok($som->result->[0]{mt_keywords}, $entry1->keywords || ''); |
|---|
| 120 | |
|---|
| 121 | $som = $rpc->call('blogger.editPost', '', $entry1->id, 'Chuck D', 'bass', 'Foo Bar', 0); |
|---|
| 122 | ok($som->result, 1); |
|---|
| 123 | $entry1 = MT::Entry->load($entry1->id); |
|---|
| 124 | ok($entry1->text, 'Foo Bar'); |
|---|
| 125 | |
|---|
| 126 | $som = $rpc->call('metaWeblog.editPost', $entry1->id, 'Chuck D', 'bass', { |
|---|
| 127 | title => 'Title', |
|---|
| 128 | description => 'Description', |
|---|
| 129 | mt_convert_breaks => 'wiki', |
|---|
| 130 | mt_allow_comments => 1, |
|---|
| 131 | mt_allow_pings => 1, |
|---|
| 132 | mt_excerpt => 'Excerpt', |
|---|
| 133 | mt_text_more => 'Extended Entry', |
|---|
| 134 | mt_keywords => 'Keywords', |
|---|
| 135 | mt_tb_ping_urls => [ 'http://127.0.0.1/' ], |
|---|
| 136 | dateCreated => '19770922T15:30:00', |
|---|
| 137 | }, 0); |
|---|
| 138 | ok($som->result, 1); |
|---|
| 139 | $entry1 = MT::Entry->load($entry1->id); |
|---|
| 140 | ok($entry1->title, 'Title'); |
|---|
| 141 | ok($entry1->text, 'Description'); |
|---|
| 142 | ok($entry1->convert_breaks, 'wiki'); |
|---|
| 143 | ok($entry1->allow_comments, 1); |
|---|
| 144 | ok($entry1->allow_pings, 1); |
|---|
| 145 | ok($entry1->excerpt, 'Excerpt'); |
|---|
| 146 | ok($entry1->text_more, 'Extended Entry'); |
|---|
| 147 | ok($entry1->keywords, 'Keywords'); |
|---|
| 148 | ok($entry1->to_ping_urls, 'http://127.0.0.1/'); |
|---|
| 149 | ok($entry1->to_ping_url_list->[0], 'http://127.0.0.1/'); |
|---|
| 150 | ok($entry1->created_on, '19770922153000'); |
|---|
| 151 | |
|---|
| 152 | $som = $rpc->call('metaWeblog.editPost', $entry1->id, 'Chuck D', 'bass', { |
|---|
| 153 | mt_allow_comments => 2, |
|---|
| 154 | }, 0); |
|---|
| 155 | ok($som->result, 1); |
|---|
| 156 | |
|---|
| 157 | $som = $rpc->call('metaWeblog.editPost', $entry1->id, 'Chuck D', 'bass', { |
|---|
| 158 | mt_convert_breaks => '', |
|---|
| 159 | mt_text_more => '', |
|---|
| 160 | mt_excerpt => '', |
|---|
| 161 | }, 0); |
|---|
| 162 | ok($som->result, 1); |
|---|
| 163 | $entry1 = MT::Entry->load($entry1->id); |
|---|
| 164 | ok($entry1->convert_breaks, ''); |
|---|
| 165 | ok($entry1->text_more, ''); |
|---|
| 166 | ok($entry1->excerpt, ''); |
|---|
| 167 | |
|---|
| 168 | my $cat1 = MT::Category->load(1); |
|---|
| 169 | my $cat2 = MT::Category->load(2); |
|---|
| 170 | |
|---|
| 171 | $som = $rpc->call('mt.getCategoryList', $blog->id, 'Chuck D', 'bass'); |
|---|
| 172 | ok($som && $som->result); |
|---|
| 173 | ok(scalar @{ $som->result }, 2); |
|---|
| 174 | ok($som->result->[0]{categoryId}, $cat1->id); |
|---|
| 175 | ok($som->result->[0]{categoryName}, $cat1->label); |
|---|
| 176 | ok($som->result->[1]{categoryId}, $cat2->id); |
|---|
| 177 | ok($som->result->[1]{categoryName}, $cat2->label); |
|---|
| 178 | |
|---|
| 179 | $som = $rpc->call('mt.getPostCategories', $entry1->id, 'Chuck D', 'bass'); |
|---|
| 180 | ok($som && $som->result); |
|---|
| 181 | ok(!scalar @{ $som->result }); |
|---|
| 182 | |
|---|
| 183 | $mt->{cfg}->NoPlacementCache(1); |
|---|
| 184 | |
|---|
| 185 | $entry1->{__categories} = undef; |
|---|
| 186 | $entry1->{__category} = undef; |
|---|
| 187 | $som = $rpc->call('mt.setPostCategories', $entry1->id, 'Chuck D', 'bass', [ |
|---|
| 188 | { categoryId => $cat1->id }, |
|---|
| 189 | ]); |
|---|
| 190 | ok($som->result, 1); |
|---|
| 191 | my $cats = $entry1->categories; |
|---|
| 192 | ok(scalar @$cats, 1); |
|---|
| 193 | ok($cats->[0]->label, $cat1->label); |
|---|
| 194 | ok($entry1->category->label, $cat1->label); |
|---|
| 195 | |
|---|
| 196 | $entry1->{__categories} = undef; |
|---|
| 197 | $entry1->{__category} = undef; |
|---|
| 198 | $som = $rpc->call('mt.setPostCategories', $entry1->id, 'Chuck D', 'bass', [ |
|---|
| 199 | { categoryId => $cat1->id }, |
|---|
| 200 | { categoryId => $cat2->id }, |
|---|
| 201 | ]); |
|---|
| 202 | ok($som->result, 1); |
|---|
| 203 | $cats = $entry1->categories; |
|---|
| 204 | ok(scalar @$cats, 2); |
|---|
| 205 | ok($entry1->category->label, $cat1->label); |
|---|
| 206 | |
|---|
| 207 | $entry1->{__categories} = undef; |
|---|
| 208 | $entry1->{__category} = undef; |
|---|
| 209 | $som = $rpc->call('mt.setPostCategories', $entry1->id, 'Chuck D', 'bass', [ |
|---|
| 210 | { categoryId => $cat1->id, isPrimary => 1 }, |
|---|
| 211 | { categoryId => $cat2->id, isPrimary => 0 }, |
|---|
| 212 | ]); |
|---|
| 213 | ok($som->result, 1); |
|---|
| 214 | $cats = $entry1->categories; |
|---|
| 215 | ok(scalar @$cats, 2); |
|---|
| 216 | ok($entry1->category->label, $cat1->label); |
|---|
| 217 | |
|---|
| 218 | $entry1->{__categories} = undef; |
|---|
| 219 | $entry1->{__category} = undef; |
|---|
| 220 | $som = $rpc->call('mt.setPostCategories', $entry1->id, 'Chuck D', 'bass', [ |
|---|
| 221 | { categoryId => $cat1->id, isPrimary => 0 }, |
|---|
| 222 | { categoryId => $cat2->id, isPrimary => 1 }, |
|---|
| 223 | ]); |
|---|
| 224 | ok($som->result, 1); |
|---|
| 225 | $cats = $entry1->categories; |
|---|
| 226 | ok(scalar @$cats, 2); |
|---|
| 227 | ok($entry1->category->label, $cat2->label); |
|---|
| 228 | |
|---|
| 229 | $entry1->{__categories} = undef; |
|---|
| 230 | $entry1->{__category} = undef; |
|---|
| 231 | $som = $rpc->call('mt.setPostCategories', $entry1->id, 'Chuck D', 'bass', [ ]); |
|---|
| 232 | ok($som->result, 1); |
|---|
| 233 | $cats = $entry1->categories; |
|---|
| 234 | ok(!scalar @$cats); |
|---|
| 235 | ok(!$entry1->category); |
|---|