Skip to content

Commit

Permalink
Add additional test cases for deleting pages with custom status
Browse files Browse the repository at this point in the history
Fix #295
  • Loading branch information
esudalaimadan authored and sudar committed Aug 2, 2018
1 parent a1583ef commit b6266d8
Showing 1 changed file with 379 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,383 @@ public function test_that_private_pages_can_be_trashed() {
$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 10, count( $trash_pages ) );
}

/**
* Test delete pages of single custom post status
*/
public function test_that_pages_from_single_custom_post_status_can_be_deleted() {
register_post_status( 'custom' );
$this->factory->post->create_many( 50, array(
'post_type' => 'page',
'post_status' => 'custom',
) );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 50, count( $custom_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

$delete_options = array(
'post_status' => array( 'custom' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => true,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 0, count( $custom_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 0, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted.
$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

}

/**
* Test pages of single custom post status can be trashed
*/
public function test_that_pages_from_single_custom_post_status_can_be_trashed() {
register_post_status( 'custom' );
$this->factory->post->create_many( 50, array(
'post_type' => 'page',
'post_status' => 'custom',
) );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 50, count( $custom_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

$delete_options = array(
'post_status' => array( 'custom' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => false,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 0, count( $custom_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 50, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted/moved to trash.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted/moved to trash.
$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );
}

/**
* Test delete pages of two custom post statuses
*/
public function test_that_pages_from_two_custom_post_statuses_can_be_deleted() {
register_post_status( 'custom_1' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom_1',
) );

$custom_1_pages = $this->get_pages_by_status( 'custom_1' );
$this->assertEquals( 25, count( $custom_1_pages ) );

register_post_status( 'custom_2' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom_2',
) );

$custom_2_pages = $this->get_pages_by_status( 'custom_2' );
$this->assertEquals( 25, count( $custom_2_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

$delete_options = array(
'post_status' => array( 'custom_1', 'custom_2' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => true,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_1_pages = $this->get_pages_by_status( 'custom_1' );
$this->assertEquals( 0, count( $custom_1_pages ) );

$custom_2_pages = $this->get_pages_by_status( 'custom_2' );
$this->assertEquals( 0, count( $custom_2_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 0, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted/moved to trash.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted/moved to trash.
$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

}

/**
* Test pages of two custom post statuses can be trashed
*/
public function test_that_pages_from_two_custom_post_statuses_can_be_trashed() {
register_post_status( 'custom_1' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom_1',
) );

$custom_1_pages = $this->get_pages_by_status( 'custom_1' );
$this->assertEquals( 25, count( $custom_1_pages ) );

register_post_status( 'custom_2' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom_2',
) );

$custom_2_pages = $this->get_pages_by_status( 'custom_2' );
$this->assertEquals( 25, count( $custom_2_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

$delete_options = array(
'post_status' => array( 'custom_1', 'custom_2' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => false,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_1_pages = $this->get_pages_by_status( 'custom_1' );
$this->assertEquals( 0, count( $custom_1_pages ) );

$custom_2_pages = $this->get_pages_by_status( 'custom_2' );
$this->assertEquals( 0, count( $custom_2_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 50, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted/moved to trash.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted/moved to trash.
$published_pages = $this->get_pages_by_status();
$this->assertEquals( 10, count( $published_pages ) );

}

/**
* Test delete pages of one custom post status and one built-in post status
*/
public function test_pages_from_custom_and_built_in_post_status_can_be_deleted_together() {
register_post_status( 'custom' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom',
) );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 25, count( $custom_pages ) );

$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status( 'publish' );
$this->assertEquals( 25, count( $published_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'private',
) );

$private_pages = $this->get_pages_by_status( 'private' );
$this->assertEquals( 10, count( $private_pages ) );

$delete_options = array(
'post_status' => array( 'custom', 'publish' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => true,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 0, count( $custom_pages ) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 0, count( $published_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 0, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted/moved to trash.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted/moved to trash.
$private_pages = $this->get_pages_by_status( 'private' );
$this->assertEquals( 10, count( $private_pages ) );
}

/**
* Test pages of one custom post status and one built-in post status can be trashed
*/
public function test_pages_from_custom_and_built_in_post_status_can_be_trashed_together() {
register_post_status( 'custom' );
$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'custom',
) );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 25, count( $custom_pages ) );

$this->factory->post->create_many( 25, array(
'post_type' => 'page',
'post_status' => 'publish',
) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 25, count( $published_pages ) );

register_post_status( 'keep_me' );
$this->factory->post->create_many( 20, array(
'post_type' => 'page',
'post_status' => 'keep_me',
) );

$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

$this->factory->post->create_many( 10, array(
'post_type' => 'page',
'post_status' => 'private',
) );

$private_pages = $this->get_pages_by_status( 'private' );
$this->assertEquals( 10, count( $private_pages ) );

$delete_options = array(
'post_status' => array( 'custom', 'publish' ),
'limit_to' => 0,
'restrict' => false,
'force_delete' => false,
);

$pages_deleted = $this->module->delete( $delete_options );
$this->assertEquals( 50, $pages_deleted );

$custom_pages = $this->get_pages_by_status( 'custom' );
$this->assertEquals( 0, count( $custom_pages ) );

$published_pages = $this->get_pages_by_status();
$this->assertEquals( 0, count( $published_pages ) );

$trash_pages = $this->get_pages_by_status( 'trash' );
$this->assertEquals( 50, count( $trash_pages ) );

// Make sure other custom post status pages are not deleted/moved to trash.
$keep_me_pages = $this->get_pages_by_status( 'keep_me' );
$this->assertEquals( 20, count( $keep_me_pages ) );

// Make sure other built-in post status pages are not deleted/moved to trash.
$private_pages = $this->get_pages_by_status( 'private' );
$this->assertEquals( 10, count( $private_pages ) );
}
}

0 comments on commit b6266d8

Please sign in to comment.