Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tests failing since Twig 3.8.0 #2895

Merged
merged 1 commit into from
Jan 26, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/install-wp-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ install_wp() {
tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR
fi

download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
download https://raw.githubusercontent.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php
}

install_test_suite() {
Expand Down
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.");
}
}
}
48 changes: 44 additions & 4 deletions tests/test-timber-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use Timber\Integration\AcfIntegration;
use Timber\Timber;
use Twig\Environment;
use Twig\Error\RuntimeError;

/**
* Class TestTimberMeta
Expand Down Expand Up @@ -618,7 +620,17 @@ public function testMetaDirectAccessProtectedMethodConflict()
*/
public function testPostMetaDirectAccessMethodWithRequiredParametersConflict()
{
$this->expectException(\ArgumentCountError::class);
/**
* Twig 3.8 changed the way some exception are handled and a different exception is thrown.
*
* @see https://github.com/twigphp/Twig/commit/85bf01b4abd4b4ee6f6d1aca19af74189c939d69
*/
if (version_compare(Environment::VERSION, '3.8.0', '>=')) {
$this->expectException(RuntimeError::class);
} else {
$this->expectException(\ArgumentCountError::class);
}

$post_id = $this->factory->post->create();

update_post_meta($post_id, 'public_method_with_args', 'I am a meta value');
Expand All @@ -641,7 +653,17 @@ public function testPostMetaDirectAccessMethodWithRequiredParametersConflict()
*/
public function testTermMetaDirectAccessMethodWithRequiredParametersConflict()
{
$this->expectException(\ArgumentCountError::class);
/**
* Twig 3.8 changed the way some exceptions are handled and a different exception is thrown.
*
* @see https://github.com/twigphp/Twig/commit/85bf01b4abd4b4ee6f6d1aca19af74189c939d69
*/
if (version_compare(Environment::VERSION, '3.8.0', '>=')) {
$this->expectException(RuntimeError::class);
} else {
$this->expectException(\ArgumentCountError::class);
}

$term_id = $this->factory->term->create();

update_term_meta($term_id, 'public_method_with_args', 'I am a meta value');
Expand All @@ -666,7 +688,16 @@ public function testTermMetaDirectAccessMethodWithRequiredParametersConflict()
*/
public function testUserMetaDirectAccessMethodWithRequiredParametersConflict()
{
$this->expectException(\ArgumentCountError::class);
/**
* Twig 3.8 changed the way some exceptions are handled and a different exception is thrown.
*
* @see https://github.com/twigphp/Twig/commit/85bf01b4abd4b4ee6f6d1aca19af74189c939d69
*/
if (version_compare(Environment::VERSION, '3.8.0', '>=')) {
$this->expectException(RuntimeError::class);
} else {
$this->expectException(\ArgumentCountError::class);
}

$user_id = $this->factory->user->create();

Expand All @@ -693,7 +724,16 @@ public function testUserMetaDirectAccessMethodWithRequiredParametersConflict()
*/
public function testCommentMetaDirectAccessMethodWithRequiredParametersConflict()
{
$this->expectException(\ArgumentCountError::class);
/**
* Twig 3.8 changed the way some exceptions are handled and a different exception is thrown.
*
* @see https://github.com/twigphp/Twig/commit/85bf01b4abd4b4ee6f6d1aca19af74189c939d69
*/
if (version_compare(Environment::VERSION, '3.8.0', '>=')) {
$this->expectException(RuntimeError::class);
} else {
$this->expectException(\ArgumentCountError::class);
}

$post_id = $this->factory->post->create();
$comment_id = $this->factory->comment->create([
Expand Down
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->setExpectedDeprecated('the_block_template_skip_link');
}

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->setExpectedDeprecated('the_block_template_skip_link');
}
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->setExpectedDeprecated('the_block_template_skip_link');
}
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->setExpectedDeprecated('the_block_template_skip_link');
}
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->setExpectedDeprecated('the_block_template_skip_link');
}
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->setExpectedDeprecated('the_block_template_skip_link');
}
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, [], false, true);
Expand Down