Skip to content

tests: add PHPUnit tests for Free/Pro template path resolution#260

Merged
nk-o merged 1 commit intomasterfrom
tests/template-path-resolution
Mar 4, 2026
Merged

tests: add PHPUnit tests for Free/Pro template path resolution#260
nk-o merged 1 commit intomasterfrom
tests/template-path-resolution

Conversation

@Fellan-91
Copy link
Collaborator

Summary

Adds comprehensive PHPUnit tests verifying template path resolution works correctly for both Free and Pro plugin scenarios.

This prevents regressions like the critical bug where Quick View / Quick Frame templates failed to load when the Pro plugin was installed due to incorrect template path initialization.

Problem

When the Pro plugin was active, templates from pro_plugin_path/templates/ (e.g. popup/quick-view-data) were not being found by the template loader. This caused Quick View to stop working entirely. The root cause was related to path initialization and the is_allowed_template_path() security guard.

Test Coverage

The new test class Test_Class_Templates_Path (17 tests, ~575 lines) covers:

Free Plugin Only

  • ✅ Free templates resolve to plugin_path/templates/
  • find_template_styles() resolves CSS from the free plugin

Pro Plugin Active

  • ✅ Pro-only templates load from pro_plugin_path/templates/
  • ✅ Pro-only deeper nested templates (items-style) load correctly
  • ✅ Free templates still accessible when Pro is active
  • ✅ Pro templates override Free templates with the same name

Security (is_allowed_template_path)

  • ✅ Pro template paths are in the allowed directories
  • ✅ Random external paths are rejected
  • ✅ Free plugin templates are always allowed

CSS Resolution

  • find_template_styles() finds Pro CSS files
  • ✅ Falls back to Free CSS when Pro doesn't override

Critical Regression Tests

  • Quick View template loads when Pro is active
  • Quick Frame template loads when Pro is active

Edge Cases

  • ✅ Fallback to Free when Pro templates/ directory is missing
  • ✅ Trailing slash normalization in pro_plugin_path
  • ✅ Nonexistent templates produce no output and no errors
  • ✅ Multiple Pro templates load sequentially without conflict
  • pro_plugin_path construction has correct trailing slash

How It Works

Tests simulate the Pro plugin by creating a temporary directory structure with template files, and setting visual_portfolio()->pro_plugin_path to point at it. This exercises the exact same code paths used in production without requiring the actual Pro plugin to be installed.

Test Results

All 64 tests pass (including 17 new ones), 164 assertions total.

@nk-o nk-o merged commit 20e332b into master Mar 4, 2026
10 checks passed
@nk-o nk-o deleted the tests/template-path-resolution branch March 4, 2026 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants