Skip to content

Commit

Permalink
unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pschoffer committed Jun 30, 2022
1 parent 1b73a2e commit 964292a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions includes/classes/Indexable/Post/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,11 @@ protected function get_term_order( $term_taxonomy_id, $object_id ) {
}

/**
* Chekcs if meta key is allowed
* Checks if meta key is allowed
*
* @param string $meta_key meta key to check
* @param WP_Post $post Post object
* @since 3.6.6
* @since 4.3.0
* @return boolean
*/
public function is_meta_allowed( $meta_key, $post ) {
Expand All @@ -813,7 +813,7 @@ public function is_meta_allowed( $meta_key, $post ) {
*
* @param array $metas Key => value pairs of post meta
* @param WP_Post $post Post object
* @since 3.6.6
* @since 4.3.0
* @return array
*/
public function filter_allowed_metas( $metas, $post ) {
Expand Down
28 changes: 28 additions & 0 deletions tests/php/indexables/TestPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -6867,4 +6867,32 @@ public function testMetaWithoutValue() {
$this->assertEquals( $expected_result, $query->post_count );

}

/**
* Tests is_meta_allowed
*
* @return void
* @group is_meta_allowed
*/
public function testIsMetaAllowed() {
$meta_not_protected = 'meta';
$meta_not_protected_excluded = 'meta_excluded';
$meta_protected = '_meta';
$meta_protected_allowed = '_meta_allowed';

add_filter( 'ep_prepare_meta_allowed_protected_keys', function () use ( $meta_protected_allowed ) {
return [ $meta_protected_allowed ];
} );
add_filter( 'ep_prepare_meta_excluded_public_keys', function () use ( $meta_protected_allowed ) {
return [ $meta_protected_allowed ];
} );

$indexable = \ElasticPress\Indexables::factory()->get( 'post' );

$this->assertTrue( $indexable->is_meta_allowed( $meta_not_protected, null ) );
$this->assertTrue( $indexable->is_meta_allowed( $meta_protected_allowed, null ) );

$this->assertFalse( $indexable->is_meta_allowed( $meta_not_protected_excluded, null ) );
$this->assertFalse( $indexable->is_meta_allowed( $meta_protected, null ) );
}
}

0 comments on commit 964292a

Please sign in to comment.