From 16e0cc873b3a35546f2d496e739c209e9129069e Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 29 Sep 2015 04:02:00 +0000 Subject: [PATCH] Add unit tests for `post_exists()`. Props MikeHansenMe. See #34012. git-svn-id: https://develop.svn.wordpress.org/trunk@34680 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/admin/includesPost.php | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index feafbacadf..1336305c1c 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -525,4 +525,77 @@ class Tests_Admin_includesPost extends WP_UnitTestCase { $wp_rewrite->set_permalink_structure( '' ); flush_rewrite_rules(); } + + public function test_post_exists_should_match_title() { + $p = $this->factory->post->create( array( + 'post_title' => 'Foo Bar', + ) ); + + $this->assertSame( $p, post_exists( 'Foo Bar' ) ); + } + + public function test_post_exists_should_not_match_nonexistent_title() { + $p = $this->factory->post->create( array( + 'post_title' => 'Foo Bar', + ) ); + + $this->assertSame( 0, post_exists( 'Foo Bar Baz' ) ); + } + + public function test_post_exists_should_match_nonempty_content() { + $title = 'Foo Bar'; + $content = 'Foo Bar Baz'; + $p = $this->factory->post->create( array( + 'post_title' => $title, + 'post_content' => $content, + ) ); + + $this->assertSame( $p, post_exists( $title, $content ) ); + } + + public function test_post_exists_should_not_match_when_nonempty_content_doesnt_match() { + $title = 'Foo Bar'; + $content = 'Foo Bar Baz'; + $p = $this->factory->post->create( array( + 'post_title' => $title, + 'post_content' => $content . ' Quz', + ) ); + + $this->assertSame( 0, post_exists( $title, $content ) ); + } + + public function test_post_exists_should_match_nonempty_date() { + $title = 'Foo Bar'; + $date = '2014-05-08 12:00:00'; + $p = $this->factory->post->create( array( + 'post_title' => $title, + 'post_date' => $date, + ) ); + + $this->assertSame( $p, post_exists( $title, '', $date ) ); + } + + public function test_post_exists_should_not_match_when_nonempty_date_doesnt_match() { + $title = 'Foo Bar'; + $date = '2014-05-08 12:00:00'; + $p = $this->factory->post->create( array( + 'post_title' => $title, + 'post_date' => '2015-10-10 00:00:00', + ) ); + + $this->assertSame( 0, post_exists( $title, '', $date ) ); + } + + public function test_post_exists_should_match_nonempty_title_content_and_date() { + $title = 'Foo Bar'; + $content = 'Foo Bar Baz'; + $date = '2014-05-08 12:00:00'; + $p = $this->factory->post->create( array( + 'post_title' => $title, + 'post_content' => $content, + 'post_date' => $date, + ) ); + + $this->assertSame( $p, post_exists( $title, $content, $date ) ); + } }