From e4740bbe123f61c85266d622121b70e651a45640 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 14 Apr 2020 19:24:05 +0200 Subject: [PATCH 01/38] REST API: Themes: Expose some additional basic field --- .../class-wp-rest-themes-controller.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 14478786cf88d..e4bd8c1b77e2d 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,6 +115,13 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); + $simple_fields = array( 'name', 'stylesheet', 'template' ); + $simple_fields_to_include = array_intersect( $simple_fields, $fields ); + + foreach ( $simple_fields_to_include as $field_name ) { + $data[ $field_name ] = $theme->$field_name; + } + if ( in_array( 'theme_supports', $fields, true ) ) { $item_schemas = $this->get_item_schema(); $theme_supports = $item_schemas['properties']['theme_supports']['properties']; @@ -192,6 +199,21 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( + 'name' => array( + 'description' => __( 'The theme\'s name.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'stylesheet' => array( + 'description' => __( 'The theme\'s stylesheet.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'template' => array( + 'description' => __( 'The theme\'s template name.' ), + 'type' => 'string', + 'readonly' => true, + ), 'theme_supports' => array( 'description' => __( 'Features supported by this theme.' ), 'type' => 'object', From 61b89e93c3c738323b45d19c4137709bf708a027 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 15 Apr 2020 19:16:15 +0200 Subject: [PATCH 02/38] phpcbf --- .../endpoints/class-wp-rest-themes-controller.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index e4bd8c1b77e2d..ac51e9bd4986e 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,7 +115,7 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); - $simple_fields = array( 'name', 'stylesheet', 'template' ); + $simple_fields = array( 'name', 'stylesheet', 'template' ); $simple_fields_to_include = array_intersect( $simple_fields, $fields ); foreach ( $simple_fields_to_include as $field_name ) { @@ -199,17 +199,17 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( - 'name' => array( + 'name' => array( 'description' => __( 'The theme\'s name.' ), 'type' => 'string', 'readonly' => true, ), - 'stylesheet' => array( + 'stylesheet' => array( 'description' => __( 'The theme\'s stylesheet.' ), 'type' => 'string', 'readonly' => true, ), - 'template' => array( + 'template' => array( 'description' => __( 'The theme\'s template name.' ), 'type' => 'string', 'readonly' => true, From e3a03decc465b53acf3fcc21a66710acfff93f9a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 15 Apr 2020 20:09:10 +0200 Subject: [PATCH 03/38] Fix unit tests --- tests/phpunit/tests/rest-api/rest-themes-controller.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 0da8553ad9bb2..84355c68f2846 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -150,6 +150,9 @@ public function test_get_items() { $this->check_get_theme_response( $response ); $fields = array( + 'name', + 'stylesheet', + 'template', 'theme_supports', ); $this->assertEqualSets( $fields, array_keys( $data[0] ) ); @@ -207,7 +210,10 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 1, count( $properties ) ); + $this->assertEquals( 4, count( $properties ) ); + $this->assertArrayHasKey( 'name', $properties ); + $this->assertArrayHasKey( 'stylesheet', $properties ); + $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); $theme_supports = $properties['theme_supports']['properties']; $this->assertEquals( 20, count( $theme_supports ) ); From 4378fd9b89f5eb45386697985204e7effdb7b2e2 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 00:07:21 +0200 Subject: [PATCH 04/38] Blindly try adding a unit test for the new stylesheet field --- .../tests/rest-api/rest-themes-controller.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 84355c68f2846..18775d626839c 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -239,6 +239,15 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); } + public function test_theme_stylesheet() { + add_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'stylesheet', $result[0] ); + $this->assertSame( $this->return_stylesheet(), $result[0]['stylesheet'] ); + remove_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); + } + /** * @ticket 49037 */ @@ -859,6 +868,13 @@ public function additional_field_get_callback( $theme ) { return 2; } + /** + * Return a value for the current theme's stylesheet. + */ + public function return_stylesheet() { + return 'twentytesting'; + } + /** * The create_item() method does not exist for themes. */ From eb662ca3d7b33fc1ea06d0958155dd1654c45e4f Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 13:47:45 +0200 Subject: [PATCH 05/38] Blindly add unit test for template field --- .../tests/rest-api/rest-themes-controller.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 18775d626839c..7b53dec2705f6 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -248,6 +248,15 @@ public function test_theme_stylesheet() { remove_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); } + public function test_theme_template() { + add_filter( 'template', array( $this, 'return_template' ) ); + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'template', $result[0] ); + $this->assertSame( $this->return_template(), $result[0]['template'] ); + remove_filter( 'template', array( $this, 'return_template' ) ); + } + /** * @ticket 49037 */ @@ -872,6 +881,13 @@ public function additional_field_get_callback( $theme ) { * Return a value for the current theme's stylesheet. */ public function return_stylesheet() { + return 'twentytestingchild'; + } + + /** + * Return a value for the current theme's template. + */ + public function return_template() { return 'twentytesting'; } From dcf4047b7544bef668971ad86010130d5cb04858 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 14:33:34 +0200 Subject: [PATCH 06/38] Fix template unit test --- .../tests/rest-api/rest-themes-controller.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 7b53dec2705f6..b7aec382518cd 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -249,12 +249,14 @@ public function test_theme_stylesheet() { } public function test_theme_template() { - add_filter( 'template', array( $this, 'return_template' ) ); + add_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); + add_filter( 'template', array( $this, 'return_stylesheet' ) ); // Both need to be filtered to work for template. $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'template', $result[0] ); - $this->assertSame( $this->return_template(), $result[0]['template'] ); - remove_filter( 'template', array( $this, 'return_template' ) ); + $this->assertSame( $this->return_stylesheet(), $result[0]['template'] ); + add_filter( 'template', array( $this, 'return_stylesheet' ) ); + remove_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); } /** @@ -884,13 +886,6 @@ public function return_stylesheet() { return 'twentytestingchild'; } - /** - * Return a value for the current theme's template. - */ - public function return_template() { - return 'twentytesting'; - } - /** * The create_item() method does not exist for themes. */ From db0378b750809d609513da1a4d2ca59e5ba6b476 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 18:29:12 +0200 Subject: [PATCH 07/38] Add a few more fields --- .../class-wp-rest-themes-controller.php | 35 +++++++++++++++++-- .../tests/rest-api/rest-themes-controller.php | 11 +++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index ac51e9bd4986e..34d3388b9d6bb 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,13 +115,24 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); - $simple_fields = array( 'name', 'stylesheet', 'template' ); + $simple_fields = array( + 'author', + 'description', + 'name', + //'screenshot', // Needs different treatment to get absolute URL. + 'stylesheet', + 'template', + 'version', + ); $simple_fields_to_include = array_intersect( $simple_fields, $fields ); foreach ( $simple_fields_to_include as $field_name ) { $data[ $field_name ] = $theme->$field_name; } + // Using $theme->get_screenshot() with no args to get absolute URL. + $data['screenshot'] = $theme->get_screenshot(); + if ( in_array( 'theme_supports', $fields, true ) ) { $item_schemas = $this->get_item_schema(); $theme_supports = $item_schemas['properties']['theme_supports']['properties']; @@ -199,8 +210,23 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( + 'author' => array( + 'description' => __( 'The author of the theme.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'description' => array( + 'description' => __( 'A description of the theme.' ), + 'type' => 'string', + 'readonly' => true, + ), 'name' => array( - 'description' => __( 'The theme\'s name.' ), + 'description' => __( 'The name of the theme.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'screenshot' => array( + 'description' => __( 'A theme screenshot URL.' ), 'type' => 'string', 'readonly' => true, ), @@ -480,6 +506,11 @@ public function get_item_schema() { ), ), ), + 'version' => array( + 'description' => __( 'The theme\'s current version.' ), + 'type' => 'string', + 'readonly' => true, + ), ), ); diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index b7aec382518cd..5f222de5502b4 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -150,10 +150,14 @@ public function test_get_items() { $this->check_get_theme_response( $response ); $fields = array( + 'author', + 'description', 'name', + 'screenshot', 'stylesheet', 'template', 'theme_supports', + 'version', ); $this->assertEqualSets( $fields, array_keys( $data[0] ) ); } @@ -210,11 +214,16 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 4, count( $properties ) ); + $this->assertEquals( 8, count( $properties ) ); + $this->assertArrayHasKey( 'author', $properties ); + $this->assertArrayHasKey( 'description', $properties ); $this->assertArrayHasKey( 'name', $properties ); + $this->assertArrayHasKey( 'screenshot', $properties ); $this->assertArrayHasKey( 'stylesheet', $properties ); $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); + $this->assertArrayHasKey( 'version', $properties ); + $theme_supports = $properties['theme_supports']['properties']; $this->assertEquals( 20, count( $theme_supports ) ); $this->assertArrayHasKey( 'align-wide', $theme_supports ); From d45471edde509124eb0d3b32f1a67c4a4132bd0b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 18:31:23 +0200 Subject: [PATCH 08/38] Add conditional for screenshot --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 34d3388b9d6bb..a9dbb0c49861d 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -130,8 +130,10 @@ public function prepare_item_for_response( $theme, $request ) { $data[ $field_name ] = $theme->$field_name; } - // Using $theme->get_screenshot() with no args to get absolute URL. - $data['screenshot'] = $theme->get_screenshot(); + if ( in_array( 'screenshot', $fields, true ) ) { + // Using $theme->get_screenshot() with no args to get absolute URL. + $data['screenshot'] = $theme->get_screenshot(); + } if ( in_array( 'theme_supports', $fields, true ) ) { $item_schemas = $this->get_item_schema(); From dfdb0b23d28350429b34cda465495be058442d3d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 18:42:41 +0200 Subject: [PATCH 09/38] Use default theme for testing --- .../tests/rest-api/rest-themes-controller.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 5f222de5502b4..b98033e51f988 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -249,23 +249,17 @@ public function test_get_item_schema() { } public function test_theme_stylesheet() { - add_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'stylesheet', $result[0] ); - $this->assertSame( $this->return_stylesheet(), $result[0]['stylesheet'] ); - remove_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); + $this->assertSame( 'default', $result[0]['stylesheet'] ); } public function test_theme_template() { - add_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); - add_filter( 'template', array( $this, 'return_stylesheet' ) ); // Both need to be filtered to work for template. $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'template', $result[0] ); - $this->assertSame( $this->return_stylesheet(), $result[0]['template'] ); - add_filter( 'template', array( $this, 'return_stylesheet' ) ); - remove_filter( 'stylesheet', array( $this, 'return_stylesheet' ) ); + $this->assertSame( 'default', $result[0]['template'] ); } /** @@ -888,13 +882,6 @@ public function additional_field_get_callback( $theme ) { return 2; } - /** - * Return a value for the current theme's stylesheet. - */ - public function return_stylesheet() { - return 'twentytestingchild'; - } - /** * The create_item() method does not exist for themes. */ From d9dfddd2b532a6bd82c7449773dd4ad45df44ba9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 19:35:58 +0200 Subject: [PATCH 10/38] More flexible implementation --- .../class-wp-rest-themes-controller.php | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index a9dbb0c49861d..00bc8d2cce6d5 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,19 +115,18 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); - $simple_fields = array( - 'author', - 'description', - 'name', - //'screenshot', // Needs different treatment to get absolute URL. - 'stylesheet', - 'template', - 'version', + $field_mappings = array( + 'author' => 'Author Name', + 'description' => 'Description', + 'name' => 'Name', + 'stylesheet' => 'Stylesheet', + 'template' => 'Template', + 'version' => 'Version', ); - $simple_fields_to_include = array_intersect( $simple_fields, $fields ); + $fields_to_include = array_intersect( array_keys( $field_mappings ), $fields ); - foreach ( $simple_fields_to_include as $field_name ) { - $data[ $field_name ] = $theme->$field_name; + foreach ( $fields_to_include as $field ) { + $data[ $field ] = $theme[ $field_mappings[ $field ] ]; } if ( in_array( 'screenshot', $fields, true ) ) { From 1acdfb72d0ab994927fa8932c32c38bf2452a089 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 19:45:22 +0200 Subject: [PATCH 11/38] Add more unit tests, change author to author_name --- .../class-wp-rest-themes-controller.php | 6 +-- .../tests/rest-api/rest-themes-controller.php | 42 ++++++++++++++++++- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 00bc8d2cce6d5..5cbd4773502ac 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -116,7 +116,7 @@ public function prepare_item_for_response( $theme, $request ) { $fields = $this->get_fields_for_response( $request ); $field_mappings = array( - 'author' => 'Author Name', + 'author_name' => 'Author Name', 'description' => 'Description', 'name' => 'Name', 'stylesheet' => 'Stylesheet', @@ -211,8 +211,8 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( - 'author' => array( - 'description' => __( 'The author of the theme.' ), + 'author_name' => array( + 'description' => __( 'The theme author\'s name.' ), 'type' => 'string', 'readonly' => true, ), diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index b98033e51f988..9124bd78b99ec 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -150,7 +150,7 @@ public function test_get_items() { $this->check_get_theme_response( $response ); $fields = array( - 'author', + 'author_name', 'description', 'name', 'screenshot', @@ -215,7 +215,7 @@ public function test_get_item_schema() { $data = $response->get_data(); $properties = $data['schema']['properties']; $this->assertEquals( 8, count( $properties ) ); - $this->assertArrayHasKey( 'author', $properties ); + $this->assertArrayHasKey( 'author_name', $properties ); $this->assertArrayHasKey( 'description', $properties ); $this->assertArrayHasKey( 'name', $properties ); $this->assertArrayHasKey( 'screenshot', $properties ); @@ -248,6 +248,37 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); } + public function test_theme_author_name() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'author_name', $result[0] ); + $this->assertSame( 'Michael Heilemann', $result[0]['author_name'] ); + } + + public function test_theme_description() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'description', $result[0] ); + $this->assertSame( + 'The default WordPress theme based on the famous Kubrick.', + $result[0]['description'] + ); + } + + public function test_theme_name() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'name', $result[0] ); + $this->assertSame( 'WordPress Default', $result[0]['name'] ); + } + + public function test_theme_screenshot() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'screenshot', $result[0] ); + $this->assertFalse( $result[0]['screenshot'] ); // No screenshot for default theme + } + public function test_theme_stylesheet() { $response = self::perform_active_theme_request(); $result = $response->get_data(); @@ -262,6 +293,13 @@ public function test_theme_template() { $this->assertSame( 'default', $result[0]['template'] ); } + public function test_theme_version() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'version', $result[0] ); + $this->assertSame( '1.6', $result[0]['version'] ); + } + /** * @ticket 49037 */ From f80dbdd1cf95bdc34cee59ff58a954402c30e0ad Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 16 Apr 2020 20:58:14 +0200 Subject: [PATCH 12/38] Add author, author_uri, and theme_uri fields --- .../class-wp-rest-themes-controller.php | 18 +++++++++++ .../tests/rest-api/rest-themes-controller.php | 32 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 5cbd4773502ac..735634808d9f1 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -116,11 +116,14 @@ public function prepare_item_for_response( $theme, $request ) { $fields = $this->get_fields_for_response( $request ); $field_mappings = array( + 'author' => 'Author', 'author_name' => 'Author Name', + 'author_uri' => 'Author URI', 'description' => 'Description', 'name' => 'Name', 'stylesheet' => 'Stylesheet', 'template' => 'Template', + 'theme_uri' => 'Theme URI', 'version' => 'Version', ); $fields_to_include = array_intersect( array_keys( $field_mappings ), $fields ); @@ -211,11 +214,21 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( + 'author' => array( + 'description' => __( 'The theme author.' ), + 'type' => 'string', + 'readonly' => true, + ), 'author_name' => array( 'description' => __( 'The theme author\'s name.' ), 'type' => 'string', 'readonly' => true, ), + 'author_uri' => array( + 'description' => __( 'The website of the theme author.' ), + 'type' => 'string', + 'readonly' => true, + ), 'description' => array( 'description' => __( 'A description of the theme.' ), 'type' => 'string', @@ -507,6 +520,11 @@ public function get_item_schema() { ), ), ), + 'theme_uri' => array( + 'description' => __( 'The URI of the theme\'s webpage.' ), + 'type' => 'string', + 'readonly' => true, + ), 'version' => array( 'description' => __( 'The theme\'s current version.' ), 'type' => 'string', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 9124bd78b99ec..f1ef4c476980f 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -150,13 +150,16 @@ public function test_get_items() { $this->check_get_theme_response( $response ); $fields = array( + 'author', 'author_name', + 'author_uri', 'description', 'name', 'screenshot', 'stylesheet', 'template', 'theme_supports', + 'theme_uri', 'version', ); $this->assertEqualSets( $fields, array_keys( $data[0] ) ); @@ -214,14 +217,17 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 8, count( $properties ) ); + $this->assertEquals( 11, count( $properties ) ); + $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'author_name', $properties ); + $this->assertArrayHasKey( 'author_uri', $properties ); $this->assertArrayHasKey( 'description', $properties ); $this->assertArrayHasKey( 'name', $properties ); $this->assertArrayHasKey( 'screenshot', $properties ); $this->assertArrayHasKey( 'stylesheet', $properties ); $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); + $this->assertArrayHasKey( 'theme_uri', $properties ); $this->assertArrayHasKey( 'version', $properties ); $theme_supports = $properties['theme_supports']['properties']; @@ -248,6 +254,16 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); } + public function test_theme_author() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'author', $result[0] ); + $this->assertSame( + 'Michael Heilemann', + $result[0]['author'] + ); + } + public function test_theme_author_name() { $response = self::perform_active_theme_request(); $result = $response->get_data(); @@ -255,6 +271,13 @@ public function test_theme_author_name() { $this->assertSame( 'Michael Heilemann', $result[0]['author_name'] ); } + public function test_theme_author_uri() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'author_uri', $result[0] ); + $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri'] ); + } + public function test_theme_description() { $response = self::perform_active_theme_request(); $result = $response->get_data(); @@ -293,6 +316,13 @@ public function test_theme_template() { $this->assertSame( 'default', $result[0]['template'] ); } + public function test_theme_theme_uri() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'theme_uri', $result[0] ); + $this->assertNull( $result[0]['theme_uri'] ); // Theme URI is null for default theme. + } + public function test_theme_version() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From 9b9bace07e3798930406aa48d29be99984f86999 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 21:56:49 +0200 Subject: [PATCH 13/38] Have screenshot fall back to empty string --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- tests/phpunit/tests/rest-api/rest-themes-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 735634808d9f1..b6c4f6162dcea 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -134,7 +134,7 @@ public function prepare_item_for_response( $theme, $request ) { if ( in_array( 'screenshot', $fields, true ) ) { // Using $theme->get_screenshot() with no args to get absolute URL. - $data['screenshot'] = $theme->get_screenshot(); + $data['screenshot'] = $theme->get_screenshot() ?: ''; } if ( in_array( 'theme_supports', $fields, true ) ) { diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index f1ef4c476980f..7538f1f02e8ff 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -299,7 +299,7 @@ public function test_theme_screenshot() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'screenshot', $result[0] ); - $this->assertFalse( $result[0]['screenshot'] ); // No screenshot for default theme + $this->assertSame( '', $result[0]['screenshot'] ); // No screenshot for default theme } public function test_theme_stylesheet() { From 9282f21fe74989b06b5b3d359d281ea595c082e7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 22:00:09 +0200 Subject: [PATCH 14/38] Add format: 'uri' to author_uri and theme_uri --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index b6c4f6162dcea..bc1f9f1bcf52f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -226,6 +226,7 @@ public function get_item_schema() { ), 'author_uri' => array( 'description' => __( 'The website of the theme author.' ), + 'format' => 'uri', 'type' => 'string', 'readonly' => true, ), @@ -524,6 +525,7 @@ public function get_item_schema() { 'description' => __( 'The URI of the theme\'s webpage.' ), 'type' => 'string', 'readonly' => true, + 'format' => 'uri', ), 'version' => array( 'description' => __( 'The theme\'s current version.' ), From 09e285b9a57743abfaa82796eeca38526257e318 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 22:13:42 +0200 Subject: [PATCH 15/38] raw/rendered --- tests/phpunit/tests/rest-api/rest-themes-controller.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 7538f1f02e8ff..d7bf6b6019858 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -219,7 +219,9 @@ public function test_get_item_schema() { $properties = $data['schema']['properties']; $this->assertEquals( 11, count( $properties ) ); $this->assertArrayHasKey( 'author', $properties ); - $this->assertArrayHasKey( 'author_name', $properties ); + $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['author']['properties'] ); + $this->assertArrayHasKey( 'author_uri', $properties ); $this->assertArrayHasKey( 'description', $properties ); $this->assertArrayHasKey( 'name', $properties ); @@ -258,9 +260,10 @@ public function test_theme_author() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'author', $result[0] ); + $this->assertSame( 'Michael Heilemann', $result[0]['author']['raw'] ); $this->assertSame( 'Michael Heilemann', - $result[0]['author'] + $result[0]['author']['rendered'] ); } From 364f9758447eeb28dcb3c5d169dbbaaec232bac9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 22:56:22 +0200 Subject: [PATCH 16/38] Drop author_name, user raw/rendered for author --- .../class-wp-rest-themes-controller.php | 26 ++++++++++++++----- .../tests/rest-api/rest-themes-controller.php | 10 +------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index bc1f9f1bcf52f..46f33bbf646a3 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -116,8 +116,6 @@ public function prepare_item_for_response( $theme, $request ) { $fields = $this->get_fields_for_response( $request ); $field_mappings = array( - 'author' => 'Author', - 'author_name' => 'Author Name', 'author_uri' => 'Author URI', 'description' => 'Description', 'name' => 'Name', @@ -132,6 +130,13 @@ public function prepare_item_for_response( $theme, $request ) { $data[ $field ] = $theme[ $field_mappings[ $field ] ]; } + if ( in_array( 'author', $fields, true ) ) { + $data['author'] = array( + 'raw' => $theme->display( 'Author', false, true ), + 'rendered' => $theme->display( 'Author' ), + ); + } + if ( in_array( 'screenshot', $fields, true ) ) { // Using $theme->get_screenshot() with no args to get absolute URL. $data['screenshot'] = $theme->get_screenshot() ?: ''; @@ -218,11 +223,18 @@ public function get_item_schema() { 'description' => __( 'The theme author.' ), 'type' => 'string', 'readonly' => true, - ), - 'author_name' => array( - 'description' => __( 'The theme author\'s name.' ), - 'type' => 'string', - 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( 'The theme author\'s name.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'HTML for the theme author, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), ), 'author_uri' => array( 'description' => __( 'The website of the theme author.' ), diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index d7bf6b6019858..6650bf1d3f451 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -151,7 +151,6 @@ public function test_get_items() { $this->check_get_theme_response( $response ); $fields = array( 'author', - 'author_name', 'author_uri', 'description', 'name', @@ -217,7 +216,7 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 11, count( $properties ) ); + $this->assertEquals( 10, count( $properties ) ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); $this->assertArrayHasKey( 'rendered', $properties['author']['properties'] ); @@ -267,13 +266,6 @@ public function test_theme_author() { ); } - public function test_theme_author_name() { - $response = self::perform_active_theme_request(); - $result = $response->get_data(); - $this->assertArrayHasKey( 'author_name', $result[0] ); - $this->assertSame( 'Michael Heilemann', $result[0]['author_name'] ); - } - public function test_theme_author_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From f7245710de68fef1e860071dab1b6a3c3aab08d0 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 23:00:36 +0200 Subject: [PATCH 17/38] Moar consistent --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 46f33bbf646a3..0539d94ed4f90 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -132,8 +132,8 @@ public function prepare_item_for_response( $theme, $request ) { if ( in_array( 'author', $fields, true ) ) { $data['author'] = array( - 'raw' => $theme->display( 'Author', false, true ), - 'rendered' => $theme->display( 'Author' ), + 'raw' => $theme['Author Name'], + 'rendered' => $theme['Author'], ); } From 8b16987e581696a1092c1a992d050b9dd53c11cf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 27 Apr 2020 23:45:10 +0200 Subject: [PATCH 18/38] Use ->display for all teh things --- .../class-wp-rest-themes-controller.php | 91 +++++++++++++++---- .../tests/rest-api/rest-themes-controller.php | 30 +++++- 2 files changed, 98 insertions(+), 23 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 0539d94ed4f90..0b52424317405 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,26 +115,16 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); - $field_mappings = array( - 'author_uri' => 'Author URI', - 'description' => 'Description', - 'name' => 'Name', - 'stylesheet' => 'Stylesheet', - 'template' => 'Template', - 'theme_uri' => 'Theme URI', - 'version' => 'Version', + $plain_field_mappings = array( + 'stylesheet' => 'Stylesheet', + 'template' => 'Template', + 'version' => 'Version', ); - $fields_to_include = array_intersect( array_keys( $field_mappings ), $fields ); - foreach ( $fields_to_include as $field ) { - $data[ $field ] = $theme[ $field_mappings[ $field ] ]; - } + $plain_fields_to_include = array_intersect( array_keys( $plain_field_mappings ), $fields ); - if ( in_array( 'author', $fields, true ) ) { - $data['author'] = array( - 'raw' => $theme['Author Name'], - 'rendered' => $theme['Author'], - ); + foreach ( $plain_fields_to_include as $field ) { + $data[ $field ] = $theme[ $plain_field_mappings[ $field ] ]; } if ( in_array( 'screenshot', $fields, true ) ) { @@ -142,6 +132,23 @@ public function prepare_item_for_response( $theme, $request ) { $data['screenshot'] = $theme->get_screenshot() ?: ''; } + $rich_field_mappings = array( + 'author' => 'Author', + 'author_uri' => 'AuthorURI', + 'description' => 'Description', + 'name' => 'Name', + 'theme_uri' => 'ThemeURI', + ); + + $rich_fields_to_include = array_intersect( array_keys( $rich_field_mappings ), $fields ); + + foreach ( $rich_fields_to_include as $field ) { + $data[ $field ] = array( + 'raw' => $theme->display( $rich_field_mappings[ $field ], false, true ), + 'rendered' => $theme->display( $rich_field_mappings[ $field ] ), + ); + } + if ( in_array( 'theme_supports', $fields, true ) ) { $item_schemas = $this->get_item_schema(); $theme_supports = $item_schemas['properties']['theme_supports']['properties']; @@ -225,7 +232,7 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'The theme author\'s name.' ), + 'description' => __( 'The theme author\'s name, as it exists in the database.' ), 'type' => 'string', 'readonly' => true, ), @@ -241,16 +248,52 @@ public function get_item_schema() { 'format' => 'uri', 'type' => 'string', 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( 'The website of the theme author, as it exists in the database.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'The website of the theme author, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), ), 'description' => array( 'description' => __( 'A description of the theme.' ), 'type' => 'string', 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( 'The theme description, as it exists in the database.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'The theme description, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), ), 'name' => array( 'description' => __( 'The name of the theme.' ), 'type' => 'string', 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( 'The theme name, as it exists in the database.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'The theme name, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), ), 'screenshot' => array( 'description' => __( 'A theme screenshot URL.' ), @@ -538,6 +581,18 @@ public function get_item_schema() { 'type' => 'string', 'readonly' => true, 'format' => 'uri', + 'properties' => array( + 'raw' => array( + 'description' => __( 'The URI of the theme\'s webpage, as it exists in the database.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'The URI of the theme\'s webpage, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), ), 'version' => array( 'description' => __( 'The theme\'s current version.' ), diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 6650bf1d3f451..5b35904276f0f 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -217,18 +217,32 @@ public function test_get_item_schema() { $data = $response->get_data(); $properties = $data['schema']['properties']; $this->assertEquals( 10, count( $properties ) ); + $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); $this->assertArrayHasKey( 'rendered', $properties['author']['properties'] ); $this->assertArrayHasKey( 'author_uri', $properties ); + $this->assertArrayHasKey( 'raw', $properties['author_uri']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['author_uri']['properties'] ); + $this->assertArrayHasKey( 'description', $properties ); + $this->assertArrayHasKey( 'raw', $properties['description']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['description']['properties'] ); + $this->assertArrayHasKey( 'name', $properties ); + $this->assertArrayHasKey( 'raw', $properties['name']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['name']['properties'] ); + $this->assertArrayHasKey( 'screenshot', $properties ); $this->assertArrayHasKey( 'stylesheet', $properties ); $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); + $this->assertArrayHasKey( 'theme_uri', $properties ); + $this->assertArrayHasKey( 'raw', $properties['theme_uri']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['theme_uri']['properties'] ); + $this->assertArrayHasKey( 'version', $properties ); $theme_supports = $properties['theme_supports']['properties']; @@ -270,7 +284,8 @@ public function test_theme_author_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'author_uri', $result[0] ); - $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri'] ); + $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri']['raw'] ); + $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri']['rendered'] ); } public function test_theme_description() { @@ -279,7 +294,11 @@ public function test_theme_description() { $this->assertArrayHasKey( 'description', $result[0] ); $this->assertSame( 'The default WordPress theme based on the famous Kubrick.', - $result[0]['description'] + $result[0]['description']['raw'] + ); + $this->assertSame( + 'The default WordPress theme based on the famous Kubrick.', + $result[0]['description']['rendered'] ); } @@ -287,7 +306,8 @@ public function test_theme_name() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'name', $result[0] ); - $this->assertSame( 'WordPress Default', $result[0]['name'] ); + $this->assertSame( 'WordPress Default', $result[0]['name']['raw'] ); + $this->assertSame( 'WordPress Default', $result[0]['name']['rendered'] ); } public function test_theme_screenshot() { @@ -315,8 +335,8 @@ public function test_theme_theme_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'theme_uri', $result[0] ); - $this->assertNull( $result[0]['theme_uri'] ); // Theme URI is null for default theme. - } + $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['raw'] ); + $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['rendered'] ); } public function test_theme_version() { $response = self::perform_active_theme_request(); From 2e3a4877851fa7e2b50cb3635413301dfcd0d745 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Tue, 28 Apr 2020 12:06:39 +0200 Subject: [PATCH 19/38] Change wording to 'as found in the theme header' --- .../endpoints/class-wp-rest-themes-controller.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 0b52424317405..a926b4cc280ce 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -232,7 +232,7 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'The theme author\'s name, as it exists in the database.' ), + 'description' => __( 'The theme author\'s name, as found in the theme header.' ), 'type' => 'string', 'readonly' => true, ), @@ -250,7 +250,7 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'The website of the theme author, as it exists in the database.' ), + 'description' => __( 'The website of the theme author, as found in the theme header.' ), 'type' => 'string', 'readonly' => true, ), @@ -267,7 +267,7 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'The theme description, as it exists in the database.' ), + 'description' => __( 'The theme description, as found in the theme header.' ), 'type' => 'string', 'readonly' => true, ), @@ -284,7 +284,7 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'The theme name, as it exists in the database.' ), + 'description' => __( 'The theme name, as found in the theme header.' ), 'type' => 'string', 'readonly' => true, ), @@ -583,7 +583,7 @@ public function get_item_schema() { 'format' => 'uri', 'properties' => array( 'raw' => array( - 'description' => __( 'The URI of the theme\'s webpage, as it exists in the database.' ), + 'description' => __( 'The URI of the theme\'s webpage, as found in the theme header.' ), 'type' => 'string', 'readonly' => true, ), From d9174744e78789a872db07ac2c253c7321c5ea13 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:44:43 +0200 Subject: [PATCH 20/38] Change `type` to `object` for `author_uri` Co-authored-by: Jonny Harris --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index a926b4cc280ce..a1b9e8db02a06 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -246,7 +246,7 @@ public function get_item_schema() { 'author_uri' => array( 'description' => __( 'The website of the theme author.' ), 'format' => 'uri', - 'type' => 'string', + 'type' => 'object', 'readonly' => true, 'properties' => array( 'raw' => array( From 375d25b385f57058b74c5038c3624f2be851e177 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:46:16 +0200 Subject: [PATCH 21/38] Change `type` to `object` for `description` Co-authored-by: Jonny Harris --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index a1b9e8db02a06..772fec5737800 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -263,7 +263,7 @@ public function get_item_schema() { ), 'description' => array( 'description' => __( 'A description of the theme.' ), - 'type' => 'string', + 'type' => 'object', 'readonly' => true, 'properties' => array( 'raw' => array( From 505d96d471cd6265fddbf47b024b4891a540dcdf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:46:49 +0200 Subject: [PATCH 22/38] Change `type` to `object` for `name` Co-authored-by: Jonny Harris --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 772fec5737800..35910b0eb9d39 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -280,7 +280,7 @@ public function get_item_schema() { ), 'name' => array( 'description' => __( 'The name of the theme.' ), - 'type' => 'string', + 'type' => 'object', 'readonly' => true, 'properties' => array( 'raw' => array( From 1e3d010122b187cdc3c02b311979c5bce8e5a6d3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:47:31 +0200 Subject: [PATCH 23/38] Change `type` to `object` for `author` Co-authored-by: Jonny Harris --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 35910b0eb9d39..ced5df5d13395 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -228,7 +228,7 @@ public function get_item_schema() { 'properties' => array( 'author' => array( 'description' => __( 'The theme author.' ), - 'type' => 'string', + 'type' => 'object', 'readonly' => true, 'properties' => array( 'raw' => array( From a0c31d63c8e32ab8fa0ecb6cf39ff028e9955776 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:48:02 +0200 Subject: [PATCH 24/38] Change `type` to `object` for `theme_uri` Co-authored-by: Jonny Harris --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index ced5df5d13395..77aff880d5a45 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -578,7 +578,7 @@ public function get_item_schema() { ), 'theme_uri' => array( 'description' => __( 'The URI of the theme\'s webpage.' ), - 'type' => 'string', + 'type' => 'object', 'readonly' => true, 'format' => 'uri', 'properties' => array( From 769a614dfe0b4c6bf5a9c3b54b0a521d61707946 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:50:45 +0200 Subject: [PATCH 25/38] Change `type` to `uri` for `raw` `author_uri` and `theme_uri` --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 77aff880d5a45..c2cbfd486449f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -251,7 +251,7 @@ public function get_item_schema() { 'properties' => array( 'raw' => array( 'description' => __( 'The website of the theme author, as found in the theme header.' ), - 'type' => 'string', + 'type' => 'uri', 'readonly' => true, ), 'rendered' => array( @@ -584,7 +584,7 @@ public function get_item_schema() { 'properties' => array( 'raw' => array( 'description' => __( 'The URI of the theme\'s webpage, as found in the theme header.' ), - 'type' => 'string', + 'type' => 'uri', 'readonly' => true, ), 'rendered' => array( From 6c0bcfd4b7de4d5a399734df4e79c61973bb2de7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 18 May 2020 13:52:57 +0200 Subject: [PATCH 26/38] Change `type` to `uri` for `rendered` `author_uri` and `theme_uri` --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index c2cbfd486449f..0efb15623e88f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -256,7 +256,7 @@ public function get_item_schema() { ), 'rendered' => array( 'description' => __( 'The website of the theme author, transformed for display.' ), - 'type' => 'string', + 'type' => 'uri', 'readonly' => true, ), ), @@ -589,7 +589,7 @@ public function get_item_schema() { ), 'rendered' => array( 'description' => __( 'The URI of the theme\'s webpage, transformed for display.' ), - 'type' => 'string', + 'type' => 'uri', 'readonly' => true, ), ), From 34a179c46126f2a21a05b2b43ffdadd7173f3b6b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 00:20:04 +0200 Subject: [PATCH 27/38] Add tags --- .../class-wp-rest-themes-controller.php | 18 ++++++++++++++++++ .../tests/rest-api/rest-themes-controller.php | 16 +++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 0efb15623e88f..c90a1a86f4c7b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -137,6 +137,7 @@ public function prepare_item_for_response( $theme, $request ) { 'author_uri' => 'AuthorURI', 'description' => 'Description', 'name' => 'Name', + 'tags' => 'Tags', 'theme_uri' => 'ThemeURI', ); @@ -305,6 +306,23 @@ public function get_item_schema() { 'type' => 'string', 'readonly' => true, ), + 'tags' => array( + 'description' => __( 'Tags indicating styles and features of the theme.' ), + 'type' => 'object', + 'readonly' => true, + 'properties' => array( + 'raw' => array( + 'description' => __( 'Theme tags, as found in the theme header.' ), + 'type' => 'array', + 'readonly' => true, + ), + 'rendered' => array( + 'description' => __( 'Theme tags, transformed for display.' ), + 'type' => 'string', + 'readonly' => true, + ), + ), + ), 'template' => array( 'description' => __( 'The theme\'s template name.' ), 'type' => 'string', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 5b35904276f0f..abe0c02a6f4f7 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -156,6 +156,7 @@ public function test_get_items() { 'name', 'screenshot', 'stylesheet', + 'tags', 'template', 'theme_supports', 'theme_uri', @@ -216,7 +217,7 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 10, count( $properties ) ); + $this->assertEquals( 11, count( $properties ) ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); @@ -236,6 +237,11 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'screenshot', $properties ); $this->assertArrayHasKey( 'stylesheet', $properties ); + + $this->assertArrayHasKey( 'tags', $properties ); + $this->assertArrayHasKey( 'raw', $properties['tags']['properties'] ); + $this->assertArrayHasKey( 'rendered', $properties['tags']['properties'] ); + $this->assertArrayHasKey( 'template', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); @@ -324,6 +330,14 @@ public function test_theme_stylesheet() { $this->assertSame( 'default', $result[0]['stylesheet'] ); } + public function test_theme_tags() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'tags', $result[0] ); + $this->assertSame( array(), $result[0]['tags']['raw'] ); + $this->assertSame( '', $result[0]['tags']['rendered'] ); + } + public function test_theme_template() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From d00cfb4f3ab06ddf3812fe5e27449957e81471a9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 00:20:38 +0200 Subject: [PATCH 28/38] Whitespace/linebreak --- tests/phpunit/tests/rest-api/rest-themes-controller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index abe0c02a6f4f7..2aeea7e2f06b5 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -350,7 +350,8 @@ public function test_theme_theme_uri() { $result = $response->get_data(); $this->assertArrayHasKey( 'theme_uri', $result[0] ); $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['raw'] ); - $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['rendered'] ); } + $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['rendered'] ); + } public function test_theme_version() { $response = self::perform_active_theme_request(); From f828777a8491525486c94a0dc958575a1411c050 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 13:50:57 +0200 Subject: [PATCH 29/38] Add 'items' declaration for 'raw' tags --- .../rest-api/endpoints/class-wp-rest-themes-controller.php | 3 +++ tests/phpunit/tests/rest-api/rest-themes-controller.php | 1 + 2 files changed, 4 insertions(+) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index c90a1a86f4c7b..73b2400bbbae3 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -315,6 +315,9 @@ public function get_item_schema() { 'description' => __( 'Theme tags, as found in the theme header.' ), 'type' => 'array', 'readonly' => true, + 'items' => array( + 'type' => 'string', + ), ), 'rendered' => array( 'description' => __( 'Theme tags, transformed for display.' ), diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 2aeea7e2f06b5..91543db518a9e 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -240,6 +240,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'tags', $properties ); $this->assertArrayHasKey( 'raw', $properties['tags']['properties'] ); + $this->assertArrayHasKey( 'items', $properties['tags']['properties']['raw'] ); $this->assertArrayHasKey( 'rendered', $properties['tags']['properties'] ); $this->assertArrayHasKey( 'template', $properties ); From d14da4093bc35259e6b74640647378ac8ae1950e Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 14:44:26 +0200 Subject: [PATCH 30/38] Use (preferred) $theme->get rather than (backward-compat) ArrayAccess --- .../endpoints/class-wp-rest-themes-controller.php | 15 +++++++++++++-- .../tests/rest-api/rest-themes-controller.php | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 73b2400bbbae3..7ce1cdebbf3e3 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -117,14 +117,13 @@ public function prepare_item_for_response( $theme, $request ) { $plain_field_mappings = array( 'stylesheet' => 'Stylesheet', - 'template' => 'Template', 'version' => 'Version', ); $plain_fields_to_include = array_intersect( array_keys( $plain_field_mappings ), $fields ); foreach ( $plain_fields_to_include as $field ) { - $data[ $field ] = $theme[ $plain_field_mappings[ $field ] ]; + $data[ $field ] = $theme->get( $plain_field_mappings[ $field ] ); } if ( in_array( 'screenshot', $fields, true ) ) { @@ -132,6 +131,18 @@ public function prepare_item_for_response( $theme, $request ) { $data['screenshot'] = $theme->get_screenshot() ?: ''; } + if ( in_array( 'template', $fields, true ) ) { + /** + * @see WP_Theme::get() + * + * Use the get_template() method, not the 'Template' header, for finding the template. + * The 'Template' header is only good for what was written in the style.css, while + * get_template() takes into account where WordPress actually located the theme and + * whether it is actually valid. + */ + $data['template'] = $theme->get_template(); + } + $rich_field_mappings = array( 'author' => 'Author', 'author_uri' => 'AuthorURI', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 91543db518a9e..8a53932b39fb0 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -328,7 +328,7 @@ public function test_theme_stylesheet() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'stylesheet', $result[0] ); - $this->assertSame( 'default', $result[0]['stylesheet'] ); + $this->assertFalse( $result[0]['stylesheet'] ); } public function test_theme_tags() { From 4a959aee182893a35fbadb78d5330e3e1e48b12d Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 14:52:15 +0200 Subject: [PATCH 31/38] Add textdomain field --- .../endpoints/class-wp-rest-themes-controller.php | 6 ++++++ .../phpunit/tests/rest-api/rest-themes-controller.php | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 7ce1cdebbf3e3..8cda03258c0ef 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -117,6 +117,7 @@ public function prepare_item_for_response( $theme, $request ) { $plain_field_mappings = array( 'stylesheet' => 'Stylesheet', + 'textdomain' => 'TextDomain', 'version' => 'Version', ); @@ -342,6 +343,11 @@ public function get_item_schema() { 'type' => 'string', 'readonly' => true, ), + 'textdomain' => array( + 'description' => __( 'The theme\'s textdomain.' ), + 'type' => 'string', + 'readonly' => true, + ), 'theme_supports' => array( 'description' => __( 'Features supported by this theme.' ), 'type' => 'object', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 8a53932b39fb0..4655c21331ded 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -158,6 +158,7 @@ public function test_get_items() { 'stylesheet', 'tags', 'template', + 'textdomain', 'theme_supports', 'theme_uri', 'version', @@ -217,7 +218,7 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 11, count( $properties ) ); + $this->assertEquals( 12, count( $properties ) ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); @@ -244,6 +245,7 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'rendered', $properties['tags']['properties'] ); $this->assertArrayHasKey( 'template', $properties ); + $this->assertArrayHasKey( 'textdomain', $properties ); $this->assertArrayHasKey( 'theme_supports', $properties ); $this->assertArrayHasKey( 'theme_uri', $properties ); @@ -346,6 +348,13 @@ public function test_theme_template() { $this->assertSame( 'default', $result[0]['template'] ); } + public function test_theme_textdomain() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'textdomain', $result[0] ); + $this->assertSame( '', $result[0]['textdomain'] ); + } + public function test_theme_theme_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From fac13e50b3a9c0a025cf0a3e231960742df3c745 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Wed, 3 Jun 2020 21:07:36 +0200 Subject: [PATCH 32/38] Add requires_php and requires_wp fields --- .../class-wp-rest-themes-controller.php | 18 ++++++++++++++--- .../tests/rest-api/rest-themes-controller.php | 20 ++++++++++++++++++- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 8cda03258c0ef..761ee1cfd07a2 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -116,9 +116,11 @@ public function prepare_item_for_response( $theme, $request ) { $fields = $this->get_fields_for_response( $request ); $plain_field_mappings = array( - 'stylesheet' => 'Stylesheet', - 'textdomain' => 'TextDomain', - 'version' => 'Version', + 'requires_php' => 'RequiresPHP', + 'requires_wp' => 'RequiresWP', + 'stylesheet' => 'Stylesheet', + 'textdomain' => 'TextDomain', + 'version' => 'Version', ); $plain_fields_to_include = array_intersect( array_keys( $plain_field_mappings ), $fields ); @@ -308,6 +310,16 @@ public function get_item_schema() { ), ), ), + 'requires_php' => array( + 'description' => __( 'The minimum PHP version required for the theme to work.' ), + 'type' => 'string', + 'readonly' => true, + ), + 'requires_wp' => array( + 'description' => __( 'The minimum WordPress version required for the theme to work.' ), + 'type' => 'string', + 'readonly' => true, + ), 'screenshot' => array( 'description' => __( 'A theme screenshot URL.' ), 'type' => 'string', diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index 4655c21331ded..d84adbe9eb122 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -154,6 +154,8 @@ public function test_get_items() { 'author_uri', 'description', 'name', + 'requires_php', + 'requires_wp', 'screenshot', 'stylesheet', 'tags', @@ -218,7 +220,7 @@ public function test_get_item_schema() { $response = self::perform_active_theme_request( 'OPTIONS' ); $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertEquals( 12, count( $properties ) ); + $this->assertEquals( 14, count( $properties ) ); $this->assertArrayHasKey( 'author', $properties ); $this->assertArrayHasKey( 'raw', $properties['author']['properties'] ); @@ -236,6 +238,8 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'raw', $properties['name']['properties'] ); $this->assertArrayHasKey( 'rendered', $properties['name']['properties'] ); + $this->assertArrayHasKey( 'requires_php', $properties ); + $this->assertArrayHasKey( 'requires_wp', $properties ); $this->assertArrayHasKey( 'screenshot', $properties ); $this->assertArrayHasKey( 'stylesheet', $properties ); @@ -311,6 +315,20 @@ public function test_theme_description() { ); } + public function test_theme_requires_php() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'requires_php', $result[0] ); + $this->assertSame( '', $result[0]['requires_php'] ); + } + + public function test_theme_requires_wp() { + $response = self::perform_active_theme_request(); + $result = $response->get_data(); + $this->assertArrayHasKey( 'requires_wp', $result[0] ); + $this->assertSame( '', $result[0]['requires_wp'] ); + } + public function test_theme_name() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From 7f5db79e2b6ee0494df44c664b09e4333636bed9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Thu, 4 Jun 2020 16:29:13 +0200 Subject: [PATCH 33/38] format should be uri, not type --- .../class-wp-rest-themes-controller.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 761ee1cfd07a2..2957b213e80b5 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -260,18 +260,20 @@ public function get_item_schema() { ), 'author_uri' => array( 'description' => __( 'The website of the theme author.' ), - 'format' => 'uri', 'type' => 'object', + 'format' => 'uri', 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'The website of the theme author, as found in the theme header.' ), - 'type' => 'uri', + 'type' => 'string', + 'format' => 'uri', 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The website of the theme author, transformed for display.' ), - 'type' => 'uri', + 'type' => 'string', + 'format' => 'uri', 'readonly' => true, ), ), @@ -629,17 +631,19 @@ public function get_item_schema() { 'theme_uri' => array( 'description' => __( 'The URI of the theme\'s webpage.' ), 'type' => 'object', - 'readonly' => true, 'format' => 'uri', + 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'The URI of the theme\'s webpage, as found in the theme header.' ), - 'type' => 'uri', + 'type' => 'string', + 'format' => 'uri', 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The URI of the theme\'s webpage, transformed for display.' ), - 'type' => 'uri', + 'type' => 'string', + 'format' => 'uri', 'readonly' => true, ), ), From 019eb4b251756cda734c7bf23cbd55013d681a3c Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 7 Jun 2020 00:48:14 -0400 Subject: [PATCH 34/38] Switch to "rest_is_field_included" --- .../class-wp-rest-themes-controller.php | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 2957b213e80b5..7475def211b20 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -123,18 +123,18 @@ public function prepare_item_for_response( $theme, $request ) { 'version' => 'Version', ); - $plain_fields_to_include = array_intersect( array_keys( $plain_field_mappings ), $fields ); - - foreach ( $plain_fields_to_include as $field ) { - $data[ $field ] = $theme->get( $plain_field_mappings[ $field ] ); + foreach ( $plain_field_mappings as $field => $header ) { + if ( rest_is_field_included( $field, $fields ) ) { + $data[ $field ] = $theme->get( $header ); + } } - if ( in_array( 'screenshot', $fields, true ) ) { + if ( rest_is_field_included( 'screenshot', $fields ) ) { // Using $theme->get_screenshot() with no args to get absolute URL. $data['screenshot'] = $theme->get_screenshot() ?: ''; } - if ( in_array( 'template', $fields, true ) ) { + if ( rest_is_field_included( 'template', $fields ) ) { /** * @see WP_Theme::get() * @@ -157,17 +157,24 @@ public function prepare_item_for_response( $theme, $request ) { $rich_fields_to_include = array_intersect( array_keys( $rich_field_mappings ), $fields ); - foreach ( $rich_fields_to_include as $field ) { - $data[ $field ] = array( - 'raw' => $theme->display( $rich_field_mappings[ $field ], false, true ), - 'rendered' => $theme->display( $rich_field_mappings[ $field ] ), - ); + foreach ( $rich_field_mappings as $field => $header ) { + if ( rest_is_field_included( "{$field}.raw", $fields ) ) { + $data[ $field ]['raw'] = $theme->display( $header, false, true ); + } + + if ( rest_is_field_included( "{$field}.rendered", $fields ) ) { + $data[ $field ]['rendered'] = $theme->display( $header ); + } } - if ( in_array( 'theme_supports', $fields, true ) ) { + if ( rest_is_field_included( 'theme_supports', $fields ) ) { $item_schemas = $this->get_item_schema(); $theme_supports = $item_schemas['properties']['theme_supports']['properties']; foreach ( $theme_supports as $name => $schema ) { + if ( ! rest_is_field_included( "theme_supports.{$name}", $fields ) ) { + continue; + } + if ( 'formats' === $name ) { continue; } From fd52d6fc015517c204f57ad178e2ce20a8e927d2 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 7 Jun 2020 01:13:38 -0400 Subject: [PATCH 35/38] Clean up the schema definition a bit. --- .../class-wp-rest-themes-controller.php | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 7475def211b20..729d69069b76c 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -155,8 +155,6 @@ public function prepare_item_for_response( $theme, $request ) { 'theme_uri' => 'ThemeURI', ); - $rich_fields_to_include = array_intersect( array_keys( $rich_field_mappings ), $fields ); - foreach ( $rich_field_mappings as $field => $header ) { if ( rest_is_field_included( "{$field}.raw", $fields ) ) { $data[ $field ]['raw'] = $theme->display( $header, false, true ); @@ -248,6 +246,11 @@ public function get_item_schema() { 'title' => 'theme', 'type' => 'object', 'properties' => array( + 'stylesheet' => array( + 'description' => __( 'The theme\'s stylesheet. This uniquely identifies the theme.' ), + 'type' => 'string', + 'readonly' => true, + ), 'author' => array( 'description' => __( 'The theme author.' ), 'type' => 'object', @@ -256,32 +259,27 @@ public function get_item_schema() { 'raw' => array( 'description' => __( 'The theme author\'s name, as found in the theme header.' ), 'type' => 'string', - 'readonly' => true, ), 'rendered' => array( 'description' => __( 'HTML for the theme author, transformed for display.' ), 'type' => 'string', - 'readonly' => true, ), ), ), 'author_uri' => array( 'description' => __( 'The website of the theme author.' ), 'type' => 'object', - 'format' => 'uri', 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'The website of the theme author, as found in the theme header.' ), 'type' => 'string', 'format' => 'uri', - 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The website of the theme author, transformed for display.' ), 'type' => 'string', 'format' => 'uri', - 'readonly' => true, ), ), ), @@ -293,12 +291,10 @@ public function get_item_schema() { 'raw' => array( 'description' => __( 'The theme description, as found in the theme header.' ), 'type' => 'string', - 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The theme description, transformed for display.' ), 'type' => 'string', - 'readonly' => true, ), ), ), @@ -310,12 +306,10 @@ public function get_item_schema() { 'raw' => array( 'description' => __( 'The theme name, as found in the theme header.' ), 'type' => 'string', - 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The theme name, transformed for display.' ), 'type' => 'string', - 'readonly' => true, ), ), ), @@ -330,13 +324,9 @@ public function get_item_schema() { 'readonly' => true, ), 'screenshot' => array( - 'description' => __( 'A theme screenshot URL.' ), - 'type' => 'string', - 'readonly' => true, - ), - 'stylesheet' => array( - 'description' => __( 'The theme\'s stylesheet.' ), + 'description' => __( 'The theme\'s screenshot URL.' ), 'type' => 'string', + 'format' => 'uri', 'readonly' => true, ), 'tags' => array( @@ -345,17 +335,15 @@ public function get_item_schema() { 'readonly' => true, 'properties' => array( 'raw' => array( - 'description' => __( 'Theme tags, as found in the theme header.' ), + 'description' => __( 'The theme tags, as found in the theme header.' ), 'type' => 'array', - 'readonly' => true, 'items' => array( 'type' => 'string', ), ), 'rendered' => array( - 'description' => __( 'Theme tags, transformed for display.' ), + 'description' => __( 'The theme tags, transformed for display.' ), 'type' => 'string', - 'readonly' => true, ), ), ), @@ -638,20 +626,17 @@ public function get_item_schema() { 'theme_uri' => array( 'description' => __( 'The URI of the theme\'s webpage.' ), 'type' => 'object', - 'format' => 'uri', 'readonly' => true, 'properties' => array( 'raw' => array( 'description' => __( 'The URI of the theme\'s webpage, as found in the theme header.' ), 'type' => 'string', 'format' => 'uri', - 'readonly' => true, ), 'rendered' => array( 'description' => __( 'The URI of the theme\'s webpage, transformed for display.' ), 'type' => 'string', 'format' => 'uri', - 'readonly' => true, ), ), ), From 0ec4581001ce18399651bc40eaa27f6497e344f1 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 7 Jun 2020 01:55:15 -0400 Subject: [PATCH 36/38] Cleanup tests. Fix stylesheet handling. --- .../class-wp-rest-themes-controller.php | 37 +++++----- .../phpunit/data/themedir1/rest-api/style.css | 15 +++++ .../tests/rest-api/rest-themes-controller.php | 67 ++++++++++++++----- 3 files changed, 86 insertions(+), 33 deletions(-) create mode 100644 tests/phpunit/data/themedir1/rest-api/style.css diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php index 729d69069b76c..dfc11edc084c5 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php @@ -115,10 +115,23 @@ public function prepare_item_for_response( $theme, $request ) { $data = array(); $fields = $this->get_fields_for_response( $request ); + if ( rest_is_field_included( 'stylesheet', $fields ) ) { + $data['stylesheet'] = $theme->get_stylesheet(); + } + + if ( rest_is_field_included( 'template', $fields ) ) { + /** + * Use the get_template() method, not the 'Template' header, for finding the template. + * The 'Template' header is only good for what was written in the style.css, while + * get_template() takes into account where WordPress actually located the theme and + * whether it is actually valid. + */ + $data['template'] = $theme->get_template(); + } + $plain_field_mappings = array( 'requires_php' => 'RequiresPHP', 'requires_wp' => 'RequiresWP', - 'stylesheet' => 'Stylesheet', 'textdomain' => 'TextDomain', 'version' => 'Version', ); @@ -134,18 +147,6 @@ public function prepare_item_for_response( $theme, $request ) { $data['screenshot'] = $theme->get_screenshot() ?: ''; } - if ( rest_is_field_included( 'template', $fields ) ) { - /** - * @see WP_Theme::get() - * - * Use the get_template() method, not the 'Template' header, for finding the template. - * The 'Template' header is only good for what was written in the style.css, while - * get_template() takes into account where WordPress actually located the theme and - * whether it is actually valid. - */ - $data['template'] = $theme->get_template(); - } - $rich_field_mappings = array( 'author' => 'Author', 'author_uri' => 'AuthorURI', @@ -251,6 +252,11 @@ public function get_item_schema() { 'type' => 'string', 'readonly' => true, ), + 'template' => array( + 'description' => __( 'The theme\'s template. If this is a child theme, this refers to the parent theme, otherwise this is the same as the theme\'s stylesheet.' ), + 'type' => 'string', + 'readonly' => true, + ), 'author' => array( 'description' => __( 'The theme author.' ), 'type' => 'object', @@ -347,11 +353,6 @@ public function get_item_schema() { ), ), ), - 'template' => array( - 'description' => __( 'The theme\'s template name.' ), - 'type' => 'string', - 'readonly' => true, - ), 'textdomain' => array( 'description' => __( 'The theme\'s textdomain.' ), 'type' => 'string', diff --git a/tests/phpunit/data/themedir1/rest-api/style.css b/tests/phpunit/data/themedir1/rest-api/style.css new file mode 100644 index 0000000000000..9cc08dad31211 --- /dev/null +++ b/tests/phpunit/data/themedir1/rest-api/style.css @@ -0,0 +1,15 @@ +/* +Theme Name: REST Theme +Theme URI: http://wordpress.org/?search=1&term=2 +Description: The 9' foot tall theme. +Version: 1.6 +Author: Michael Heilemann +Author URI: http://binarybonsai.com/?search=1&term=2 +Tags: holiday, custom-menu +Template: default +Requires at least: 5.3 +Requires PHP: 7.4 +Text Domain: rest-api +*/ + + diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index d84adbe9eb122..e1ec37b01a404 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -125,6 +125,7 @@ public function setUp() { parent::setUp(); wp_set_current_user( self::$contributor_id ); + switch_theme( 'rest-api' ); } /** @@ -282,61 +283,82 @@ public function test_get_item_schema() { $this->assertArrayHasKey( 'wp-block-styles', $theme_supports ); } + /** + * @ticket 49906 + */ public function test_theme_author() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'author', $result[0] ); $this->assertSame( 'Michael Heilemann', $result[0]['author']['raw'] ); $this->assertSame( - 'Michael Heilemann', + 'Michael Heilemann', $result[0]['author']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_author_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'author_uri', $result[0] ); - $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri']['raw'] ); - $this->assertSame( 'http://binarybonsai.com/', $result[0]['author_uri']['rendered'] ); + $this->assertSame( 'http://binarybonsai.com/?search=1&term=2', $result[0]['author_uri']['raw'] ); + $this->assertSame( 'http://binarybonsai.com/?search=1&term=2', $result[0]['author_uri']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_description() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'description', $result[0] ); $this->assertSame( - 'The default WordPress theme based on the famous Kubrick.', + 'The 9\' foot tall theme.', $result[0]['description']['raw'] ); $this->assertSame( - 'The default WordPress theme based on the famous Kubrick.', + 'The 9′ foot tall theme.', $result[0]['description']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_requires_php() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'requires_php', $result[0] ); - $this->assertSame( '', $result[0]['requires_php'] ); + $this->assertSame( '7.4', $result[0]['requires_php'] ); } + /** + * @ticket 49906 + */ public function test_theme_requires_wp() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'requires_wp', $result[0] ); - $this->assertSame( '', $result[0]['requires_wp'] ); + $this->assertSame( '5.3', $result[0]['requires_wp'] ); } + /** + * @ticket 49906 + */ public function test_theme_name() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'name', $result[0] ); - $this->assertSame( 'WordPress Default', $result[0]['name']['raw'] ); - $this->assertSame( 'WordPress Default', $result[0]['name']['rendered'] ); + $this->assertSame( 'REST Theme', $result[0]['name']['raw'] ); + $this->assertSame( 'REST Theme', $result[0]['name']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_screenshot() { $response = self::perform_active_theme_request(); $result = $response->get_data(); @@ -344,21 +366,30 @@ public function test_theme_screenshot() { $this->assertSame( '', $result[0]['screenshot'] ); // No screenshot for default theme } + /** + * @ticket 49906 + */ public function test_theme_stylesheet() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'stylesheet', $result[0] ); - $this->assertFalse( $result[0]['stylesheet'] ); + $this->assertSame( 'rest-api', $result[0]['stylesheet'] ); } + /** + * @ticket 49906 + */ public function test_theme_tags() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'tags', $result[0] ); - $this->assertSame( array(), $result[0]['tags']['raw'] ); - $this->assertSame( '', $result[0]['tags']['rendered'] ); + $this->assertSame( array( 'holiday', 'custom-menu' ), $result[0]['tags']['raw'] ); + $this->assertSame( 'holiday, custom-menu', $result[0]['tags']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_template() { $response = self::perform_active_theme_request(); $result = $response->get_data(); @@ -366,21 +397,27 @@ public function test_theme_template() { $this->assertSame( 'default', $result[0]['template'] ); } + /** + * @ticket 49906 + */ public function test_theme_textdomain() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'textdomain', $result[0] ); - $this->assertSame( '', $result[0]['textdomain'] ); + $this->assertSame( 'rest-api', $result[0]['textdomain'] ); } public function test_theme_theme_uri() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'theme_uri', $result[0] ); - $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['raw'] ); - $this->assertSame( 'http://wordpress.org/', $result[0]['theme_uri']['rendered'] ); + $this->assertSame( 'http://wordpress.org/?search=1&term=2', $result[0]['theme_uri']['raw'] ); + $this->assertSame( 'http://wordpress.org/?search=1&term=2', $result[0]['theme_uri']['rendered'] ); } + /** + * @ticket 49906 + */ public function test_theme_version() { $response = self::perform_active_theme_request(); $result = $response->get_data(); From 2b0e2634065c1ac983862978ae2e6a0909a875b7 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 7 Jun 2020 02:07:47 -0400 Subject: [PATCH 37/38] Include fixture in theme list test. --- tests/phpunit/tests/theme/themeDir.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index 0b697ef49237e..a8cfd87f47c5a 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -163,6 +163,7 @@ function test_theme_list() { 'Theme with Spaces in the Directory', 'Internationalized Theme', 'camelCase', + 'REST Theme', ); sort( $theme_names ); From 29ae2dcfc302697c90b9f515d6e1587058b62002 Mon Sep 17 00:00:00 2001 From: Timothy Jacobs Date: Sun, 7 Jun 2020 02:20:09 -0400 Subject: [PATCH 38/38] We of course have to let the theme work on 5.6 :D --- tests/phpunit/data/themedir1/rest-api/style.css | 2 +- tests/phpunit/tests/rest-api/rest-themes-controller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/data/themedir1/rest-api/style.css b/tests/phpunit/data/themedir1/rest-api/style.css index 9cc08dad31211..27fe7b53a0df5 100644 --- a/tests/phpunit/data/themedir1/rest-api/style.css +++ b/tests/phpunit/data/themedir1/rest-api/style.css @@ -8,7 +8,7 @@ Author URI: http://binarybonsai.com/?search=1&term=2 Tags: holiday, custom-menu Template: default Requires at least: 5.3 -Requires PHP: 7.4 +Requires PHP: 5.6 Text Domain: rest-api */ diff --git a/tests/phpunit/tests/rest-api/rest-themes-controller.php b/tests/phpunit/tests/rest-api/rest-themes-controller.php index e1ec37b01a404..1f7c53b37458a 100644 --- a/tests/phpunit/tests/rest-api/rest-themes-controller.php +++ b/tests/phpunit/tests/rest-api/rest-themes-controller.php @@ -332,7 +332,7 @@ public function test_theme_requires_php() { $response = self::perform_active_theme_request(); $result = $response->get_data(); $this->assertArrayHasKey( 'requires_php', $result[0] ); - $this->assertSame( '7.4', $result[0]['requires_php'] ); + $this->assertSame( '5.6', $result[0]['requires_php'] ); } /**