Changeset 42343 for trunk/tests/phpunit/tests/theme/getAllowedFilters.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/theme/getAllowedFilters.php
r36366 r42343 1 1 <?php 2 2 if ( is_multisite() ) : 3 /**4 * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.5 *6 * @group themes7 * @group multisite8 */9 class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase {10 3 /** 11 * @array List of themes allowed before filters are applied. 4 * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions. 5 * 6 * @group themes 7 * @group multisite 12 8 */ 13 protected $default_allowed; 9 class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase { 10 /** 11 * @array List of themes allowed before filters are applied. 12 */ 13 protected $default_allowed; 14 14 15 protected $filter_network_allowed_themes_args;15 protected $filter_network_allowed_themes_args; 16 16 17 public function test_network_allowed_themes_filter_sends_blog_id() {18 $blog_id = 1;17 public function test_network_allowed_themes_filter_sends_blog_id() { 18 $blog_id = 1; 19 19 20 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );21 WP_Theme::get_allowed( $blog_id );22 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );20 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 ); 21 WP_Theme::get_allowed( $blog_id ); 22 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) ); 23 23 24 $this->assertEquals( 2, count( $this->filter_network_allowed_themes_args ) ); 25 $this->assertEquals( $blog_id, $this->filter_network_allowed_themes_args[1] ); 24 $this->assertEquals( 2, count( $this->filter_network_allowed_themes_args ) ); 25 $this->assertEquals( $blog_id, $this->filter_network_allowed_themes_args[1] ); 26 } 27 28 /** 29 * Test the `allowed_themes` filter, which filters themes allowed on a network. 30 */ 31 public function test_wp_theme_get_allowed_with_allowed_themes_filter() { 32 $blog_id = 1; 33 34 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 35 36 add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 ); 37 $allowed = WP_Theme::get_allowed( $blog_id ); 38 remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 ); 39 40 $expected = $this->default_allowed + array( 'allow-on-network' => true ); 41 42 $this->assertEquals( $expected, $allowed ); 43 } 44 45 /** 46 * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`. 47 */ 48 public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() { 49 $blog_id = 1; 50 51 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 52 53 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 ); 54 $allowed = WP_Theme::get_allowed( $blog_id ); 55 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 ); 56 57 $expected = $this->default_allowed + array( 'network-allowed-theme' => true ); 58 59 $this->assertEquals( $expected, $allowed ); 60 } 61 62 /** 63 * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`. 64 */ 65 public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() { 66 $blog_id = 1; 67 68 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 69 70 add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 ); 71 $allowed = WP_Theme::get_allowed( $blog_id ); 72 remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 ); 73 74 $expected = $this->default_allowed + array( 'site-allowed-theme' => true ); 75 76 $this->assertEquals( $expected, $allowed ); 77 } 78 79 public function filter_allowed_themes( $allowed_themes ) { 80 $allowed_themes['allow-on-network'] = true; 81 82 return $allowed_themes; 83 } 84 85 public function filter_network_allowed_themes( $allowed_themes, $blog_id ) { 86 $this->filter_network_allowed_themes_args = func_get_args(); 87 88 $allowed_themes['network-allowed-theme'] = true; 89 90 return $allowed_themes; 91 } 92 93 public function filter_site_allowed_themes( $allowed_themes, $blog_id ) { 94 $allowed_themes['site-allowed-theme'] = true; 95 96 return $allowed_themes; 97 } 26 98 } 27 28 /**29 * Test the `allowed_themes` filter, which filters themes allowed on a network.30 */31 public function test_wp_theme_get_allowed_with_allowed_themes_filter() {32 $blog_id = 1;33 34 $this->default_allowed = WP_Theme::get_allowed( $blog_id );35 36 add_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );37 $allowed = WP_Theme::get_allowed( $blog_id );38 remove_filter( 'allowed_themes', array( $this, 'filter_allowed_themes' ), 10 );39 40 $expected = $this->default_allowed + array( 'allow-on-network' => true );41 42 $this->assertEquals( $expected, $allowed );43 }44 45 /**46 * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.47 */48 public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {49 $blog_id = 1;50 51 $this->default_allowed = WP_Theme::get_allowed( $blog_id );52 53 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );54 $allowed = WP_Theme::get_allowed( $blog_id );55 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );56 57 $expected = $this->default_allowed + array( 'network-allowed-theme' => true );58 59 $this->assertEquals( $expected, $allowed );60 }61 62 /**63 * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.64 */65 public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {66 $blog_id = 1;67 68 $this->default_allowed = WP_Theme::get_allowed( $blog_id );69 70 add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );71 $allowed = WP_Theme::get_allowed( $blog_id );72 remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );73 74 $expected = $this->default_allowed + array( 'site-allowed-theme' => true );75 76 $this->assertEquals( $expected, $allowed );77 }78 79 public function filter_allowed_themes( $allowed_themes ) {80 $allowed_themes['allow-on-network'] = true;81 82 return $allowed_themes;83 }84 85 public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {86 $this->filter_network_allowed_themes_args = func_get_args();87 88 $allowed_themes['network-allowed-theme'] = true;89 90 return $allowed_themes;91 }92 93 public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {94 $allowed_themes['site-allowed-theme'] = true;95 96 return $allowed_themes;97 }98 }99 99 endif;
Note: See TracChangeset
for help on using the changeset viewer.