From 40f076d7562b91af876495a45ce35a2351a072f0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 15 Jan 2017 06:50:00 +0000 Subject: [PATCH] Themes: Add a unit test for `get_theme_feature_list()` to make sure that the list of theme features pulled from the WordPress.org API returns the expected data structure. Props iandunn. Fixes #28121. git-svn-id: https://develop.svn.wordpress.org/trunk@39906 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/includes/testcase.php | 15 ++++++++++++ tests/phpunit/tests/admin/includesTheme.php | 27 +++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 899050455d..0528cfffa7 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -439,6 +439,21 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { $this->assertEquals( $expected, $actual ); } + /** + * Asserts that the given variable is a multidimensional array, and that all arrays are non-empty. + * + * @param array $array + */ + function assertNonEmptyMultidimensionalArray( $array ) { + $this->assertTrue( is_array( $array ) ); + $this->assertNotEmpty( $array ); + + foreach( $array as $sub_array ) { + $this->assertTrue( is_array( $sub_array ) ); + $this->assertNotEmpty( $sub_array ); + } + } + /** * Modify WordPress's query internals as if a given URL has been requested. * diff --git a/tests/phpunit/tests/admin/includesTheme.php b/tests/phpunit/tests/admin/includesTheme.php index 522615c8a0..223560d98d 100644 --- a/tests/phpunit/tests/admin/includesTheme.php +++ b/tests/phpunit/tests/admin/includesTheme.php @@ -136,4 +136,31 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase { ), get_page_templates() ); $this->assertEquals( array(), get_page_templates( null, 'bar' ) ); } + + /** + * Test that the list of theme features pulled from the WordPress.org API returns the expected data structure. + * + * Differences in the structure can also trigger failure by causing PHP notices/warnings. + * + * @group external-http + * @ticket 28121 + */ + function test_get_theme_featured_list_api() { + wp_set_current_user( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); + $featured_list_api = get_theme_feature_list( true ); + $this->assertNonEmptyMultidimensionalArray( $featured_list_api ); + } + + /** + * Test that the list of theme features hardcoded into Core returns the expected data structure. + * + * Differences in the structure can also trigger failure by causing PHP notices/warnings. + * + * @group external-http + * @ticket 28121 + */ + function test_get_theme_featured_list_hardcoded() { + $featured_list_hardcoded = get_theme_feature_list( false ); + $this->assertNonEmptyMultidimensionalArray( $featured_list_hardcoded ); + } }