-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Global styles revisions: remove PHP unit tests that are running in Core #56492
Merged
ramonjd
merged 1 commit into
trunk
from
update/global-styles-revision-controller-prune-tests
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,26 +14,11 @@ class Gutenberg_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_RES | |
*/ | ||
protected static $admin_id; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected static $second_admin_id; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected static $author_id; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
protected static $global_styles_id; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $total_revisions; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
|
@@ -44,47 +29,17 @@ class Gutenberg_REST_Global_Styles_Revisions_Controller_Test extends WP_Test_RES | |
*/ | ||
private $revision_1_id; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $revision_2; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $revision_2_id; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $revision_3; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $revision_3_id; | ||
|
||
/** | ||
* Create fake data before our tests run. | ||
* | ||
* @param WP_UnitTest_Factory $factory Helper that lets us create fake data. | ||
*/ | ||
public static function wpSetupBeforeClass( $factory ) { | ||
self::$admin_id = $factory->user->create( | ||
array( | ||
'role' => 'administrator', | ||
) | ||
); | ||
self::$second_admin_id = $factory->user->create( | ||
self::$admin_id = $factory->user->create( | ||
array( | ||
'role' => 'administrator', | ||
) | ||
); | ||
self::$author_id = $factory->user->create( | ||
array( | ||
'role' => 'author', | ||
) | ||
); | ||
|
||
wp_set_current_user( self::$admin_id ); | ||
// This creates the global styles for the current theme. | ||
|
@@ -199,8 +154,6 @@ public static function wpSetupBeforeClass( $factory ) { | |
*/ | ||
public static function wpTearDownAfterClass() { | ||
self::delete_user( self::$admin_id ); | ||
self::delete_user( self::$second_admin_id ); | ||
self::delete_user( self::$author_id ); | ||
} | ||
|
||
/** | ||
|
@@ -209,24 +162,16 @@ public static function wpTearDownAfterClass() { | |
public function set_up() { | ||
parent::set_up(); | ||
switch_theme( 'emptytheme' ); | ||
$revisions = wp_get_post_revisions( self::$global_styles_id ); | ||
$this->total_revisions = count( $revisions ); | ||
|
||
$revisions = wp_get_post_revisions( self::$global_styles_id ); | ||
$this->revision_1 = array_pop( $revisions ); | ||
$this->revision_1_id = $this->revision_1->ID; | ||
|
||
$this->revision_2 = array_pop( $revisions ); | ||
$this->revision_2_id = $this->revision_2->ID; | ||
|
||
$this->revision_3 = array_pop( $revisions ); | ||
$this->revision_3_id = $this->revision_3->ID; | ||
|
||
/* | ||
* For some reason the `rest_api_init` doesn't run early enough to ensure an overwritten `get_item_schema()` | ||
* is used. So we manually call it here. | ||
* See: https://github.com/WordPress/gutenberg/pull/52370#issuecomment-1643331655. | ||
*/ | ||
$global_styles_revisions_controller = new Gutenberg_REST_Global_Styles_Revisions_Controller_6_4(); | ||
$global_styles_revisions_controller = new Gutenberg_REST_Global_Styles_Revisions_Controller_6_5(); | ||
$global_styles_revisions_controller->register_routes(); | ||
} | ||
|
||
|
@@ -237,11 +182,6 @@ public function set_up() { | |
*/ | ||
public function test_register_routes() { | ||
$routes = rest_get_server()->get_routes(); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/global-styles/(?P<parent>[\d]+)/revisions', | ||
$routes, | ||
'Global style revisions based on the given parentID route does not exist.' | ||
); | ||
$this->assertArrayHasKey( | ||
'/wp/v2/global-styles/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', | ||
$routes, | ||
|
@@ -277,32 +217,6 @@ protected function check_get_revision_response( $response_revision_item, $revisi | |
); | ||
} | ||
|
||
/** | ||
* @ticket 58524 | ||
* | ||
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller_6_4::get_items | ||
*/ | ||
public function test_get_items() { | ||
wp_set_current_user( self::$admin_id ); | ||
|
||
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$data = $response->get_data(); | ||
|
||
$this->assertSame( 200, $response->get_status(), 'Response status is 200.' ); | ||
$this->assertCount( $this->total_revisions, $data, 'Check that correct number of revisions exists.' ); | ||
|
||
// Reverse chronology. | ||
$this->assertSame( $this->revision_3_id, $data[0]['id'] ); | ||
$this->check_get_revision_response( $data[0], $this->revision_3 ); | ||
|
||
$this->assertSame( $this->revision_2_id, $data[1]['id'] ); | ||
$this->check_get_revision_response( $data[1], $this->revision_2 ); | ||
|
||
$this->assertSame( $this->revision_1_id, $data[2]['id'] ); | ||
$this->check_get_revision_response( $data[2], $this->revision_1 ); | ||
} | ||
|
||
/** | ||
* @ticket 59810 | ||
* | ||
|
@@ -336,26 +250,19 @@ public function test_get_item_invalid_revision_id_should_error() { | |
} | ||
|
||
/** | ||
* @ticket 58524 | ||
* | ||
* @covers Gutenberg_REST_Global_Styles_Revisions_Controller_6_4::get_item_schema | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function test_get_item_schema() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
$request = new WP_REST_Request( 'OPTIONS', '/wp/v2/global-styles/' . self::$global_styles_id . '/revisions' ); | ||
$response = rest_get_server()->dispatch( $request ); | ||
$data = $response->get_data(); | ||
$properties = $data['schema']['properties']; | ||
public function test_get_items() { | ||
// Unit tests have been more to WordPress Core for test_get_items(). | ||
// No unique compat unit tests exist. | ||
} | ||
|
||
$this->assertCount( 9, $properties, 'Schema properties array has exactly 9 elements.' ); | ||
$this->assertArrayHasKey( 'id', $properties, 'Schema properties array has "id" key.' ); | ||
$this->assertArrayHasKey( 'styles', $properties, 'Schema properties array has "styles" key.' ); | ||
$this->assertArrayHasKey( 'settings', $properties, 'Schema properties array has "settings" key.' ); | ||
$this->assertArrayHasKey( 'parent', $properties, 'Schema properties array has "parent" key.' ); | ||
$this->assertArrayHasKey( 'author', $properties, 'Schema properties array has "author" key.' ); | ||
$this->assertArrayHasKey( 'date', $properties, 'Schema properties array has "date" key.' ); | ||
$this->assertArrayHasKey( 'date_gmt', $properties, 'Schema properties array has "date_gmt" key.' ); | ||
$this->assertArrayHasKey( 'modified', $properties, 'Schema properties array has "modified" key.' ); | ||
$this->assertArrayHasKey( 'modified_gmt', $properties, 'Schema properties array has "modified_gmt" key.' ); | ||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
public function test_get_item_schema() { | ||
// Unit tests have been more to WordPress Core for test_get_item_schema(). | ||
// No unique compat unit tests exist. | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate Core test:
https://github.com/ramonjd/wordpress-develop/blob/trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php#L286