Skip to content

Commit

Permalink
fix: failing tests for WP <6.4
Browse files Browse the repository at this point in the history
Add two new methods in base test case to check WordPress version and mark test skipped for specific versions.
  • Loading branch information
nlemoine committed Jan 26, 2024
1 parent b6be656 commit 02d0882
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
12 changes: 12 additions & 0 deletions tests/Timber_UnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,16 @@ public function restore_themes()
wp_clean_themes_cache();
unset($GLOBALS['wp_themes']);
}

public function isWordPressVersion(string $version, string $operator = '=')
{
return version_compare($GLOBALS['wp_version'], $version, $operator);
}

public function skipForWordpressVersion(string $version, string $operator = '<')
{
if ($this->isWordPressVersion($version, $operator)) {
$this->markTestSkipped("This test requires WordPress version $version or higher.");
}
}
}
37 changes: 19 additions & 18 deletions tests/test-timber-wp-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ public function testFunctionFire()
$this->assertEquals('jared sez hi', $output);
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testFooterOnFooterFW()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}

global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
Expand All @@ -30,11 +31,11 @@ public function testFooterOnFooterFW()
$this->assertSame(0, strlen($wp_footer_output1));
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testFooterAlone()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
Expand All @@ -53,11 +54,11 @@ public function testDoubleAction()
$this->assertEquals('bar', $fw1->call());
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testDoubleActionWPFooter()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}
global $wp_scripts;
$wp_scripts = null;
add_action('wp_footer', 'echo_junk');
Expand All @@ -69,11 +70,11 @@ public function testDoubleActionWPFooter()
remove_action('wp_footer', 'echo_junk');
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testInTwig()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
Expand All @@ -82,11 +83,11 @@ public function testInTwig()
$this->assertGreaterThan(-1, $pos);
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testInTwigString()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('jquery', false, [], false, true);
Expand All @@ -95,11 +96,11 @@ public function testInTwigString()
$this->assertGreaterThan(-1, $pos);
}

/**
* @expectedDeprecated the_block_template_skip_link
*/
public function testAgainstFooterFunctionOutput()
{
if ($this->isWordPressVersion('6.4', '>=')) {
$this->expectDeprecated();
}
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, [], false, true);
Expand Down

0 comments on commit 02d0882

Please sign in to comment.