Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Correct unit tests when running WP 5.7 #774

Merged
merged 6 commits into from Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -52,7 +52,7 @@ before_script:
# Set up unit tests
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
# Properly handle versions since the pre-installed PHPUnit is incompatible on some builds
- composer require --dev "phpunit/phpunit":"^5"
- composer require --dev "phpunit/phpunit":"^7"

script:
# WordPress Coding Standards.
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Expand Up @@ -10,7 +10,7 @@
<const name="WP_TESTS_MULTISITE" value="1" />
</php>
<testsuites>
<testsuite>
<testsuite name="tests">
<directory prefix="test-" suffix=".php">./tests/</directory>
</testsuite>
</testsuites>
Expand Down
Binary file added tests/fixtures/dummy-attachment.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 20 additions & 25 deletions tests/test-coauthors-guest-authors.php
Expand Up @@ -143,22 +143,17 @@ public function test_get_guest_author_thumbnail() {

$this->assertNull( $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 ) );

// Checks when guest author has thumbnail.
$filename = rand_str() . '.jpg';
$contents = rand_str();
$upload = wp_upload_bits( $filename, null, $contents );

$this->assertTrue( empty( $upload['error'] ) );

$attachment_id = $this->_make_attachment( $upload );
$attachment_id = $this->factory->attachment->create_upload_object( __DIR__ . '/fixtures/dummy-attachment.png' );

set_post_thumbnail( $guest_author->ID, $attachment_id );

$thumbnail = $guest_author_obj->get_guest_author_thumbnail( $guest_author, 0 );

$this->assertContains( 'avatar-0', $thumbnail );
$this->assertContains( $filename, $thumbnail );
$this->assertContains( 'src="' . wp_get_attachment_url( $attachment_id ) . '"', $thumbnail );
$this->assertStringContainsString( 'avatar-0', $thumbnail );
// Checking for dummy-attachment instead of dummy-attachment.png, as filename might change to
// dummy-attachment-1.png, dummy-attachment-2.png, etc. when running multiple tests.
$this->assertStringContainsString( 'dummy-attachment', $thumbnail );
$this->assertStringContainsString( wp_get_attachment_url( $attachment_id ), $thumbnail );
}

/**
Expand Down Expand Up @@ -394,7 +389,7 @@ public function test_handle_delete_guest_author_action_with_nonce() {
}

$this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
$this->assertStringContainsString( esc_html( $expected ), $exception->getMessage() );

// Checks when nonce is as expected.
$_POST['_wpnonce'] = wp_create_nonce( 'delete-guest-author' );
Expand Down Expand Up @@ -446,7 +441,7 @@ public function test_handle_delete_guest_author_action_with_list_users_capabilit
}

$this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
$this->assertStringContainsString( esc_html( $expected ), $exception->getMessage() );

// Checks when current user has list_users capability.
wp_set_current_user( $this->admin1->ID );
Expand Down Expand Up @@ -503,7 +498,7 @@ public function test_handle_delete_guest_author_action_with_guest_author_existen
}

$this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
$this->assertStringContainsString( esc_html( $expected ), $exception->getMessage() );

// Checks when guest author exists.
$_POST['id'] = $guest_author_obj->create_guest_author_from_user_id( $this->admin1->ID );
Expand Down Expand Up @@ -558,7 +553,7 @@ public function test_handle_delete_guest_author_action_with_reassign_not_as_expe
}

$this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
$this->assertStringContainsString( esc_html( $expected ), $exception->getMessage() );

// Restore current user from backup.
wp_set_current_user( $current_user );
Expand Down Expand Up @@ -599,9 +594,9 @@ public function test_handle_delete_guest_author_action_with_reassign_is_leave_as

} catch ( Exception $e ) {

$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
$this->assertStringContainsString( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertStringContainsString( 'page=view-guest-authors', $e->getMessage() );
$this->assertStringContainsString( 'message=guest-author-deleted', $e->getMessage() );
}

remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
Expand Down Expand Up @@ -649,7 +644,7 @@ public function test_handle_delete_guest_author_action_with_reassign_is_reassign
}

$this->assertInstanceOf( 'WPDieException', $exception );
$this->assertContains( esc_html( $expected ), $exception->getMessage() );
$this->assertStringContainsString( esc_html( $expected ), $exception->getMessage() );

// When coauthor exists.
$_POST['leave-assigned-to'] = $this->author1->user_nicename;
Expand All @@ -662,9 +657,9 @@ public function test_handle_delete_guest_author_action_with_reassign_is_reassign

} catch ( Exception $e ) {

// $this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
//$this->assertStringContainsString( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertStringContainsString( 'page=view-guest-authors', $e->getMessage() );
$this->assertStringContainsString( 'message=guest-author-deleted', $e->getMessage() );
}

remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
Expand Down Expand Up @@ -708,9 +703,9 @@ public function test_handle_delete_guest_author_action_with_reassign_is_remove_b

} catch ( Exception $e ) {

$this->assertContains( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertContains( 'page=view-guest-authors', $e->getMessage() );
$this->assertContains( 'message=guest-author-deleted', $e->getMessage() );
$this->assertStringContainsString( $guest_author_obj->parent_page, $e->getMessage() );
$this->assertStringContainsString( 'page=view-guest-authors', $e->getMessage() );
$this->assertStringContainsString( 'message=guest-author-deleted', $e->getMessage() );
}

remove_filter( 'wp_redirect', array( $this, 'catch_redirect_destination' ), 99 );
Expand Down