Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/fixtures/themes/saddle-classic-fixture/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* The one template a classic theme must have. Its existence (and the absence
* of templates/index.html + theme.json) is what makes wp_is_block_theme()
* return false, which is the only thing the test suite needs from it.
*
* @package Saddle
*/

get_header();
the_post();
the_content();
get_footer();
13 changes: 13 additions & 0 deletions tests/fixtures/themes/saddle-classic-fixture/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
Theme Name: Saddle Classic Fixture
Theme URI: https://plugpress.co/saddle/
Author: PlugPress
Description: A minimal classic (PHP-template) theme used only by Saddle's test suite. CI provisions a fresh WordPress core whose bundled themes are all block themes, so without this fixture the classic-theme branches of the playbook can never be exercised there — they passed locally only because the developer's host install happened to run a classic theme.
Version: 1.0.0
Requires at least: 6.9
Tested up to: 7.0
Requires PHP: 7.4
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: saddle-classic-fixture
*/
89 changes: 78 additions & 11 deletions tests/skills-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,55 @@ private function builtin_names() {
}

/**
* The test site runs a CLASSIC theme, which is exactly the case the old
* wp_is_block_theme() gate excluded — so a classic site with no builder,
* the one with no site editor to fall back on, got no playbook at all.
* Run assertions with a fixture theme active, then put the host theme back.
*
* The theme in force during a test is an environment fact, not a fixture:
* the harness symlinks wp-content/themes from whichever WordPress it was
* pointed at. On the developer's host that happens to be a classic theme;
* CI provisions a fresh core whose bundled themes are ALL block themes. A
* test that assumes either one passes on one machine and fails on the other
* (#145), so anything that branches on wp_is_block_theme() switches to the
* fixture it means, explicitly, the way site-editor-test.php already does.
*
* @param string $slug 'saddle-classic-fixture' or 'saddle-block-fixture'.
* @param callable $fn Assertions.
*/
private function with_theme( $slug, callable $fn ) {
$previous = get_stylesheet();

register_theme_directory( __DIR__ . '/fixtures/themes' );
delete_site_transient( 'theme_roots' );
wp_clean_themes_cache();

$this->assertTrue( wp_get_theme( $slug )->exists(), "Fixture theme {$slug} is missing from tests/fixtures/themes." );
switch_theme( $slug );

try {
$fn();
} finally {
if ( get_stylesheet() !== $previous ) {
switch_theme( $previous );
}
}
}

/**
* A classic theme is exactly the case the old wp_is_block_theme() gate
* excluded — so a classic site with no builder, the one with no site editor
* to fall back on, got no playbook at all.
*/
public function test_the_playbooks_ship_on_a_classic_theme_with_no_builder() {
$this->with_no_foreign_builder(
$this->with_theme(
'saddle-classic-fixture',
function () {
$names = $this->builtin_names();
$this->with_no_foreign_builder(
function () {
$names = $this->builtin_names();

$this->assertContains( 'build-page', $names );
$this->assertContains( 'fix-page', $names );
$this->assertContains( 'build-page', $names );
$this->assertContains( 'fix-page', $names );
}
);
}
);
}
Expand Down Expand Up @@ -381,12 +419,41 @@ function () {
* not send the agent after get-template — it would be refused.
*/
public function test_the_playbook_adapts_step_two_to_a_classic_theme() {
$this->with_no_foreign_builder(
$this->with_theme(
'saddle-classic-fixture',
function () {
$this->assertFalse( wp_is_block_theme(), 'The classic fixture must not read as a block theme.' );

$this->with_no_foreign_builder(
function () {
$body = Saddle_Skills::find( 'build-page' )['body'];

$this->assertStringContainsString( 'classic theme', $body );
$this->assertStringNotContainsString( 'saddle/get-template on the header', $body );
}
);
}
);
}

/**
* The other branch, pinned for the same reason: a block theme has header
* and footer parts Saddle CAN read, so step 2 sends the agent to them.
*/
public function test_the_playbook_sends_step_two_to_the_template_parts_on_a_block_theme() {
$this->with_theme(
'saddle-block-fixture',
function () {
$body = Saddle_Skills::find( 'build-page' )['body'];
$this->assertTrue( wp_is_block_theme(), 'The block fixture must read as a block theme.' );

$this->with_no_foreign_builder(
function () {
$body = Saddle_Skills::find( 'build-page' )['body'];

$this->assertStringContainsString( 'classic theme', $body );
$this->assertStringNotContainsString( 'saddle/get-template on the header', $body );
$this->assertStringContainsString( 'saddle/get-template on the header', $body );
$this->assertStringNotContainsString( 'this is a classic theme', $body );
}
);
}
);
}
Expand Down
Loading