Skip to content

Commit

Permalink
[CMSP-995] Notices for low max age values in Page Cache Options (#268)
Browse files Browse the repository at this point in the history
* add initial admin interface class
hook to mu-plugin > 1.4.0

* some more scaffolding

* require at least 6.4

* don't show notices if wp_admin_notice doesn't exist

* add notice if mu-plugin was not found

* add notice if the mu-plugin is old

* fix link and change decimal to string

* use spaces instead of line breaks

* add helper function to get current max age
this is either set in the mu-plugin or empty. if empty, it should default to 1 week

* add notice if less than 1 week but not == 600 seconds

* add docblock

* add translator comments

* update tested up to and requires at least values in readmes

* version bump

* bump composer deps

* don't display the warnings if we aren't on the pantheon cache admin page

* convert static class to a namespace
there's no reason to make this a class since we're not using any class features

* add a bootstrapper for namespace-only files

* lint

* escape the wp_die message

* use a helper for humanized time calculations

* we still need to test the current max age

* pass the current max age to the message, too
and be specific that we're talking about seconds

* use the filterable value for default max age
because it could be something different

* add a helper function for retrieving the default max age
this is helpful so we can always return the filtered value

* also display the seconds in the successful test

* rank the max age value
don't say it's "very low" unless that's actually accurate.

* add caching to the ranked compare

* make the color more severe if it's a bigger issue

* change the color of the admin notice based on the severity of the diff

* clear the transient when the option is updated

* break notice type into a variable

* fix the translator note

* keep the rank but hide it from the dom

* add unit tests

* add initial behat test
let's just see if we can assume this will work

* fix failing test

* specify the element where the notices are

* add site health check test

* actually save the changes

* remove max age check
only exists in an html comment anyway

* simplify the site health check

* add the message when you expand the accordion

* add other site health things

* change press to click?

* add "open the accordion" as a custom step

* move behat stuff around

* move stuff around again

* update the behat.yml

* remove custom context and try "when I follow"

* move to checking the text inside the elements

* target the hidden element

* use hidden='hidden'

* call it a div

* simplify the tests

* remove press
since we can't actually press

* it did actually find the right heading
maybe it will find the right text?

* add @\since tags

* add changelog and upgrade notice

* let's try checking for some of the hidden text

* period at the end of the sentence

* add the ranks back
this shows us that our ranking function is working

* add the messages

* remove age rank tests
because goutte doesn't natively interpret html comments

* add github testing badge
since phpunit is no longer run on circle

* add script to maybe skip behat tests if we don't need to run them

* add step to workflow

* do not run if the circle config changes

* also ignore if scripts (that aren't behat-related) have changed

* fix the logic (again)

* one more flippity flip

* remove the "ignoring" message
it's actually implied by the fact that is_ignored is checked

* use function to determine if a file should be ignored

Co-authored-by: Phil Tyler <phil.tyler@pantheon.io>

* update changelog to note mu-plugin updates

* Update tests/phpunit/test-admin-interface.php

* use data providers to simplify the tests

---------

Co-authored-by: Phil Tyler <phil.tyler@pantheon.io>
  • Loading branch information
jazzsequence and pwtyler authored May 17, 2024
1 parent faa6c47 commit 83df364
Show file tree
Hide file tree
Showing 10 changed files with 945 additions and 214 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- image: quay.io/pantheon-public/build-tools-ci:8.x-php8.2
steps:
- checkout
- run:
name: Check if we need to run Behat
command: ./bin/maybe-skip-tests.sh
- restore_cache:
keys:
- test-behat-dependencies-{{ checksum "composer.json" }}
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

**Contributors:** [getpantheon](https://profiles.wordpress.org/getpantheon), [danielbachhuber](https://profiles.wordpress.org/danielbachhuber), [kporras07](https://profiles.wordpress.org/kporras07), [jspellman](https://profiles.wordpress.org/jspellman/), [jazzs3quence](https://profiles.wordpress.org/jazzs3quence/), [ryanshoover](https://profiles.wordpress.org/ryanshoover/), [rwagner00](https://profiles.wordpress.org/rwagner00/), [pwtyler](https://profiles.wordpress.org/pwtyler)
**Tags:** pantheon, cdn, cache
**Requires at least:** 4.7
**Tested up to:** 6.4.3
**Stable tag:** 1.5.0-dev
**Requires at least:** 6.4
**Tested up to:** 6.5.3
**Stable tag:** 2.0.0-dev
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Automatically clear related pages from Pantheon's Edge when you update content. High TTL. Fresh content. Visitors never wait.

## Description ##

[![Actively Maintained](https://img.shields.io/badge/Pantheon-Actively_Maintained-yellow?logo=pantheon&color=FFDC28)](https://pantheon.io/docs/oss-support-levels#actively-maintained-support) [![CircleCI](https://circleci.com/gh/pantheon-systems/pantheon-advanced-page-cache.svg?style=svg)](https://circleci.com/gh/pantheon-systems/pantheon-advanced-page-cache)
[![Actively Maintained](https://img.shields.io/badge/Pantheon-Actively_Maintained-yellow?logo=pantheon&color=FFDC28)](https://pantheon.io/docs/oss-support-levels#actively-maintained-support)
[![Lint and Test](https://github.com/pantheon-systems/pantheon-advanced-page-cache/actions/workflows/lint-test.yml/badge.svg)](https://github.com/pantheon-systems/pantheon-advanced-page-cache/actions/workflows/lint-test.yml)
[![CircleCI](https://circleci.com/gh/pantheon-systems/pantheon-advanced-page-cache.svg?style=svg)](https://circleci.com/gh/pantheon-systems/pantheon-advanced-page-cache)

For sites wanting fine-grained control over how their responses are represented in their edge cache, Pantheon Advanced Page Cache is the golden ticket. Here's a high-level overview of how the plugin works:

Expand Down Expand Up @@ -353,7 +355,10 @@ Pantheon Advanced Page Cache integrates with WordPress plugins, including:
See [CONTRIBUTING.md](https://github.com/pantheon-systems/pantheon-advanced-page-cache/blob/master/CONTRIBUTING.md) for information on contributing.

## Changelog ##
### 1.5.0-dev (March 11, 2024) ###
### 2.0.0-dev ###
* Adds new admin alerts and Site Health tests about default cache max-age settings and recommendations [[#268](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/268)]. The default Pantheon GCDN cache max-age value has been updated to 1 week in the [Pantheon MU plugin](https://github.com/pantheon-systems/pantheon-mu-plugin). For more information, see the [release note](https://docs.pantheon.io/release-notes/2024/04/pantheon-mu-plugin-1-4-0-update).

### 1.5.0 (March 11, 2024) ###
* Adds filter `pantheon_purge_post_type_ignored` to allow an array of post types to ignore before purging cache [[#258](https://github.com/pantheon-systems/pantheon-advanced-page-cache/pull/258)]
* Adds [wpunit-helpers](https://github.com/pantheon-systems/wpunit-helpers) for running/setting up WP Unit tests

Expand Down
52 changes: 52 additions & 0 deletions bin/maybe-skip-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

# Paths to ignore.
ignored_paths=(
.editorconfig
.gitattributes
.gitignore
CODEOWNERS
CONTRIBUTING.md
LICENSE
phpcs.xml.dist
phpunit.xml.dist
README.md
readme.txt
.circleci/config.yml
bin/maybe-skip-tests.sh
bin/helpers.sh
bin/install-local-tests.sh
bin/install-wp-tests.sh
bin/phpunit-test.sh
.wordpress-org/*
.github/*
tests/phpunit/*
)

# Fetch list of changed files from the last commit
changed_files=$(git diff-tree --no-commit-id --name-only -r HEAD)
should_run_tests=true


is_ignored_file(){
for ignore in "${ignored_paths[@]}"; do
if [[ "${1:-}" == "$ignore" ]]; then
return 0
fi
done
return 1
}

for file in $changed_files; do
if ! is_ignored_file "$file"; then
echo "Running tests because $file was changed."
break
fi
should_run_tests=false
echo "Skipping $file..."
done

if [ "$should_run_tests" = false ]; then
echo "Only ignored files modified. Skipping Behat tests."
circleci-agent step halt
fi
Loading

0 comments on commit 83df364

Please sign in to comment.