Skip to content

Commit

Permalink
Do not fill the original post URL if the post is not a Rewrite & Repu…
Browse files Browse the repository at this point in the history
…blish copy
  • Loading branch information
enricobattocchi committed Jan 27, 2021
1 parent 02ef49d commit 42e4ba9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui/class-block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public function get_check_permalink() {
public function get_original_post_edit_url() {
$post = \get_post();

if ( ! $post instanceof WP_Post ) {
if ( ! $post instanceof WP_Post || ! $this->permissions_helper->is_rewrite_and_republish_copy( $post ) ) {
return '';
}

Expand Down
38 changes: 38 additions & 0 deletions tests/ui/class-block-editor-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,11 @@ public function test_get_original_post_edit_url_successful() {
Monkey\Functions\expect( '\get_post' )
->andReturn( $post );

$this->permissions_helper
->expects( 'is_rewrite_and_republish_copy' )
->with( $post )
->andReturnTrue();

$utils
->expects( 'get_original_post_id' )
->with( $post->ID )
Expand Down Expand Up @@ -739,6 +744,34 @@ function ( $array, $string ) {
);
}

/**
* Tests the unsuccessful get_original_post_edit_url when the post is not a Rewrite & Republish copy.
*
* @covers \Yoast\WP\Duplicate_Post\UI\Block_Editor::get_original_post_edit_url
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function test_get_original_post_edit_url_not_rewrite_and_republish() {
$utils = Mockery::mock( 'alias:\Yoast\WP\Duplicate_Post\Utils' );
$post = Mockery::mock( \WP_Post::class );
$post->ID = 128;
$original_id = 64;
$nonce = '12345678';

Monkey\Functions\expect( '\get_post' )
->andReturn( $post );

$this->permissions_helper
->expects( 'is_rewrite_and_republish_copy' )
->with( $post )
->andReturnFalse();

$this->assertSame(
'',
$this->instance->get_original_post_edit_url()
);
}

/**
* Tests the get_original_post_edit_url when there is no post.
*
Expand Down Expand Up @@ -770,6 +803,11 @@ public function test_get_original_post_edit_url_no_original() {
Monkey\Functions\expect( '\get_post' )
->andReturn( $post );

$this->permissions_helper
->expects( 'is_rewrite_and_republish_copy' )
->with( $post )
->andReturnTrue();

$utils
->expects( 'get_original_post_id' )
->with( $post->ID )
Expand Down

0 comments on commit 42e4ba9

Please sign in to comment.