mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Props johnbillion, jrf, SergeyBiryukov. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
88 lines
2.0 KiB
PHP
88 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* @group link
|
|
* @covers ::get_preview_post_link
|
|
*/
|
|
class Tests_Link_GetPreviewPostLink extends WP_UnitTestCase {
|
|
|
|
public function test_get_preview_post_link() {
|
|
$post = self::factory()->post->create();
|
|
|
|
$this->assertSame( add_query_arg( 'preview', 'true', get_permalink( $post ) ), get_preview_post_link( $post ) );
|
|
}
|
|
|
|
public function test_get_preview_post_link_should_add_additional_query_vars() {
|
|
$post = self::factory()->post->create();
|
|
|
|
$expected = add_query_arg(
|
|
array(
|
|
'foo' => 'bar',
|
|
'bar' => 'baz',
|
|
'preview' => 'true',
|
|
),
|
|
get_permalink( $post )
|
|
);
|
|
|
|
$this->assertSame(
|
|
$expected,
|
|
get_preview_post_link(
|
|
$post,
|
|
array(
|
|
'foo' => 'bar',
|
|
'bar' => 'baz',
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
public function test_get_preview_post_link_should_use_custom_base_preview_link() {
|
|
$post = self::factory()->post->create();
|
|
|
|
$expected = 'https://google.com/?foo=bar&bar=baz&preview=true';
|
|
|
|
$this->assertSame(
|
|
$expected,
|
|
get_preview_post_link(
|
|
$post,
|
|
array(
|
|
'foo' => 'bar',
|
|
'bar' => 'baz',
|
|
),
|
|
'https://google.com/'
|
|
)
|
|
);
|
|
}
|
|
|
|
public function test_get_preview_post_link_should_return_null_for_non_existent_post() {
|
|
$this->assertNull( get_preview_post_link() );
|
|
$this->assertNull( get_preview_post_link( 9999 ) );
|
|
$this->assertNull( get_preview_post_link( 'foo' ) );
|
|
}
|
|
|
|
public function test_get_preview_post_link_for_global_post() {
|
|
$post = self::factory()->post->create_and_get();
|
|
|
|
$GLOBALS['post'] = $post;
|
|
|
|
$this->assertSame( add_query_arg( 'preview', 'true', get_permalink( $post ) ), get_preview_post_link() );
|
|
}
|
|
|
|
public function test_get_preview_post_link_should_return_empty_string_for_non_viewable_post_type() {
|
|
$post_type = register_post_type(
|
|
'non_viewable_cpt',
|
|
array(
|
|
'public' => false,
|
|
)
|
|
);
|
|
|
|
$post = self::factory()->post->create(
|
|
array(
|
|
'post_type' => $post_type->name,
|
|
)
|
|
);
|
|
|
|
$this->assertSame( '', get_preview_post_link( $post ) );
|
|
}
|
|
|
|
}
|