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