- Timestamp:
- 04/09/2025 01:29:39 PM (6 weeks 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 16 protected $filter_network_allowed_themes_args; 16 17 17 18 18 public function test_network_allowed_themes_filter_sends_blog_id() { 19 $blog_id = 1; 19 20 20 21 22 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 25 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 30 31 32 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 35 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 35 36 36 37 38 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 41 $expected = $this->default_allowed + array( 'allow-on-network' => true ); 41 42 42 43 43 $this->assertSame( $expected, $allowed ); 44 } 44 45 45 46 47 48 49 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 52 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 52 53 53 54 55 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 58 $expected = $this->default_allowed + array( 'network-allowed-theme' => true ); 58 59 59 60 60 $this->assertSame( $expected, $allowed ); 61 } 61 62 62 63 64 65 66 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 69 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 69 70 70 71 72 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 75 $expected = $this->default_allowed + array( 'site-allowed-theme' => true ); 75 76 76 77 77 $this->assertSame( $expected, $allowed ); 78 } 78 79 79 80 80 public function filter_allowed_themes( $allowed_themes ) { 81 $allowed_themes['allow-on-network'] = true; 81 82 82 83 83 return $allowed_themes; 84 } 84 85 85 86 86 public function filter_network_allowed_themes( $allowed_themes, $blog_id ) { 87 $this->filter_network_allowed_themes_args = func_get_args(); 87 88 88 89 $allowed_themes['network-allowed-theme'] = true; 89 90 90 91 91 return $allowed_themes; 92 } 92 93 93 94 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.