2023-02-20 18:08:10 +01:00
< ? php
2023-10-19 21:46:31 +02:00
use Activitypub\Shortcodes ;
2023-02-20 18:08:10 +01:00
class Test_Activitypub_Shortcodes extends WP_UnitTestCase {
2023-10-19 21:46:31 +02:00
2023-02-20 18:08:10 +01:00
public function test_content () {
2023-10-19 21:46:31 +02:00
Shortcodes :: register ();
2023-02-20 18:08:10 +01:00
global $post ;
$post_id = - 99 ; // negative ID, to avoid clash with a valid post
$post = new stdClass ();
$post -> ID = $post_id ;
$post -> post_author = 1 ;
$post -> post_date = current_time ( 'mysql' );
$post -> post_date_gmt = current_time ( 'mysql' , 1 );
$post -> post_title = 'Some title or other' ;
2023-02-20 21:18:03 +01:00
$post -> post_content = '<script>test</script>hallo<script type="javascript">{"asdf": "qwerty"}</script><style></style>' ;
2023-02-20 18:08:10 +01:00
$post -> post_status = 'publish' ;
$post -> comment_status = 'closed' ;
$post -> ping_status = 'closed' ;
$post -> post_name = 'fake-page-' . rand ( 1 , 99999 ); // append random number to avoid clash
$post -> post_type = 'page' ;
$post -> filter = 'raw' ; // important!
$content = '[ap_content]' ;
// Fill in the shortcodes.
setup_postdata ( $post );
$content = do_shortcode ( $content );
wp_reset_postdata ();
$this -> assertEquals ( '<p>hallo</p>' , $content );
2023-10-19 21:46:31 +02:00
Shortcodes :: unregister ();
2023-02-20 18:08:10 +01:00
}
2023-03-02 09:54:52 +01:00
public function test_password_protected_content () {
2023-10-19 21:46:31 +02:00
Shortcodes :: register ();
2023-03-02 09:54:52 +01:00
global $post ;
$post_id = - 98 ; // negative ID, to avoid clash with a valid post
$post = new stdClass ();
$post -> ID = $post_id ;
$post -> post_author = 1 ;
$post -> post_date = current_time ( 'mysql' );
$post -> post_date_gmt = current_time ( 'mysql' , 1 );
$post -> post_title = 'Some title or other' ;
$post -> post_content = '<script>test</script>hallo<script type="javascript">{"asdf": "qwerty"}</script><style></style>' ;
$post -> comment_status = 'closed' ;
$post -> ping_status = 'closed' ;
$post -> post_name = 'fake-page-' . rand ( 1 , 99999 ); // append random number to avoid clash
$post -> post_type = 'page' ;
$post -> filter = 'raw' ; // important!
2023-07-17 17:23:13 +02:00
$post -> post_password = 'abc' ;
2023-03-02 09:54:52 +01:00
$content = '[ap_content]' ;
// Fill in the shortcodes.
setup_postdata ( $post );
$content = do_shortcode ( $content );
wp_reset_postdata ();
$this -> assertEquals ( '' , $content );
2023-10-19 21:46:31 +02:00
Shortcodes :: unregister ();
2023-03-02 09:54:52 +01:00
}
2023-12-16 07:36:45 +01:00
public function test_excerpt () {
Shortcodes :: register ();
global $post ;
$post_id = - 97 ; // negative ID, to avoid clash with a valid post
$post = new stdClass ();
$post -> ID = $post_id ;
$post -> post_author = 1 ;
$post -> post_date = current_time ( 'mysql' );
$post -> post_date_gmt = current_time ( 'mysql' , 1 );
$post -> post_title = 'Some title or other' ;
$post -> post_content = '<script>test</script>Lorem ipsum dolor sit amet, consectetur.<script type="javascript">{"asdf": "qwerty"}</script><style></style>' ;
$post -> post_status = 'publish' ;
$post -> comment_status = 'closed' ;
$post -> ping_status = 'closed' ;
$post -> post_name = 'fake-page-' . rand ( 1 , 99999 ); // append random number to avoid clash
$post -> post_type = 'page' ;
$post -> filter = 'raw' ; // important!
$content = '[ap_excerpt length="25"]' ;
// Fill in the shortcodes.
setup_postdata ( $post );
$content = do_shortcode ( $content );
wp_reset_postdata ();
$this -> assertEquals ( " <p>Lorem ipsum […]</p> \n " , $content );
Shortcodes :: unregister ();
}
2023-02-20 18:08:10 +01:00
}