From 3e0721eb5d64ef49b5e2d99f22195af8aef0fcb8 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 24 Dec 2020 15:43:29 +0100 Subject: Post-initial commit --- tests/test-adjacent-post-order.php | 76 ++++++++++++++++++++++++++++++++++++++ tests/test-post-order.php | 10 +++-- 2 files changed, 82 insertions(+), 4 deletions(-) create mode 100644 tests/test-adjacent-post-order.php (limited to 'tests') diff --git a/tests/test-adjacent-post-order.php b/tests/test-adjacent-post-order.php new file mode 100644 index 0000000..80939cf --- /dev/null +++ b/tests/test-adjacent-post-order.php @@ -0,0 +1,76 @@ +factory()->post->create(); + update_post_meta( $id, Draggable_Post_Order::$meta_key, $i ); + + $this->test_posts[] = get_post( $id ); + } + + // since tests are loaded after init, run init manually. + Draggable_Post_Order::init(); + } + + /** + * Test previous and next post with creation order + */ + public function test_previous_next_post_creation_order() { + $first = $this->test_posts[0]; + $second = $this->test_posts[1]; + $third = $this->test_posts[2]; + + $this->go_to( '/?p=' . $second->ID ); + + $this->assertEquals( $first->ID, get_previous_post()->ID ); + $this->assertEquals( $third->ID, get_next_post()->ID ); + } + + /** + * Test previous and next post jumbled order + */ + public function test_previous_next_post_jumbled_order() { + $first = $this->test_posts[1]; + $second = $this->test_posts[2]; + $third = $this->test_posts[0]; + + update_post_meta( $first->ID, Draggable_Post_Order::$meta_key, 1 ); + update_post_meta( $second->ID, Draggable_Post_Order::$meta_key, 2 ); + update_post_meta( $third->ID, Draggable_Post_Order::$meta_key, 3 ); + + // test whether the key was set properly. + $this->assertEquals( 2, get_post_meta( $second->ID, Draggable_Post_Order::$meta_key, true ) ); + + $this->go_to( '/?p=' . $second->ID ); + + $this->assertEquals( $first->ID, get_previous_post()->ID ); + $this->assertEquals( $third->ID, get_next_post()->ID ); + } +} diff --git a/tests/test-post-order.php b/tests/test-post-order.php index b5b26c7..7aa0be4 100644 --- a/tests/test-post-order.php +++ b/tests/test-post-order.php @@ -5,6 +5,8 @@ * @package DraggablePostOrder */ +use Draggable_Post_Order\Draggable_Post_Order; + /** * Sample test case. */ @@ -26,13 +28,13 @@ class TestPostOrder extends WP_UnitTestCase { $this->test_post_type = register_post_type( 'test', [ - 'supports' => [ 'draggable-post-order' ], + 'supports' => [ Draggable_Post_Order::$post_type_feature ], 'has_archive' => true, ] ); // since tests are loaded after init, run init manually. - \Draggable_Post_Order\Draggable_Post_Order::init(); + Draggable_Post_Order::init(); } /** @@ -45,12 +47,12 @@ class TestPostOrder extends WP_UnitTestCase { $meta_sub_query = [ 'relation' => 'OR', 'draggable-post-order-clause' => [ - 'key' => 'draggable-post-order', + 'key' => Draggable_Post_Order::$meta_key, 'type' => 'NUMERIC', ], // get all posts without the meta as well. 'draggable-post-order-exists-clause' => [ - 'key' => 'draggable-post-order', + 'key' => Draggable_Post_Order::$meta_key, 'compare' => 'NOT EXISTS', ], ]; -- cgit v1.2.3