wordpress-develop/tests/phpunit/tests/post/pings.php
Gary Pendergast 2d6badf6ab Pings: Allow ping functions to accept WP_Post objects as well as post IDs.
This removes the use of several `global $wpdb` instances, as well as bringing the ping functions into line with other post-related functions, which will accept a post ID or `WP_Post` object.

Props dshanke.
Fixes #38202.



git-svn-id: https://develop.svn.wordpress.org/trunk@38852 602fd350-edb4-49c9-b593-d223f7449a82
2016-10-21 05:59:34 +00:00

54 lines
1.9 KiB
PHP

<?php
/**
* @group post
* @group ping
*/
class Tests_Ping_and_Trackback_Sending extends WP_UnitTestCase {
public function test_returns_to_ping_sites_from_post_id() {
$post_id = self::factory()->post->create( array( 'to_ping' => 'http://www.example.com
http://www.otherexample.com' ) );
$this->assertSame( array( 'http://www.example.com', 'http://www.otherexample.com' ), get_to_ping( $post_id ) );
}
public function test_returns_to_ping_sites_from_post_object() {
$post_id = self::factory()->post->create( array( 'to_ping' => 'http://www.example.com
http://www.otherexample.com' ) );
$post = get_post( $post_id );
$this->assertSame( array( 'http://www.example.com', 'http://www.otherexample.com' ), get_to_ping( $post ) );
}
public function test_returns_pinged_sites_from_post_id() {
$post_id = self::factory()->post->create( array( 'pinged' => 'foo bar baz' ) );
$this->assertSame( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) );
}
public function test_returns_pinged_sites_from_post_object() {
$post_id = self::factory()->post->create( array( 'pinged' => 'foo bar baz' ) );
$post = get_post( $post_id );
$this->assertSame( array( 'foo', 'bar', 'baz' ), get_pung( $post ) );
}
public function test_add_ping_with_post_id() {
$post_id = self::factory()->post->create();
add_ping( $post_id, 'foo' );
add_ping( $post_id, 'bar' );
add_ping( $post_id, 'baz' );
$this->assertSame( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) );
}
public function test_add_ping_array_with_post_id() {
$post_id = self::factory()->post->create();
add_ping( $post_id, array( 'foo', 'bar', 'baz' ) );
$this->assertSame( array( 'foo', 'bar', 'baz' ), get_pung( $post_id ) );
}
public function test_add_ping_with_post_object() {
$post_id = self::factory()->post->create();
$post = get_post( $post_id );
add_ping( $post, 'foo' );
$this->assertSame( array( 'foo' ), get_pung( $post_id ) );
}
}