<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[38907] trunk/tests/phpunit: Tests: Use a minimal theme for tests.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/38907">38907</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/38907","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>pento</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-10-25 10:24:57 +0000 (Tue, 25 Oct 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Tests: Use a minimal theme for tests.
This functionality was originally added in <a href="https://core.trac.wordpress.org/changeset/38858">[38858]</a>, using `symlink()` to put a link to the theme in WordPress' `themes` directory. Unfortunately, not all installs have write access to the `themes` directory, causing unit tests to fail.
The new method is to add the test theme directory to `$wp_theme_directories`, and fix the handful of tests that don't expect `$wp_theme_directories` to have multiple entries.
The test install/bootstrap routines now also check that `WP_DEFAULT_THEME` is defined, in case the tests are being run on a system that hasn't upgraded its' `wp-tests-config.php`.
See <a href="https://core.trac.wordpress.org/ticket/31550">#31550</a>.
Fixes <a href="https://core.trac.wordpress.org/ticket/38457">#38457</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunktestsphpunitincludesbootstrapphp">trunk/tests/phpunit/includes/bootstrap.php</a></li>
<li><a href="#trunktestsphpunitincludesfunctionsphp">trunk/tests/phpunit/includes/functions.php</a></li>
<li><a href="#trunktestsphpunitincludesinstallphp">trunk/tests/phpunit/includes/install.php</a></li>
<li><a href="#trunktestsphpunitteststhemephp">trunk/tests/phpunit/tests/theme.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunktestsphpunitincludesbootstrapphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/bootstrap.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/bootstrap.php 2016-10-25 06:30:27 UTC (rev 38906)
+++ trunk/tests/phpunit/includes/bootstrap.php 2016-10-25 10:24:57 UTC (rev 38907)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,7 +16,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Globalize some WordPress variables, because PHPUnit loads this file inside a function
</span><span class="cx" style="display: block; padding: 0 10px"> * See: https://github.com/sebastianbergmann/phpunit/issues/325
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+global $wpdb, $current_site, $current_blog, $wp_rewrite, $shortcode_tags, $wp, $phpmailer, $wp_theme_directories;
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( !is_readable( $config_file_path ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> die( "ERROR: wp-tests-config.php is missing! Please use wp-tests-config-sample.php to create a config file.\n" );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,8 +53,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( dirname( __FILE__ ) . '/mock-mailer.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> $phpmailer = new MockPHPMailer();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-// Add a symlink to the empty default theme to the themes directory, so it can be used for the tests.
-_symlink_default_theme();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
+if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
+ define( 'WP_DEFAULT_THEME', 'default' );
+}
+$wp_theme_directories = array( DIR_TESTDATA . '/themedir1' );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunitincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/functions.php 2016-10-25 06:30:27 UTC (rev 38906)
+++ trunk/tests/phpunit/includes/functions.php 2016-10-25 10:24:57 UTC (rev 38907)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -161,21 +161,3 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> return $uploads;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-/**
- * Helper functions to link and unlink the empty default theme into the WordPress install
- */
-function _symlink_default_theme() {
- _unlink_default_theme();
- symlink( DIR_TESTDATA . '/themedir1/default', ABSPATH . '/wp-content/themes/default' );
-}
-
-function _unlink_default_theme() {
- if ( file_exists( ABSPATH . '/wp-content/themes/default' ) ) {
- unlink( ABSPATH . '/wp-content/themes/default' );
- }
-}
-// Only unlink when we're in the main process.
-if ( 'phpunit' === substr( $GLOBALS['argv'][0], -7 ) ) {
- register_shutdown_function( '_unlink_default_theme' );
-}
</del></span></pre></div>
<a id="trunktestsphpunitincludesinstallphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/includes/install.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/includes/install.php 2016-10-25 06:30:27 UTC (rev 38906)
+++ trunk/tests/phpunit/includes/install.php 2016-10-25 10:24:57 UTC (rev 38907)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9,6 +9,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $config_file_path = $argv[1];
</span><span class="cx" style="display: block; padding: 0 10px"> $multisite = ! empty( $argv[2] );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Set the theme to our special empty theme, to avoid interference from the current Twenty* theme.
+if ( ! defined( 'WP_DEFAULT_THEME' ) ) {
+ define( 'WP_DEFAULT_THEME', 'default' );
+}
+$wp_theme_directories = array( dirname( __FILE__ ) . '/../data/themedir1' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> define( 'WP_INSTALLING', true );
</span><span class="cx" style="display: block; padding: 0 10px"> require_once $config_file_path;
</span><span class="cx" style="display: block; padding: 0 10px"> require_once dirname( __FILE__ ) . '/functions.php';
</span></span></pre></div>
<a id="trunktestsphpunitteststhemephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme.php 2016-10-25 06:30:27 UTC (rev 38906)
+++ trunk/tests/phpunit/tests/theme.php 2016-10-25 10:24:57 UTC (rev 38907)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,16 +14,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function setUp() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_theme_directories;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> parent::setUp();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $backup_wp_theme_directories = $wp_theme_directories;
+ $wp_theme_directories = array( WP_CONTENT_DIR . '/themes' );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'extra_theme_headers', array( $this, '_theme_data_extra_headers' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_clean_themes_cache();
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $GLOBALS['wp_themes'] );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> function tearDown() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ global $wp_theme_directories;
+
+ $wp_theme_directories = $this->wp_theme_directories;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'extra_theme_headers', array( $this, '_theme_data_extra_headers' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> wp_clean_themes_cache();
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $GLOBALS['wp_themes'] );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> parent::tearDown();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre>
</div>
</div>
</body>
</html>