bobbingwide / dupes

Cater for duplicate slugs in WordPress content
GNU General Public License v2.0
0 stars 0 forks source link

Develop In Situ PHPUnit tests for WordPress TRAC #13459 #1

Open bobbingwide opened 2 years ago

bobbingwide commented 2 years ago

In https://herbmiller.me/requirements-for-permalink-postname/ I've documented my requirements for a permalink structure of /%postname%/.

The above (perma)link applies to both a page and a post.
With the current implementation of WordPress, the page trumps the post, but you can get to read the post since I've fetched the post's contents into the page using a shortcode which accesses the post by its post ID.

This trumping is a bug that was originally reported in #13459 Conflict between post and page slugs/permalinks when permalink setting is set to /%postname%/.

The dupes plugin may eventually include a workaround to the current WordPress issue. In the meantime, we need some automatic tests for a variety of different combinations of permalink structure, post status and CPT combinations.

Requirements

Develop some automated tests for WordPress permalink functionality.

These need to reflect real usage and user's expectations. eg

This first example fails when the user clicks on a link to the post but the page is displayed instead of the post. The second fails when clicking on the image redisplays the post. Expected result: it should lead to the attachment page.

The tests should also test scenarios which currently work. eg.

More advanced tests would cover:

The underlying requirement is, if a user is displayed some content with a link to view more of that content then, when the link is clicked, that content should be displayed. It should not result in different content, a 404 or other unexpected result.

Proposed solution

bobbingwide commented 2 years ago

When run using pu - to invoke PHPUnit under oik-batch for in situ testing - the current output is a below.

C:\apache\htdocs\phpLibraries\phpunit\phpunit-9.5.5.phar
Searching for wp-config.php in directories leading to: C:\apache\htdocs\cwiccer\wp-content\plugins\dupes
Found wp-config.php in: C:\apache\htdocs\cwiccer/
oik-wp running WordPress 5.9.2
C:\apache\htdocs\wordpress\wp-content\plugins\dupes
cli
Using wordpress-develop-tests plugin
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.0.2
Configuration: C:\apache\htdocs\wordpress\wp-content\plugins\dupes\phpunit.xml.dist

.F                                                                  2 / 2 (100%)

Time: 00:04.103, Memory: 50.00 MB

There was 1 failure:

1) Tests_issue_13459::test_duplicate_page_post
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'<p class="duplicate-title-trac-13459">duplicate title TRAC 13459:post:publish:2758</p>'
+'<p class="duplicate-title-trac-13459">duplicate title TRAC 13459:page:publish:2756</p>'

C:\apache\htdocs\wordpress\wp-content\plugins\dupes\tests\test-issue-13459.php:194
C:\apache\htdocs\wordpress\wp-content\plugins\dupes\tests\test-issue-13459.php:249

FAILURES!
Tests: 2, Assertions: 30, Failures: 1.
<!--PHP version:8.0.2
--><!--PHP functions:1271
--><!--User functions:3342
--><!--Classes:1328
--><!--Plugins:1
--><!--Files:1505
--><!--Registered widgets:45
--><!--Post types:14
--><!--Taxonomies:7
--><!--Queries:316
--><!--Query time:0.42538166046143
--><!--Trace file:C:/apache/htdocs/cwiccer/bwtrace/bwtrace.cli
--><!--Trace records:89

The failure was not because the post's permalink was not unique, but because, from the point of view of the requester, the wrong post was returned.

bobbingwide commented 2 years ago