| | 362 | COMMENT: |
| | 363 | # comments retrieval |
| | 364 | { |
| | 365 | my $wsse_header = make_wsse($chuck_token); |
| | 366 | my $uri = new URI; |
| | 367 | $uri->path('/mt-atom.cgi/comments/blog_id=1'); |
| | 368 | my $req = new HTTP::Request(GET => $uri); |
| | 369 | $req->header('Authorization' => 'Atom'); |
| | 370 | $req->header('X-WSSE' => $wsse_header); |
| | 371 | |
| | 372 | my $resp = $ua->request($req); |
| | 373 | if (ok($resp->is_success)) { |
| | 374 | my $thr_ns = XML::Atom::Namespace->new(prefix => undef, uri => 'http://purl.org/syndication/thread/1.0'); |
| | 375 | my $comments = XML::Atom::Feed->new(\$resp->content()); |
| | 376 | my $count = MT::Comment->count({ |
| | 377 | blog_id => 1, visible => 1 |
| | 378 | }); |
| | 379 | is( $count, scalar($comments->entries), 'comment count' ); |
| | 380 | foreach my $c ( $comments->entries ) { |
| | 381 | my $id = $c->id; |
| | 382 | my ( $cmt_id ) = $id =~ m{/([0-9]+)$}; |
| | 383 | die unless $cmt_id; |
| | 384 | my $mt_comment = MT::Comment->load($cmt_id); |
| | 385 | die unless $mt_comment; |
| | 386 | my $mt_entry = $mt_comment->entry; |
| | 387 | is($c->title, $mt_entry->title, 'comment title == entry title'); |
| | 388 | is( $c->author->name, $mt_comment->author, 'comment author' ); |
| | 389 | is( $c->author->email || '', $mt_comment->email || '', 'commenter email' ); |
| | 390 | is( $c->author->uri || '', $mt_comment->url || '', 'commenter url' ); |
| | 391 | if ( $XML::Atom::LIBXML ) { |
| | 392 | my $nodelist = $c->elem->getElementsByTagNameNS('http://purl.org/syndication/thread/1.0', 'in-reply-to'); |
| | 393 | my $irt = $nodelist->shift; |
| | 394 | ok($irt, 'in-reply-to'); |
| | 395 | is( $irt->ref, $mt_entry->atom_id, 'in-reply-to/ref' ); |
| | 396 | is( $irt->href, $mt_entry->permalink, 'in-reply-to/href' ); |
| | 397 | } |
| | 398 | } |
| | 399 | } |
| | 400 | else { |
| | 401 | die $resp->content(); |
| | 402 | } |
| | 403 | } |
| | 404 | |
| | 405 | { |
| | 406 | my $iter = MT::Comment->count_group_by( |
| | 407 | { blog_id => 1, visible => 1 }, |
| | 408 | { group => ['entry_id'], sort => [ { desc => 'DESC', column => '1' } ] |
| | 409 | } |
| | 410 | ); |
| | 411 | #$Data::ObjectDriver::PROFILE = 1; |
| | 412 | #my $p = Data::ObjectDriver->profiler; |
| | 413 | #$p->reset; |
| | 414 | #print "$_\n" foreach @{$p->query_log}; |
| | 415 | my ( $count, $eid ) = $iter->(); |
| | 416 | $iter->('finish'); |
| | 417 | my $entry = MT::Entry->load($eid); |
| | 418 | |
| | 419 | my $wsse_header = make_wsse($chuck_token); |
| | 420 | my $uri = new URI; |
| | 421 | $uri->path('/mt-atom.cgi/1.0/blog_id=1/entry_id=' . $entry->id); |
| | 422 | my $req = new HTTP::Request(GET => $uri); |
| | 423 | $req->header('Authorization' => 'Atom'); |
| | 424 | $req->header('X-WSSE' => $wsse_header); |
| | 425 | |
| | 426 | my $resp = $ua->request($req); |
| | 427 | if (ok($resp->is_success)) { |
| | 428 | my $feed = XML::Atom::Entry->new(\$resp->content()); |
| | 429 | my ($replies) = grep { |
| | 430 | $_->rel eq 'replies' |
| | 431 | } $feed->links; |
| | 432 | |
| | 433 | # retrieve comments from replies url |
| | 434 | my $replies_uri = new URI($replies->href); |
| | 435 | my $wsse_header = make_wsse($chuck_token); |
| | 436 | my $uri = new URI; |
| | 437 | $uri->path($replies_uri->path); |
| | 438 | my $req = new HTTP::Request(GET => $uri); |
| | 439 | $req->header('Authorization' => 'Atom'); |
| | 440 | $req->header('X-WSSE' => $wsse_header); |
| | 441 | |
| | 442 | my $resp = $ua->request($req); |
| | 443 | my $thr_ns = XML::Atom::Namespace->new(prefix => undef, uri => 'http://purl.org/syndication/thread/1.0'); |
| | 444 | if (ok($resp->is_success)) { |
| | 445 | my $comments = XML::Atom::Feed->new(\$resp->content()); |
| | 446 | is( $count, scalar($comments->entries), 'comment count' ); |
| | 447 | foreach my $e ( $comments->entries ) { |
| | 448 | is($e->title, $entry->title, 'comment title == entry title'); |
| | 449 | my $id = $e->id; |
| | 450 | my ( $cmt_id ) = $id =~ m{/([0-9]+)$}; |
| | 451 | die unless $cmt_id; |
| | 452 | my $mt_comment = MT::Comment->load($cmt_id); |
| | 453 | die unless $mt_comment; |
| | 454 | is( $e->author->name, $mt_comment->author, 'comment author' ); |
| | 455 | is( $e->author->email || '', $mt_comment->email || '', 'commenter email' ); |
| | 456 | is( $e->author->uri || '', $mt_comment->url || '', 'commenter url' ); |
| | 457 | if ( $XML::Atom::LIBXML ) { |
| | 458 | my $nodelist = $e->elem->getElementsByTagNameNS('http://purl.org/syndication/thread/1.0', 'in-reply-to'); |
| | 459 | my $irt = $nodelist->shift; |
| | 460 | ok($irt, 'in-reply-to'); |
| | 461 | is( $irt->ref, $entry->atom_id, 'in-reply-to/ref' ); |
| | 462 | is( $irt->href, $entry->permalink, 'in-reply-to/href' ); |
| | 463 | } |
| | 464 | } |
| | 465 | } |
| | 466 | else { |
| | 467 | die $resp->content(); |
| | 468 | } |
| | 469 | } |
| | 470 | } |
| | 471 | |
| | 472 | { |
| | 473 | my $thr_ns = XML::Atom::Namespace->new(prefix => undef, uri => 'http://purl.org/syndication/thread/1.0'); |
| | 474 | my $wsse_header = make_wsse($chuck_token); |
| | 475 | my $uri = new URI; |
| | 476 | $uri->path('/mt-atom.cgi/comments/blog_id=1/comment_id=1'); |
| | 477 | my $req = new HTTP::Request(GET => $uri); |
| | 478 | $req->header('Authorization' => 'Atom'); |
| | 479 | $req->header('X-WSSE' => $wsse_header); |
| | 480 | |
| | 481 | my $resp = $ua->request($req); |
| | 482 | if (ok($resp->is_success)) { |
| | 483 | my $c = XML::Atom::Entry->new(\$resp->content()); |
| | 484 | my $mt_comment = MT::Comment->load(1); |
| | 485 | die unless $mt_comment; |
| | 486 | my $entry = $mt_comment->entry; |
| | 487 | is( $c->title, $entry->title, 'comment title == entry title' ); |
| | 488 | is( $c->author->name, $mt_comment->author, 'comment author' ); |
| | 489 | is( $c->author->email || '', $mt_comment->email || '', 'commenter email' ); |
| | 490 | is( $c->author->uri || '', $mt_comment->url || '', 'commenter url' ); |
| | 491 | if ( $XML::Atom::LIBXML ) { |
| | 492 | my $nodelist = $c->elem->getElementsByTagNameNS('http://purl.org/syndication/thread/1.0', 'in-reply-to'); |
| | 493 | my $irt = $nodelist->shift; |
| | 494 | ok($irt, 'in-reply-to'); |
| | 495 | is( $irt->ref, $entry->atom_id, 'in-reply-to/ref' ); |
| | 496 | is( $irt->href, $entry->permalink, 'in-reply-to/href' ); |
| | 497 | } |
| | 498 | } |
| | 499 | else { |
| | 500 | die $resp->content(); |
| | 501 | } |
| | 502 | } |