@@ -547,4 +547,132 @@ public function provide_wp_versions() {
547
547
),
548
548
);
549
549
}
550
+
551
+ /**
552
+ * Test generate_post_summary function.
553
+ *
554
+ * @covers \Activitypub\generate_post_summary
555
+ * @dataProvider get_post_summary_data
556
+ *
557
+ * @param string $desc The description of the test.
558
+ * @param object $post The post object.
559
+ * @param string $expected The expected summary.
560
+ * @param int $length The length of the summary.
561
+ */
562
+ public function test_generate_post_summary ( $ desc , $ post , $ expected , $ length = 500 ) {
563
+ \add_shortcode (
564
+ 'activitypub_test_shortcode ' ,
565
+ function () {
566
+ return 'mighty short code ' ;
567
+ }
568
+ );
569
+
570
+ $ post_id = \wp_insert_post ( $ post );
571
+
572
+ $ this ->assertEquals (
573
+ $ expected ,
574
+ \Activitypub \generate_post_summary ( $ post_id , $ length ),
575
+ $ desc
576
+ );
577
+
578
+ \wp_delete_post ( $ post_id , true );
579
+ \remove_shortcode ( 'activitypub_test_shortcode ' );
580
+ }
581
+
582
+ /**
583
+ * Data provider for test_generate_post_summary.
584
+ *
585
+ * @return array[]
586
+ */
587
+ public function get_post_summary_data () {
588
+ return array (
589
+ array (
590
+ 'Excerpt ' ,
591
+ array (
592
+ 'post_excerpt ' => 'Hello World ' ,
593
+ ),
594
+ '<p>Hello World</p> ' . PHP_EOL ,
595
+ ),
596
+ array (
597
+ 'Content ' ,
598
+ array (
599
+ 'post_content ' => 'Hello World ' ,
600
+ ),
601
+ '<p>Hello World</p> ' . PHP_EOL ,
602
+ ),
603
+ array (
604
+ 'Content with more tag ' ,
605
+ array (
606
+ 'post_content ' => 'Hello World <!--more--> More ' ,
607
+ ),
608
+ '<p>Hello World […]</p> ' . PHP_EOL ,
609
+ ),
610
+ array (
611
+ 'Excerpt with shortcode ' ,
612
+ array (
613
+ 'post_excerpt ' => 'Hello World [activitypub_test_shortcode] ' ,
614
+ ),
615
+ '<p>Hello World</p> ' . PHP_EOL ,
616
+ ),
617
+ array (
618
+ 'Content with shortcode ' ,
619
+ array (
620
+ 'post_content ' => 'Hello World [activitypub_test_shortcode] ' ,
621
+ ),
622
+ '<p>Hello World</p> ' . PHP_EOL ,
623
+ ),
624
+ array (
625
+ 'Excerpt more than limit ' ,
626
+ array (
627
+ 'post_excerpt ' => 'Hello World Hello World Hello World Hello World Hello World ' ,
628
+ ),
629
+ '<p>Hello World Hello World Hello World Hello World Hello World</p> ' . PHP_EOL ,
630
+ 10 ,
631
+ ),
632
+ array (
633
+ 'Content more than limit ' ,
634
+ array (
635
+ 'post_content ' => 'Hello World Hello World Hello World Hello World Hello World ' ,
636
+ ),
637
+ '<p>Hello […]</p> ' . PHP_EOL ,
638
+ 10 ,
639
+ ),
640
+ array (
641
+ 'Content more than limit with more tag ' ,
642
+ array (
643
+ 'post_content ' => 'Hello World Hello <!--more--> World Hello World Hello World Hello World ' ,
644
+ ),
645
+ '<p>Hello World Hello […]</p> ' . PHP_EOL ,
646
+ 1 ,
647
+ ),
648
+ array (
649
+ 'Test HTML content ' ,
650
+ array (
651
+ 'post_content ' => '<p>Hello World</p> ' ,
652
+ ),
653
+ '<p>Hello World</p> ' . PHP_EOL ,
654
+ ),
655
+ array (
656
+ 'Test HTML content with anchor ' ,
657
+ array (
658
+ 'post_content ' => 'Hello <a href="https://example.com">World</a> ' ,
659
+ ),
660
+ '<p>Hello World</p> ' . PHP_EOL ,
661
+ ),
662
+ array (
663
+ 'Test HTML excerpt ' ,
664
+ array (
665
+ 'post_excerpt ' => '<p>Hello World</p> ' ,
666
+ ),
667
+ '<p>Hello World</p> ' . PHP_EOL ,
668
+ ),
669
+ array (
670
+ 'Test HTML excerpt with anchor ' ,
671
+ array (
672
+ 'post_excerpt ' => 'Hello <a href="https://example.com">World</a> ' ,
673
+ ),
674
+ '<p>Hello World</p> ' . PHP_EOL ,
675
+ ),
676
+ );
677
+ }
550
678
}
0 commit comments