/** * Test a simple post sync * * @since 0.9 */ public function testPostSync() { $sites = ep_get_sites(); foreach ($sites as $site) { switch_to_blog($site['blog_id']); add_action('ep_sync_on_transition', array($this, 'action_sync_on_transition'), 10, 0); $post_id = epa_create_and_sync_post(); ep_refresh_index(); // $this->assertTrue( ! empty( $this->fired_actions['ep_sync_on_transition'] ) ); $post = ep_get_post($post_id); $this->assertTrue(!empty($post)); $this->fired_actions = array(); restore_current_blog(); } }
/** * Test invalid post date time * * @param array $post_statuses * @return array */ public function testPostInvalidDateTime() { add_filter('ep_indexable_post_status', array($this, 'mock_indexable_post_status'), 10, 1); $post_id = ep_create_and_sync_post(array('post_status' => 'draft')); ep_refresh_index(); ep_sync_post($post_id); wp_cache_flush(); $wp_post = get_post($post_id); $post = ep_get_post($post_id); $invalid_datetime = "0000-00-00 00:00:00"; if ($wp_post->post_date_gmt == $invalid_datetime) { $this->assertNull($post['post_date_gmt']); } if ($wp_post->post_modified_gmt == $invalid_datetime) { $this->assertNull($post['post_modified_gmt']); } $this->assertNotNull($post); remove_filter('ep_indexable_post_status', array($this, 'mock_indexable_post_status'), 10); }
/** * Test that a post being directly deleted gets correctly removed from the Elasticsearch index * * @since 1.2 */ public function testPostForceDelete() { add_action('ep_delete_post', array($this, 'action_delete_post'), 10, 0); $post_id = ep_create_and_sync_post(); ep_refresh_index(); $post = ep_get_post($post_id); // Ensure that our post made it over to elasticsearch $this->assertTrue(!empty($post)); // Let's directly delete the post, bypassing the trash wp_delete_post($post_id, true); ep_refresh_index(); $this->assertTrue(!empty($this->fired_actions['ep_delete_post'])); $post = ep_get_post($post_id); // Alright, now the post has been removed from the index, so this should be empty $this->assertTrue(empty($post)); $post = get_post($post_id); // This post should no longer exist in WP's database $this->assertTrue(empty($post)); $this->fired_actions = array(); }
/** * Test that a post becoming unpublished correctly gets removed from the Elasticsearch index * * @since 0.9.3 */ public function testPostUnpublish() { $sites = ep_get_sites(); foreach ($sites as $site) { switch_to_blog($site['blog_id']); add_action('ep_delete_post', array($this, 'action_delete_post'), 10, 0); $post_id = ep_create_and_sync_post(); ep_refresh_index(); $post = ep_get_post($post_id); // Ensure that our post made it over to elasticsearch $this->assertTrue(!empty($post)); // Let's transition the post status from published to draft wp_update_post(array('ID' => $post_id, 'post_status' => 'draft')); ep_refresh_index(); $this->assertTrue(!empty($this->fired_actions['ep_delete_post'])); $post = ep_get_post($post_id); // Alright, now the post has been removed from the index, so this should be empty $this->assertTrue(empty($post)); $this->fired_actions = array(); restore_current_blog(); } }