Skip to content

Commit

Permalink
Rename function to keep consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
leogermani committed Mar 20, 2020
1 parent 1e163aa commit c13c629
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
24 changes: 20 additions & 4 deletions modules/videopress/utility-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ function video_format_done( $info, $format ) {
*/
function video_image_url_by_guid( $guid, $format ) {

$post = video_get_post_by_guid( $guid );
$post = videopress_get_post_by_guid( $guid );

if ( is_wp_error( $post ) ) {
return null;
Expand All @@ -639,11 +639,11 @@ function video_image_url_by_guid( $guid, $format ) {
/**
* Using a GUID, find a post.
*
* @param string $guid
* @param string $guid The post guid.
* @return WP_Post|false The post for that guid, or false if none is found.
*/
function video_get_post_by_guid( $guid ) {
$cache_key = 'video_get_post_by_guid_' . $guid;
function videopress_get_post_by_guid( $guid ) {
$cache_key = 'get_post_by_guid_' . $guid;
$cache_group = 'videopress';
$cached_post = wp_cache_get( $cache_key, $cache_group );

Expand All @@ -663,6 +663,22 @@ function video_get_post_by_guid( $guid ) {
return false;
}

/**
* Using a GUID, find a post.
*
* Kept for backward compatibility. Use videopress_get_post_by_guid() instead.
*
* @deprecated since 8.4.0
* @see videopress_get_post_by_guid()
*
* @param string $guid The post guid.
* @return WP_Post|false The post for that guid, or false if none is found.
*/
function video_get_post_by_guid( $guid ) {
_deprecated_function( __FUNCTION__, 'jetpack-8.4' );
return videopress_get_post_by_guid( $guid );
}

/**
* Using a GUID, find the associated post ID.
*
Expand Down
36 changes: 18 additions & 18 deletions tests/php/modules/videopress/test_functions.utility-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class WP_Test_Jetpack_VideoPress_Utility_Functions extends WP_UnitTestCase {
/**
* Tests a helper function to get the post by guid, when there is no post found.
*
* @covers ::video_get_post_by_guid
* @covers ::videopress_get_post_by_guid
* @since 8.4.0
*/
public function test_no_post_found_video_get_post_by_guid() {
$this->assertFalse( video_get_post_by_guid( wp_generate_uuid4() ) );
public function test_no_post_found_videopress_get_post_by_guid() {
$this->assertFalse( videopress_get_post_by_guid( wp_generate_uuid4() ) );
}

/**
* Gets the test data for test_non_cached_video_get_post_by_guid().
* Gets the test data for test_non_cached_videopress_get_post_by_guid().
*
* @since 8.4.0
*
Expand All @@ -34,7 +34,7 @@ public function get_data_test_video_non_cached() {
'external_object_cache_is_enabled' => array(
'wp_cache_get',
true,
'video_get_post_by_guid_',
'get_post_by_guid_',
'videopress',
),
'external_object_cache_is_not_enabled' => array(
Expand All @@ -49,19 +49,19 @@ public function get_data_test_video_non_cached() {
* Tests a helper function to get the post by guid, when there's initially no cached value.
*
* @dataProvider get_data_test_video_non_cached
* @covers ::video_get_post_by_guid
* @covers ::videopress_get_post_by_guid
* @since 8.4.0
*
* @param callable $callback The callback to get the caching.
* @param bool $should_cache_object Whether the entire WP_Post should be cached, or simply the post ID.
* @param string $cache_key_base The base of the cache key.
* @param string|null $cache_group The cache group, if any.
*/
public function test_non_cached_video_get_post_by_guid( $callback, $should_cache_object, $cache_key_base, $cache_group = null ) {
public function test_non_cached_videopress_get_post_by_guid( $callback, $should_cache_object, $cache_key_base, $cache_group = null ) {
$guid = wp_generate_uuid4();
$expected_id = videopress_create_new_media_item( 'Example', $guid );
$expected_post = get_post( $expected_id );
$actual_post = video_get_post_by_guid( $guid );
$actual_post = videopress_get_post_by_guid( $guid );

$this->assertEquals( $expected_post, $actual_post );

Expand All @@ -79,7 +79,7 @@ public function test_non_cached_video_get_post_by_guid( $callback, $should_cache
}

/**
* Gets the test data for test_cached_video_get_post_by_guid().
* Gets the test data for test_cached_videopress_get_post_by_guid().
*
* @since 8.4.0
*
Expand All @@ -106,19 +106,19 @@ public function get_data_test_video_cached() {
* this should return that instead of instantiating WP_Query.
*
* @dataProvider get_data_test_video_cached
* @covers ::video_get_post_by_guid
* @covers ::videopress_get_post_by_guid
* @since 8.4.0
*
* @param callable $callback The callback to set the caching.
* @param bool $should_cache_object Whether the entire WP_Post should be cached, or simply the post ID.
* @param string|null $cache_group The cache group, if any.
*/
public function test_cached_video_get_post_by_guid( $callback, $should_cache_object, $cache_group = null ) {
public function test_cached_videopress_get_post_by_guid( $callback, $should_cache_object, $cache_group = null ) {
$guid = wp_generate_uuid4();
$attachment_id = videopress_create_new_media_item( 'Example Title', $guid );
$attachment_post = get_post( $attachment_id );
$post_to_cache = $should_cache_object ? $attachment_post : $attachment_id;
$caching_args = array( 'video_get_post_by_guid_' . $guid, $post_to_cache );
$caching_args = array( 'get_post_by_guid_' . $guid, $post_to_cache );

if ( $cache_group ) {
$caching_args[] = $cache_group;
Expand All @@ -129,12 +129,12 @@ public function test_cached_video_get_post_by_guid( $callback, $should_cache_obj
// This should always return the WP_Post, even though the post ID is stored in the transient.
$this->assertEquals(
$attachment_post,
video_get_post_by_guid( $guid )
videopress_get_post_by_guid( $guid )
);
}

/**
* Gets the test data for test_cached_invalid_video_get_post_by_guid().
* Gets the test data for test_cached_invalid_videopress_get_post_by_guid().
*
* @since 8.4.0
*
Expand All @@ -156,20 +156,20 @@ public function get_data_cached_invalid() {
* the tested method should ignore it and query for the post.
*
* @dataProvider get_data_cached_invalid
* @covers ::video_get_post_by_guid
* @covers ::videopress_get_post_by_guid
* @since 8.4.0
*
* @param mixed $invalid_cached_value A cached value that should be ignored.
*/
public function test_cached_invalid_video_get_post_by_guid( $invalid_cached_value ) {
public function test_cached_invalid_videopress_get_post_by_guid( $invalid_cached_value ) {
$guid = wp_generate_uuid4();
$attachment_id = videopress_create_new_media_item( 'Example Title', $guid );

wp_cache_set( 'video_get_post_by_guid_' . $guid, $invalid_cached_value, 'videopress' );
wp_cache_set( 'get_post_by_guid_' . $guid, $invalid_cached_value, 'videopress' );

$this->assertEquals(
get_post( $attachment_id ),
video_get_post_by_guid( $guid )
videopress_get_post_by_guid( $guid )
);
}

Expand Down

0 comments on commit c13c629

Please sign in to comment.