Skip to content
Snippets Groups Projects

Add block-editor support

Merged Erick Hitter requested to merge fix/gutenberg into master
Compare and Show latest version
1 file
+ 128
0
Compare changes
  • Side-by-side
  • Inline
@@ -27,6 +27,7 @@ class Test_Automatically_Paginate_Posts extends WP_UnitTestCase {
parent::set_up();
$this->_instance = new Automatically_Paginate_Posts();
$this->_instance->action_init();
}
/**
@@ -74,4 +75,131 @@ class Test_Automatically_Paginate_Posts extends WP_UnitTestCase {
'Failed to assert that settings link is added for this plugin.'
);
}
/**
* Test `the_post` filtering when in admin.
*
* @covers ::filter_the_posts()
*/
public function test_filter_the_posts_admin() {
$old_screen = $GLOBALS['current_screen'];
$GLOBALS['current_screen'] = new Test_Autopaging_Admin();
$test_posts = [
'unit-test',
];
$this->assertEquals(
$test_posts,
$this->_instance->filter_the_posts( $test_posts ),
'Failed to assert that posts are not modified in admin.'
);
$GLOBALS['current_screen'] = $old_screen;
}
/**
* Test modifications to various posts.
*
* @covers ::filter_the_posts()
* @dataProvider data_provider_filter_the_posts
*
* @param string $expected Expected post content.
* @param array $input Test arguments.
*/
public function test_filter_the_posts( $expected, $input ) {
$post = $this->factory->post->create_and_get( $input['post_args'] );
update_option( 'autopaging_paging_type', $input['type'] );
add_filter(
'autopaging_num_pages',
static function() use( $input ) {
return $input['num_pages'];
}
);
add_filter(
'autopaging_num_words',
static function() use( $input ) {
return $input['num_words'];
}
);
$this->assertEquals(
$expected,
$this->_instance->filter_the_posts( [ $post ] )[0]->post_content
);
}
/**
* Data provide to test post filtering.
*
* @return array
*/
public function data_provider_filter_the_posts() {
return array(
'Unsupported type' => array(
"I am a page.\r\n\r\nI should not be paginated.",
array(
'post_args' => array(
'post_type' => 'page',
'post_content' => "I am a page.\r\n\r\nI should not be paginated.",
),
'type' => 'pages',
'num_pages' => 2,
'num_words' => 2,
),
),
'Already paginated' => array(
"1\r\n\r\n<!--nextpage-->\r\n\r\n2\r\n\r\n3",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n<!--nextpage-->\r\n\r\n2\r\n\r\n3",
),
'type' => 'pages',
'num_pages' => 2,
'num_words' => 2,
),
),
'Classic post, two pages' => array(
"1\r\n\r\n2<!--nextpage-->\r\n\r\n3",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n2\r\n\r\n3",
),
'type' => 'pages',
'num_pages' => 2,
'num_words' => 2,
),
),
'Classic post, three pages' => array(
"1<!--nextpage-->\r\n\r\n2<!--nextpage-->\r\n\r\n3",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n2\r\n\r\n3",
),
'type' => 'pages',
'num_pages' => 3,
'num_words' => 2,
),
),
);
}
}
/**
* Test class for admin-related restrictions.
*/
class Test_Autopaging_Admin {
/**
* Mock being in wp-admin.
*
* @return bool
*/
public function in_admin() {
return true;
}
}
Loading