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
4 changes: 0 additions & 4 deletions plugins/faustwp/includes/graphql/callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ function templates_resolver( $root, $args, AppContext $context, ResolveInfo $inf
}

if ( $template ) {
if ( 'is_attachment' === $tag ) {
remove_filter( 'the_content', 'prepend_attachment' );
}

break;
}
}
Expand Down
29 changes: 29 additions & 0 deletions plugins/faustwp/tests/integration/GraphQLCallbacksTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use function WPE\FaustWP\GraphQL\{
filter_introspection,
templates_resolver,
};

class GraphQLCallbacksTests extends \WP_UnitTestCase {
Expand Down Expand Up @@ -197,6 +198,34 @@ public function test_filter_introspection_returns_on_when_faust_secret_key_is_pr
remove_filter( 'faustwp_get_setting', [ $this, 'filter_secret_key' ] );
}

/**
* Tests templates_resolver() leaves the_content alone when it finds an attachment template.
*/
public function test_templates_resolver_keeps_prepend_attachment_for_attachments(): void {
$attachment_id = self::factory()->attachment->create_object(
'image.jpg',
0,
[
'post_mime_type' => 'image/jpeg',
'post_status' => 'inherit',
]
);
$this->go_to( get_attachment_link( $attachment_id ) );

// The test theme has no attachment template.
add_filter(
'attachment_template',
static function () {
return __FILE__;
}
);

$templates = templates_resolver( [], [], new \WPGraphQL\AppContext(), $this->createMock( \GraphQL\Type\Definition\ResolveInfo::class ) );

self::assertContains( 'attachment', $templates );
self::assertSame( 10, has_filter( 'the_content', 'prepend_attachment' ) );
}

/**
* Filters the secret key value for testing.
*
Expand Down
Loading