includesTheme.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @group themes
  4. */
  5. class Tests_Admin_includesTheme extends WP_UnitTestCase {
  6. function setUp() {
  7. parent::setUp();
  8. $this->theme_root = DIR_TESTDATA . '/themedir1';
  9. $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
  10. $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
  11. add_filter('theme_root', array($this, '_theme_root'));
  12. add_filter( 'stylesheet_root', array($this, '_theme_root') );
  13. add_filter( 'template_root', array($this, '_theme_root') );
  14. // clear caches
  15. wp_clean_themes_cache();
  16. unset( $GLOBALS['wp_themes'] );
  17. }
  18. function tearDown() {
  19. $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
  20. remove_filter('theme_root', array($this, '_theme_root'));
  21. remove_filter( 'stylesheet_root', array($this, '_theme_root') );
  22. remove_filter( 'template_root', array($this, '_theme_root') );
  23. wp_clean_themes_cache();
  24. unset( $GLOBALS['wp_themes'] );
  25. parent::tearDown();
  26. }
  27. // replace the normal theme root dir with our premade test dir
  28. function _theme_root($dir) {
  29. return $this->theme_root;
  30. }
  31. /**
  32. * @ticket 10959
  33. * @ticket 11216
  34. * @expectedDeprecated get_theme
  35. * @expectedDeprecated get_themes
  36. */
  37. function test_page_templates() {
  38. $theme = get_theme( 'Page Template Theme' );
  39. $this->assertNotEmpty( $theme );
  40. switch_theme( $theme['Template'], $theme['Stylesheet'] );
  41. $templates = get_page_templates();
  42. $this->assertCount( 3, $templates );
  43. $this->assertEquals( "template-top-level.php", $templates['Top Level'] );
  44. $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );
  45. $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] );
  46. $theme = wp_get_theme( 'page-templates' );
  47. $this->assertNotEmpty( $theme );
  48. switch_theme( $theme['Template'], $theme['Stylesheet'] );
  49. $templates = get_page_templates();
  50. $this->assertCount( 3, $templates );
  51. $this->assertEquals( "template-top-level.php", $templates['Top Level'] );
  52. $this->assertEquals( "subdir/template-sub-dir.php", $templates['Sub Dir'] );
  53. $this->assertEquals( "template-header.php", $templates['This Template Header Is On One Line'] );
  54. }
  55. }