| 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); |
| | 26 | my $ser = XMLRPC::Serializer->new(); |
| | 27 | my $deser = XMLRPC::Deserializer->new(); |
| | 28 | |
| | 29 | require LWP::UserAgent::Local; |
| | 30 | my $ua = new LWP::UserAgent::Local({ ScriptAlias => '/' }); |
| | 31 | |
| | 32 | my @apis = ( |
| | 33 | { |
| | 34 | api =>'blogger.getUsersBlogs', |
| | 35 | params => [ '', $username, $password ], |
| | 36 | result => sub { |
| | 37 | my ( $som ) = @_; |
| | 38 | my $result = $som->result; |
| | 39 | is( $result->[0]->{url}, 'http://narnia.na/nana/', 'url is correct' ); |
| | 40 | is( $result->[0]->{blogid}, 1, 'blogid is correct' ); |
| | 41 | is( $result->[0]->{blogName}, 'none', 'blogName is correct' ); |
| | 42 | } |
| | 43 | }, |
| | 44 | { |
| | 45 | api => 'blogger.getUserInfo', |
| | 46 | params => [ '', $username, $password ], |
| | 47 | result => sub { |
| | 48 | my ( $som ) = @_; |
| | 49 | my $result = $som->result; |
| | 50 | my $author = MT::Author->load({ name => 'Chuck D' }); |
| | 51 | is( $result->{userid}, $author->id); |
| | 52 | is( $result->{firstname}, (split /\s+/, $author->name)[0]); |
| | 53 | is( $result->{lastname}, (split /\s+/, $author->name)[1]); |
| | 54 | is( $result->{nickname}, $author->nickname || ''); |
| | 55 | is( $result->{email}, $author->email || ''); |
| | 56 | is( $result->{url}, $author->url || ''); |
| | 57 | } |
| | 58 | }, |
| | 59 | { |
| | 60 | api => 'blogger.getUsersBlogs', |
| | 61 | params => [ '', 'Chuck D', 'wrong' ], |
| | 62 | result => sub { |
| | 63 | my ( $som ) = @_; |
| | 64 | ok(!$som->result); |
| | 65 | ok($som->fault); |
| | 66 | is($som->faultstring, 'Invalid login'); |
| | 67 | is($som->faultcode, 1); |
| | 68 | } |
| | 69 | }, |
| | 70 | { |
| | 71 | api => 'blogger.getUserInfo', |
| | 72 | params => [ '', 'Chuck D', 'wrong' ], |
| | 73 | result => sub { |
| | 74 | my ( $som ) = @_; |
| | 75 | ok(!$som->result); |
| | 76 | ok($som->fault); |
| | 77 | is($som->faultstring, 'Invalid login'); |
| | 78 | is($som->faultcode, 1); |
| | 79 | } |
| | 80 | }, |
| | 81 | { |
| | 82 | api => 'blogger.getRecentPosts', |
| | 83 | params => [ '', 1, $username, $password, 2 ], |
| | 84 | result => sub { |
| | 85 | my ( $som ) = @_; |
| | 86 | my $result = $som->result; |
| | 87 | is(scalar(@$result), 2); |
| | 88 | my $entry = MT::Entry->load(3); |
| | 89 | my $author = MT::Author->load({ name => 'Chuck D' }); |
| | 90 | is($result->[0]->{userid}, $author->id); |
| | 91 | is($result->[0]->{postid}, $entry->id); |
| | 92 | my $ao = sprintf "%04d%02d%02dT%02d:%02d:%02d", |
| | 93 | unpack 'A4A2A2A2A2A2', $entry->authored_on; |
| | 94 | is($result->[0]->{dateCreated}, $ao); |
| | 95 | is($result->[0]->{content}, $entry->text); |
| | 96 | $entry = MT::Entry->load(2); |
| | 97 | $author = MT::Author->load({ name => 'Bob D' }); |
| | 98 | is($result->[1]->{userid}, $author->id); |
| | 99 | is($result->[1]->{postid}, $entry->id); |
| | 100 | my $ao = sprintf "%04d%02d%02dT%02d:%02d:%02d", |
| | 101 | unpack 'A4A2A2A2A2A2', $entry->authored_on; |
| | 102 | is($result->[1]->{dateCreated}, $ao); |
| | 103 | is($result->[1]->{content}, $entry->text); |
| | 104 | }, |
| | 105 | }, |
| | 106 | { |
| | 107 | api => 'metaWeblog.getRecentPosts', |
| | 108 | params => [ 1, $username, $password, 2 ], |
| | 109 | result => sub { |
| | 110 | my ( $som ) = @_; |
| | 111 | my $result = $som->result; |
| | 112 | is(scalar(@$result), 2); |
| | 113 | my $author = MT::Author->load({ name => 'Chuck D' }); |
| | 114 | my $entry = MT::Entry->load(3); |
| | 115 | is($result->[0]->{userid}, $author->id); |
| | 116 | is($result->[0]->{postid}, $entry->id); |
| | 117 | my $ao = sprintf "%04d%02d%02dT%02d:%02d:%02d", |
| | 118 | unpack 'A4A2A2A2A2A2', $entry->authored_on; |
| | 119 | is($result->[0]->{dateCreated}, $ao); |
| | 120 | is($result->[0]->{description}, $entry->text); |
| | 121 | is($result->[0]->{title}, $entry->title); |
| | 122 | is($result->[0]->{link}, $entry->permalink); |
| | 123 | is($result->[0]->{permaLink}, $entry->permalink); |
| | 124 | is($result->[0]->{mt_excerpt}, |
| | 125 | defined $entry->excerpt ? $entry->excerpt : '' ); |
| | 126 | is($result->[0]->{mt_text_more}, $entry->text_more); |
| | 127 | is($result->[0]->{mt_allow_comments}, $entry->allow_comments); |
| | 128 | is($result->[0]->{mt_allow_pings}, 0); |
| | 129 | is($result->[0]->{mt_convert_breaks}, $entry->convert_breaks || ''); |
| | 130 | is($result->[0]->{mt_keywords}, ''); |
| | 131 | $author = MT::Author->load({ name => 'Bob D' }); |
| | 132 | $entry = MT::Entry->load(2); |
| | 133 | is($result->[1]->{userid}, $author->id); |
| | 134 | is($result->[1]->{postid}, $entry->id); |
| | 135 | $ao = sprintf "%04d%02d%02dT%02d:%02d:%02d", |
| | 136 | unpack 'A4A2A2A2A2A2', $entry->authored_on; |
| | 137 | is($result->[1]->{dateCreated}, $ao); |
| | 138 | is($result->[1]->{description}, $entry->text); |
| | 139 | is($result->[1]->{title}, $entry->title); |
| | 140 | is($result->[1]->{link}, $entry->permalink); |
| | 141 | is($result->[1]->{permaLink}, $entry->permalink); |
| | 142 | is($result->[1]->{mt_excerpt}, |
| | 143 | defined $entry->excerpt ? $entry->excerpt : '' ); |
| | 144 | is($result->[1]->{mt_text_more}, $entry->text_more); |
| | 145 | is($result->[1]->{mt_allow_comments}, $entry->allow_comments); |
| | 146 | is($result->[1]->{mt_allow_pings}, $entry->allow_pings || ''); |
| | 147 | is($result->[1]->{mt_convert_breaks}, $entry->convert_breaks || ''); |
| | 148 | is($result->[1]->{mt_keywords}, $entry->keywords || ''); |
| | 149 | }, |
| | 150 | }, |
| | 151 | { |
| | 152 | api => 'blogger.editPost', |
| | 153 | params => [ '', 3, $username, $password, 'Foo Bar', 0 ], |
| | 154 | result => sub { |
| | 155 | my ( $som ) = @_; |
| | 156 | my $result = $som->result; |
| | 157 | MT::Entry->driver->Disabled(1); |
| | 158 | my $entry = MT::Entry->load(3); |
| | 159 | MT::Entry->driver->Disabled(0); |
| | 160 | is($entry->text, 'Foo Bar'); |
| | 161 | }, |
| | 162 | }, |
| | 163 | { |
| | 164 | api => 'metaWeblog.editPost', |
| | 165 | params => [ 3, $username, $password, { |
| | 166 | title => 'Title', |
| | 167 | description => 'Description', |
| | 168 | mt_convert_breaks => 'wiki', |
| | 169 | mt_allow_comments => 1, |
| | 170 | mt_allow_pings => 1, |
| | 171 | mt_excerpt => 'Excerpt', |
| | 172 | mt_text_more => 'Extended Entry', |
| | 173 | mt_keywords => 'Keywords', |
| | 174 | mt_tb_ping_urls => [ 'http://127.0.0.1/' ], |
| | 175 | dateCreated => '19770922T15:30:00', |
| | 176 | }, 0 ], |
| | 177 | result => sub { |
| | 178 | my ( $som ) = @_; |
| | 179 | my $result = $som->result; |
| | 180 | MT::Entry->driver->Disabled(1); |
| | 181 | my $entry = MT::Entry->load(3); |
| | 182 | MT::Entry->driver->Disabled(0); |
| | 183 | is($entry->title, 'Title'); |
| | 184 | is($entry->text, 'Description'); |
| | 185 | is($entry->convert_breaks, 'wiki'); |
| | 186 | is($entry->allow_comments, 1); |
| | 187 | is($entry->allow_pings, 1); |
| | 188 | is($entry->excerpt, 'Excerpt'); |
| | 189 | is($entry->text_more, 'Extended Entry'); |
| | 190 | is($entry->keywords, 'Keywords'); |
| | 191 | is($entry->to_ping_urls, 'http://127.0.0.1/'); |
| | 192 | is($entry->to_ping_url_list->[0], 'http://127.0.0.1/'); |
| | 193 | is($entry->authored_on, '19770922153000'); |
| | 194 | }, |
| | 195 | }, |
| | 196 | { |
| | 197 | api => 'metaWeblog.editPost', |
| | 198 | params => [ 3, $username, $password, { |
| | 199 | mt_convert_breaks => '', |
| | 200 | mt_allow_comments => 2, |
| | 201 | mt_excerpt => '', |
| | 202 | mt_text_more => '', |
| | 203 | }, 0 ], |
| | 204 | result => sub { |
| | 205 | my ( $som ) = @_; |
| | 206 | my $result = $som->result; |
| | 207 | }, |
| | 208 | }, |
| | 209 | { |
| | 210 | api => 'mt.getCategoryList', |
| | 211 | params => [ 1, $username, $password ], |
| | 212 | result => sub { |
| | 213 | my ( $som ) = @_; |
| | 214 | my $result = $som->result; |
| | 215 | my $cat1 = MT::Category->load(1); |
| | 216 | my $cat2 = MT::Category->load(2); |
| | 217 | is($result->[0]->{categoryId}, $cat1->id); |
| | 218 | is($result->[0]->{categoryName}, $cat1->label); |
| | 219 | is($result->[1]->{categoryId}, $cat2->id); |
| | 220 | is($result->[1]->{categoryName}, $cat2->label); |
| | 221 | }, |
| | 222 | }, |
| | 223 | { |
| | 224 | api => 'mt.getPostCategories', |
| | 225 | params => [ 3, $username, $password ], |
| | 226 | result => sub { |
| | 227 | my ( $som ) = @_; |
| | 228 | my $result = $som->result; |
| | 229 | is(scalar @{ $som->result }, 0); |
| | 230 | }, |
| | 231 | }, |
| | 232 | { |
| | 233 | api => 'mt.setPostCategories', |
| | 234 | params => [ 3, $username, $password, [ |
| | 235 | { categoryId => 1 } ] |
| | 236 | ], |
| | 237 | result => sub { |
| | 238 | my ( $som ) = @_; |
| | 239 | my $result = $som->result; |
| | 240 | MT::Entry->driver->Disabled(1); |
| | 241 | my $entry = MT::Entry->load(3); |
| | 242 | MT::Entry->driver->Disabled(0); |
| | 243 | my $cat1 = MT::Category->load(1); |
| | 244 | my $cats = $entry->categories; |
| | 245 | is(scalar @$cats, 1); |
| | 246 | is($cats->[0]->label, $cat1->label); |
| | 247 | is($entry->category->label, $cat1->label); |
| | 248 | }, |
| | 249 | }, |
| | 250 | { |
| | 251 | api => 'mt.setPostCategories', |
| | 252 | params => [ 3, $username, $password, [ |
| | 253 | { categoryId => 1, isPrimary => 1 }, |
| | 254 | { categoryId => 2, isPrimary => 0 }, |
| | 255 | ] ], |
| | 256 | pre => sub { |
| | 257 | my $r = MT->request; |
| | 258 | my $oc = $r->cache('object_cache', {}); |
| | 259 | }, |
| | 260 | result => sub { |
| | 261 | my ( $som ) = @_; |
| | 262 | my $result = $som->result; |
| | 263 | MT::Entry->driver->Disabled(1); |
| | 264 | my $entry = MT::Entry->load(3); |
| | 265 | MT::Entry->driver->Disabled(0); |
| | 266 | my $cat1 = MT::Category->load(1); |
| | 267 | my $cats = $entry->categories; |
| | 268 | is(scalar @$cats, 2); |
| | 269 | is($entry->category->label, $cat1->label); |
| | 270 | }, |
| | 271 | }, |
| | 272 | { |
| | 273 | api => 'mt.setPostCategories', |
| | 274 | params => [ 3, $username, $password, [ |
| | 275 | { categoryId => 1, isPrimary => 0 }, |
| | 276 | { categoryId => 2, isPrimary => 1 }, |
| | 277 | ] ], |
| | 278 | pre => sub { |
| | 279 | my $r = MT->request; |
| | 280 | my $oc = $r->cache('object_cache', {}); |
| | 281 | }, |
| | 282 | result => sub { |
| | 283 | my ( $som ) = @_; |
| | 284 | my $result = $som->result; |
| | 285 | MT::Entry->driver->Disabled(1); |
| | 286 | my $entry = MT::Entry->load(3); |
| | 287 | MT::Entry->driver->Disabled(0); |
| | 288 | my $cat2 = MT::Category->load(2); |
| | 289 | my $cats = $entry->categories; |
| | 290 | is(scalar @$cats, 2); |
| | 291 | is($entry->category->label, $cat2->label); |
| | 292 | }, |
| | 293 | }, |
| | 294 | { |
| | 295 | api => 'mt.setPostCategories', |
| | 296 | params => [ 3, $username, $password, [ |
| | 297 | ] ], |
| | 298 | pre => sub { |
| | 299 | my $r = MT->request; |
| | 300 | my $oc = $r->cache('object_cache', {}); |
| | 301 | }, |
| | 302 | result => sub { |
| | 303 | my ( $som ) = @_; |
| | 304 | my $result = $som->result; |
| | 305 | MT::Entry->driver->Disabled(1); |
| | 306 | my $entry = MT::Entry->load(3); |
| | 307 | MT::Entry->driver->Disabled(0); |
| | 308 | my $cats = $entry->categories; |
| | 309 | is(scalar @$cats, 0); |
| | 310 | ok(!$entry->category); |
| | 311 | }, |
| | 312 | }, |
| | 313 | #TODO Add more XML-RPC API |
| | 314 | ); |
| | 315 | |
| | 316 | my $uri = new URI(); |
| | 317 | $uri->path($base_uri); |
| | 318 | my $req = new HTTP::Request(POST => $uri); |
| | 319 | |
| | 320 | foreach my $api ( @apis ) { |
| | 321 | |
| | 322 | my $data = {}; |
| | 323 | $data = $api->{pre}->() if exists $api->{pre}; |
| | 324 | |
| | 325 | $req->content($ser->method($api->{api}, @{ $api->{params} })); |
| | 326 | |
| | 327 | my $resp = $ua->request($req); |
| | 328 | # print STDERR $resp->content; |
| | 329 | my $som = $deser->deserialize($resp->content()); |
| | 330 | $api->{result}->($som, $data); |
| 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); |
| | 332 | |
| | 333 | 1; |
| | 334 | |
| | 335 | __END__ |