Skip to content

Instantly share code, notes, and snippets.

@msaari
Created November 17, 2019 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaari/0acad41d687bb16c5f22c30ffafb34d9 to your computer and use it in GitHub Desktop.
Save msaari/0acad41d687bb16c5f22c30ffafb34d9 to your computer and use it in GitHub Desktop.
Tests the relevanssi_no_image_attachments function and feature.
<?php
/**
* Tests the relevanssi_no_image_attachments function and feature.
*/
public function test_no_image_attachments() {
$this->delete_all_posts();
$image_attachment = array(
'post_title' => 'cat gif',
'post_mime_type' => 'image/gif',
'post_type' => 'attachment',
'post_status' => 'publish',
);
wp_insert_post( $image_attachment );
$pdf_attachment = array(
'post_title' => 'cat pdf',
'post_mime_type' => 'application/pdf',
'post_type' => 'attachment',
'post_status' => 'publish',
);
wp_insert_post( $pdf_attachment );
update_option( 'relevanssi_index_post_types', array( 'attachment' ) );
update_option( 'relevanssi_index_image_files', 'off' );
$return = relevanssi_build_index( false, null, null, true );
$this->assertEquals(
1,
$return['indexed'],
"With image files excluded, the number of posts indexed isn't correct."
);
update_option( 'relevanssi_index_image_files', 'on' );
$return = relevanssi_build_index( false, null, null, true );
$this->assertEquals(
2,
$return['indexed'],
"With image files included, the number of posts indexed isn't correct."
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment