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
2 files
+ 221
6
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -6,19 +6,35 @@
*/
/**
* Class Test_Automatically_Paginate_Posts.
*
* @coversDefaultClass Automatically_Paginate_Posts
*/
class SampleTest extends WP_UnitTestCase {
class Test_Automatically_Paginate_Posts extends WP_UnitTestCase {
/**
* Plugin instance.
*
* @var Automatically_Paginate_Posts
*/
protected $_instance;
/**
* Prepare tests.
*
* @return void
*/
public function set_up() {
parent::set_up();
$this->_instance = new Automatically_Paginate_Posts();
$this->_instance->action_init();
}
/**
* Test magic getter.
*
* @covers ::__get()
* @returns void
*/
public function test___get() {
$this->assertEquals(
@@ -36,7 +52,10 @@ class SampleTest extends WP_UnitTestCase {
}
/**
* Test modifications to plugin action links.
*
* @covers ::filter_plugin_action_links()
* @returns void
*/
public function test_filter_plugin_action_links() {
$this->assertEmpty(
@@ -56,4 +75,172 @@ class SampleTest 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'] );
add_filter(
'pre_option_pages',
static function() use( $input ) {
return $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, split to 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, split to 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,
),
),
'Classic post, one page, split on words' => array(
"1\r\n\r\n2\r\n\r\n3\r\n\r\n4",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n2\r\n\r\n3\r\n\r\n4",
),
'type' => 'words',
'num_pages' => 2,
'num_words' => 5,
),
),
'Classic post, two pages, split on words' => array(
"1\r\n\r\n2<!--nextpage-->\r\n\r\n3\r\n\r\n4",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n2\r\n\r\n3\r\n\r\n4",
),
'type' => 'words',
'num_pages' => 2,
'num_words' => 2,
),
),
'Classic post, three pages, split on words' => array(
"1<!--nextpage-->\r\n\r\n2<!--nextpage-->\r\n\r\n3<!--nextpage-->\r\n\r\n4",
array(
'post_args' => array(
'post_type' => 'post',
'post_content' => "1\r\n\r\n2\r\n\r\n3\r\n\r\n4",
),
'type' => 'words',
'num_pages' => 2,
'num_words' => 1,
),
),
);
}
}
/**
* Test class for admin-related restrictions.
*/
class Test_Autopaging_Admin {
/**
* Mock being in wp-admin.
*
* @return bool
*/
public function in_admin() {
return true;
}
}
Loading