Palindrome Notify
Show a notification on a post when the title is a palindrome.
by Sal Ferrarello · github.com/salcode/palindrome-notify · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/salcode/palindrome-notify/archive/refs/heads/main.zipWordPress plugin to display an alert on the page when the title is a palindrome.
This plugin was originally created as part of Sal Ferrarello's WordCamp Montclair 2024 talk Introduction to Unit Tests.
See PR #1 Add Palindrome alert, which adds the original code that provides this functionality.
How to Run the Unit Tests for this Plugin
This plugin includes multiple ways to run unit tests. In an actual project you would only choose one of these methods. All were added for instructional purposes.
In increasing order of complexity:
1. Override the Content of Posts on Webpages
In the root file palindrome-notify.php uncomment the line
// include __DIR__ . '/tests/webpage-test-is-palindrome.php';
Now when you visit any blog post on your site, the content will be replaced with the results of the unit tests.
Remember to comment out this line when you are done running the tests.
See PR #2 Add webpage unit tests, which adds the original tests.
See PR #3 Fix Bug with "Anna" not Recognized as Palindrome, which adds a new test that highlights a bug around the word "Anna" and fixes the bug.
See PR #4 Fix Bug where Palindromes with Spaces are Not Recognized, which adds a new test that highlights a bug around the phrase "Never odd or even" and fixes the bug.
See PR #5 Fix Bug where Palindromes with Punctuation are Not Recognized, which adds a new test that highlights a bug around the phrase "Go hang a salami, I'm a lasagna hog." and fixes the bug.
2. Run Unit Tests from the Command Line
From the root directory of the plugin, run the following command from the command line to run generic PHP code that has been added to this plugin.
php tests/cli-test-is-palindrome.php
See PR #6 Add Command Line Interface (CLI) tests that introduces these CLI tests.
3. Run Unit Tests from the Command Line with the PHPUnit Framework
PHPUnit is a testing framework for PHP. To run these tests you need to first
Setup
While PHPUnit can be installed directly on your machine, in my experience it is preferable to install it as part of your project as a DEV dependency using Composer because over time it is likely you'll have different projects using different versions of PHPUnit.
If you're new to Composer, you'll want to check out the Composer documentation on Getting Started.
Because PHPUnit has been defined as a dev dependency in composer.json, you'll install PHPUnit by running the following from the command line from the root directory of the plugin.
composer install
Run the PHPUnit Tests
We'll run the version of PHPUnit installed by Composer with the following from the command line
./vendor/bin/phpunit
PHPUnit knows where to look for the relevant code based on the phpunit.xml.dist file we've added to the root directory of the plugin.
See PR #7 Add PHPUnit tests that introduces these PHPUnit tests.