509 | | public function test_bbp_display_topics_feed_rss2() { |
510 | | // Remove the following lines when you implement this test. |
511 | | $this->markTestIncomplete( |
512 | | 'This test has not been implemented yet.' |
513 | | ); |
| 525 | public function test_bbp_display_topics_feed_rss2_rss() { |
| 526 | $f = $this->factory->forum->create(); |
| 527 | |
| 528 | $this->go_to( bbp_get_forum_permalink( $f ) . '&feed=rss2' ); |
| 529 | $feed = $this->do_rss2(); |
| 530 | $xml = xml_to_array( $feed ); |
| 531 | |
| 532 | // Get the rss element. |
| 533 | $rss = xml_find( $xml, 'rss' ); |
| 534 | |
| 535 | // There should only be one rss element. |
| 536 | $this->assertEquals( 1, count( $rss ) ); |
| 537 | |
| 538 | $this->assertEquals( '2.0', $rss[0]['attributes']['version'] ); |
| 539 | $this->assertEquals( 'http://purl.org/rss/1.0/modules/content/', $rss[0]['attributes']['xmlns:content'] ); |
| 540 | $this->assertEquals( 'http://wellformedweb.org/CommentAPI/', $rss[0]['attributes']['xmlns:wfw'] ); |
| 541 | $this->assertEquals( 'http://purl.org/dc/elements/1.1/', $rss[0]['attributes']['xmlns:dc'] ); |
| 542 | $this->assertEquals( 'http://www.w3.org/2005/Atom', $rss[0]['attributes']['xmlns:atom'] ); |
| 543 | $this->assertEquals( 'http://purl.org/rss/1.0/modules/syndication/', $rss[0]['attributes']['xmlns:sy'] ); |
| 544 | $this->assertEquals( 'http://purl.org/rss/1.0/modules/slash/', $rss[0]['attributes']['xmlns:slash'] ); |
| 545 | |
| 546 | // RSS should have exactly one child element (channel). |
| 547 | $this->assertEquals( 1, count( $rss[0]['child'] ) ); |
| 551 | * Test the channel element of a forum topics feed |
| 552 | * |
| 553 | * @group feeds |
| 554 | * @covers ::bbp_display_topics_feed_rss2 |
| 555 | */ |
| 556 | public function test_bbp_display_topics_feed_rss2_channel() { |
| 557 | $f = $this->factory->forum->create(); |
| 558 | |
| 559 | $this->go_to( bbp_get_forum_permalink( $f ) . '&feed=rss2' ); |
| 560 | |
| 561 | $feed = $this->do_rss2(); |
| 562 | $xml = xml_to_array( $feed ); |
| 563 | |
| 564 | // Get the rss -> channel element. |
| 565 | $channel = xml_find( $xml, 'rss', 'channel' ); |
| 566 | |
| 567 | // There should only be one rss -> channel element. |
| 568 | $this->assertEquals( 1, count( $channel ) ); |
| 569 | |
| 570 | // The rss -> channel element should not have any attributes. |
| 571 | $this->assertTrue( empty( $channel[0]['attributes'] ) ); |
| 572 | |
| 573 | $title = xml_find( $xml, 'rss', 'channel', 'title' ); |
| 574 | $this->assertEquals( get_option( 'blogname' ), $title[0]['content'] ); |
| 575 | |
| 576 | $link = xml_find( $xml, 'rss', 'channel', 'link' ); |
| 577 | $this->assertEquals( get_option( 'siteurl' ), $link[0]['content'] ); |
| 578 | |
| 579 | $desc = xml_find( $xml, 'rss', 'channel', 'description' ); |
| 580 | $this->assertEquals( get_option( 'blogdescription' ), $desc[0]['content'] ); |
| 581 | |
| 582 | $pubdate = xml_find( $xml, 'rss', 'channel', 'lastBuildDate' ); |
| 583 | $this->assertEquals( strtotime( get_lastpostmodified() ), strtotime( $pubdate[0]['content'] ) ); |
| 584 | |
| 585 | $generator = xml_find( $xml, 'rss', 'channel', 'generator' ); |
| 586 | $this->assertEquals( 'http://' . WP_TESTS_DOMAIN. bbp_get_version(), $generator[0]['content'] ); |
| 587 | |
| 588 | $language = xml_find( $xml, 'rss', 'channel', 'language' ); |
| 589 | $this->assertEquals( get_bloginfo_rss( 'language' ), $language[0]['content'] ); |
| 590 | |
| 591 | $updatePeriod = xml_find( $xml, 'rss', 'channel', 'sy:updatePeriod' ); |
| 592 | $duration = 'hourly'; |
| 593 | $this->assertEquals( apply_filters( 'rss_update_period', $duration ), $updatePeriod[0]['content'] ); |
| 594 | |
| 595 | $updateFrequency = xml_find( $xml, 'rss', 'channel', 'sy:updateFrequency' ); |
| 596 | $frequency = '1'; |
| 597 | $this->assertEquals( apply_filters( 'updateFrequency', $frequency ), $updateFrequency[0]['content'] ); |
| 598 | } |
| 599 | |
| 600 | /** |
| 601 | * Test the item elements of a forum topics feed |
| 602 | * |
| 603 | * @group feeds |
| 604 | * @covers ::bbp_display_topics_feed_rss2 |
| 605 | */ |
| 606 | public function test_bbp_display_topics_feed_rss2_items() { |
| 607 | $f = $this->factory->forum->create(); |
| 608 | |
| 609 | $t = $this->factory->topic->create_many( 2, array( |
| 610 | 'post_parent' => $f, |
| 611 | 'topic_meta' => array( |
| 612 | 'forum_id' => $f, |
| 613 | ), |
| 614 | ) ); |
| 615 | |
| 616 | $r = $this->factory->reply->create_many( 2, array( |
| 617 | 'post_parent' => $t[0], |
| 618 | 'reply_meta' => array( |
| 619 | 'forum_id' => $f, |
| 620 | 'topic_id' => $t[0], |
| 621 | ), |
| 622 | ) ); |
| 623 | |
| 624 | $this->go_to( bbp_get_forum_permalink( $f ) . '&feed=rss2' ); |
| 625 | $feed = $this->do_rss2(); |
| 626 | $xml = xml_to_array( $feed ); |
| 627 | |
| 628 | //var_dump( $this->do_rss2() ); |
| 629 | //var_dump( $xml ); |
| 630 | |
| 631 | // Get all the rss -> channel -> item elements. |
| 632 | $items = xml_find( $xml, 'rss', 'channel', 'item' ); |
| 633 | |
| 634 | // var_dump( $items ); |
| 635 | |
| 636 | // Check each of the items against the known post data. |
| 637 | foreach ( $items as $key => $item ) { |
| 638 | |
| 639 | var_dump( $item ); |
| 640 | |
| 641 | // Get topic for comparison. |
| 642 | $guid = xml_find( $items[ $key ]['child'], 'guid' ); |
| 643 | preg_match( '/\?p=(\d+)/', $guid[0]['content'], $matches ); |
| 644 | $topic = bbp_get_topic( $matches[1] ); |
| 645 | |
| 646 | // Title. |
| 647 | $title = xml_find( $items[ $key ]['child'], 'title' ); |
| 648 | $this->assertEquals( $topic->post_title, $title[0]['content'] ); |
| 649 | |
| 650 | // Link. |
| 651 | $link = xml_find( $items[ $key ]['child'], 'link' ); |
| 652 | $this->assertEquals( get_permalink( $post ), $link[0]['content'] ); |
| 653 | |
| 654 | // Comment link. |
| 655 | $comments_link = xml_find( $items[ $key ]['child'], 'comments' ); |
| 656 | $this->assertEquals( get_permalink( $post ) . '#respond', $comments_link[0]['content'] ); |
| 657 | |
| 658 | // Published date. |
| 659 | $pubdate = xml_find( $items[ $key ]['child'], 'pubDate' ); |
| 660 | $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $pubdate[0]['content'] ) ); |
| 661 | |
| 662 | // Author. |
| 663 | $creator = xml_find( $items[ $key ]['child'], 'dc:creator' ); |
| 664 | $user = new WP_User( $post->post_author ); |
| 665 | $this->assertEquals( $user->user_login, $creator[0]['content'] ); |
| 666 | |
| 667 | // GUID. |
| 668 | $guid = xml_find( $items[ $key ]['child'], 'guid' ); |
| 669 | $this->assertEquals( 'false', $guid[0]['attributes']['isPermaLink'] ); |
| 670 | $this->assertEquals( $post->guid, $guid[0]['content'] ); |
| 671 | |
| 672 | // Description/excerpt. |
| 673 | if ( ! empty( $post->post_excerpt ) ) { |
| 674 | $description = xml_find( $items[ $key ]['child'], 'description' ); |
| 675 | $this->assertEquals( trim( $post->post_excerpt ), trim( $description[0]['content'] ) ); |
| 676 | } |
| 677 | |
| 678 | // Topic content. |
| 679 | if ( ! $this->excerpt_only ) { |
| 680 | $content = xml_find( $items[ $key ]['child'], 'content:encoded' ); |
| 681 | $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) ); |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | /** |