Verified Commit 9120581f authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add tests for writable cache dir

parent 06fe7b70
Loading
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
<?php
/*
Plugin Name: Test Plugin
Description: Assists in the testing of some scenarios
*/

add_action( 'rest_api_init', function() {
	register_rest_route( 'test/v1', '/write-cache', array(
		'methods' => WP_REST_Server::READABLE,
		'callback' => function($request) {
			if ( !isset($request['file']) ) {
				return new WP_Error('Missing param file');
			}
			$file = WP_CONTENT_DIR . "/cache/{$request['file']}";
			file_put_contents($file, "Generated file");
			return rest_ensure_response( "Cache file created" );
		},
		'args' => array(
			'file' => array(
				'description' => 'File to touch on the server host',
				'type' => 'string',
			)
		)
	));
});

/* register_activation_hook( __FILE__, function() { */
/* 	if ( !defined('WP_CLI') && $_SERVER['REQUEST_URI'] == '/test-cache' ) { */
/* 		$file = WP_CONTENT_DIR . "/cache/${_GET['file']}"; */
/* 		file_put_contents($file, "Generated file"); */
/* 		wp_die("Cache file created", 200); */
/* 	} */
/* }); */
+17 −0
Original line number Diff line number Diff line
@wip
Feature: Page cache directory
	Ensure that the page cache directory at WP_CONTENT_DIR/cache is writable for
	plugins, but is not served by the server.

	Scenario: After the entrypoint has completed, there is a writable cache dir
		Given the site is not running
		And test-cache.php is mounted in /app/wp-content/mu-plugins/
		When the site is started
		And /wp-json/test/v1/write-cache?file=foo.txt is requested
		Then OK is returned
		And /app/wp-content/cache/foo.txt exists in the backend

	Scenario: The contents of the cache dir are not served by the proxy
		Given /app/wp-content/cache/foo exists in the backend
		When /wp-content/cache/foo is requested
		Then Not Found is returned
+11 −0
Original line number Diff line number Diff line
@@ -231,6 +231,17 @@ def is_plugin_installed(
		assert site.backend.cli(addon.value, "is-active", name, query=True) == status.value


@then("{path:Path} exists in the {container_name}")
def check_file_exists(context: Context, path: Path, container_name: str) -> None:
	"""
	Check a file exists in the named container
	"""
	site = use_fixture(site_fixture, context)
	container = getattr(site, container_name)
	assert container.run(["sh", "-c", f"test -e {path}"]).returncode == 0, \
		f"{path} not found in the {container_name}"


@then("the email address of {user} is \"{value}\"")
@then("the email address of {user} is '{value}'")
def is_user_email(context: Context, user: str, value: str) -> None: