Skip to content

Commit

Permalink
fix: removing repetitive test.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiesshop committed Jul 2, 2024
1 parent 175d8fe commit de55e39
Showing 1 changed file with 0 additions and 211 deletions.
211 changes: 0 additions & 211 deletions tests/Integration/CoAuthorsPlusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1917,217 +1917,6 @@ public function test_assign_multiple_post_authors_one_linked_passed_using_user_l
$this->assertEquals( 'cap-' . $linked_author_1->user_login, $guest_author_term[0]->slug );
}

/**
* This test is a combination of a few different aspects that establish some expected plugin behavior.
* Two posts are created to test with. Both have no WP_User as the author (i.e. wp_posts.post_author = 0).
* For the first post:
* 1. A guest author is created, and assigned to the post.
* 2. Since there is no WP_User which is passed, and the GA is NOT being appended, the result should be false.
* 3. The wp_posts.post_author column should still be 0 since this is a GA and not a WP_User or a linked GA.
*
* For the second post:
* 1. A guest author is created, and appended to the post.
* 2. Since we are appending a coauthor, it does not matter if there was already a WP_User author, so result should be true.
* 3. The wp_posts.post_author column should still be 0 since this is a GA and not a WP_User or a linked GA.
*
* Going back to the first post:
* 1. A linked user and a WP_User are created and assigned to this post.
* 2. Result should be true since here we essentially have 2 WP_Users.
* 3. Since there is a WP_User, and it is passed first, the wp_posts.post_author column should be set to the ID for that WP_User.
* 4. There should only be 2 author terms for this post, one for the WP_User, and one for the linked account.
* The term for the GA which was previously assigned is deleted.
*
* Finally, going back to the second post:
* 1. A linked user and a WP_User are created and appended to this post.
* 2. Result should be true since we have 2 WP_Users.
* 3. Here we passed the linked author first, so the wp_posts.post_author column should match the ID for the linked WP_user account.
* 4. There should be 3 author terms for this post, one for the GA, the WP_user, and linked account.
* @return void
*/
public function test_assign_post_authors_from_post_with_no_author() {
$post_id_1 = $this->factory()->post->create(
array(
'post_author' => 0,
'post_status' => 'publish',
'post_type' => 'post',
)
);

$query = new WP_Query(
array(
'p' => $post_id_1,
)
);

$this->assertEquals( 1, $query->found_posts );
$this->assertEquals( 0, $query->posts[0]->post_author );

$post_id_2 = $this->factory()->post->create(
array(
'post_author' => 0,
'post_status' => 'publish',
'post_type' => 'post',
)
);

$second_post_query = new WP_Query(
array(
'p' => $post_id_2,
)
);

$this->assertEquals( 1, $second_post_query->found_posts );
$this->assertEquals( 0, $second_post_query->posts[0]->post_author );

$random_username = 'random_user_' . rand( 90000, 100000 );
$display_name = str_replace( '_', ' ', $random_username );

$guest_author_1_id = $this->_cap->guest_authors->create(
array(
'user_login' => $random_username,
'display_name' => $display_name,
)
);
$guest_author_1 = $this->_cap->get_coauthor_by( 'id', $guest_author_1_id );

$this->assertIsObject( $guest_author_1 );
$this->assertThat(
$guest_author_1,
$this->logicalNot(
$this->isInstanceOf( WP_User::class )
)
);

$this->_cap->guest_authors->create_guest_author_from_user_id( $this->author3->ID );

$linked_author_1 = $this->_cap->get_coauthor_by( 'id', $this->author3->ID );
$this->assertIsObject( $linked_author_1 );
$this->assertThat(
$linked_author_1,
$this->logicalNot(
$this->isInstanceOf( WP_User::class )
)
);
$this->assertTrue( property_exists( $linked_author_1, 'is_wp_user' ) );
$this->assertTrue( $linked_author_1->is_wp_user );
$this->assertTrue( property_exists( $linked_author_1, 'wp_user' ) );
$this->assertInstanceOf( WP_User::class, $linked_author_1->wp_user );
$this->assertEquals( $this->author3->ID, $linked_author_1->wp_user->ID );

$result = $this->_cap->add_coauthors(
$post_id_1,
array(
$guest_author_1->user_login,
)
);

$this->assertFalse( $result );

$post_1_author_terms = wp_get_post_terms( $post_id_1, $this->_cap->coauthor_taxonomy );

$this->assertIsArray( $post_1_author_terms );
$this->assertCount( 1, $post_1_author_terms );
$this->assertEquals( 'cap-' . $guest_author_1->user_login, $post_1_author_terms[0]->slug );

$third_post_query = new WP_Query(
array(
'p' => $post_id_1,
)
);

$this->assertEquals( 1, $third_post_query->found_posts );
$this->assertEquals( 0, $third_post_query->posts[0]->post_author );

$result = $this->_cap->add_coauthors(
$post_id_2,
array(
$guest_author_1->user_login,
),
true
);

$this->assertTrue( $result );

$fourth_post_query = new WP_Query(
array(
'p' => $post_id_2,
)
);

$this->assertEquals( 1, $fourth_post_query->found_posts );
$this->assertEquals( 0, $fourth_post_query->posts[0]->post_author );

$result = $this->_cap->add_coauthors(
$post_id_1,
array(
$this->author2->user_login,
$linked_author_1->user_login,
)
);

$this->assertTrue( $result );

$fifth_post_query = new WP_Query(
array(
'p' => $post_id_1,
)
);

$this->assertEquals( 1, $fifth_post_query->found_posts );
$this->assertEquals( $this->author2->ID, $fifth_post_query->posts[0]->post_author );

$post_author_terms = wp_get_post_terms( $post_id_1, $this->_cap->coauthor_taxonomy );

$this->assertIsArray( $post_author_terms );
$this->assertCount( 2, $post_author_terms );

$author_slugs = array(
'cap-' . $this->author2->user_login,
'cap-' . $linked_author_1->user_login,
);

foreach ( $post_author_terms as $term ) {
$this->assertInstanceOf( WP_Term::class, $term );
$this->assertContains( $term->slug, $author_slugs );
}

$result = $this->_cap->add_coauthors(
$post_id_2,
array(
$linked_author_1->user_login,
$this->author2->user_login,
),
true
);

$this->assertTrue( $result );

$sixth_post_query = new WP_Query(
array(
'p' => $post_id_2,
)
);

$this->assertEquals( 1, $sixth_post_query->found_posts );
$this->assertEquals( $this->author3->ID, $sixth_post_query->posts[0]->post_author );

$post_author_terms = wp_get_post_terms( $post_id_2, $this->_cap->coauthor_taxonomy );

$this->assertIsArray( $post_author_terms );
$this->assertCount( 3, $post_author_terms );

$author_slugs = array(
'cap-' . $guest_author_1->user_login,
'cap-' . $this->author2->user_login,
'cap-' . $linked_author_1->user_login,
);

foreach ( $post_author_terms as $term ) {
$this->assertInstanceOf( WP_Term::class, $term );
$this->assertContains( $term->slug, $author_slugs );
}
}

/**
* @covers CoAuthors_Plus::is_block_editor()
*/
Expand Down

0 comments on commit de55e39

Please sign in to comment.