/** * Setup each test. * * @since 0.1.0 */ public function setUp() { global $wpdb; parent::setUp(); $wpdb->suppress_errors(); $admin_id = $this->factory->user->create(array('role' => 'administrator')); $this->factory->blog->create_many(2, array('user_id' => $admin_id)); $sites = ep_get_sites(); $indexes = array(); foreach ($sites as $site) { switch_to_blog($site['blog_id']); ep_delete_index(); ep_put_mapping(); $indexes[] = ep_get_index_name(); restore_current_blog(); } ep_delete_network_alias(); ep_create_network_alias($indexes); wp_set_current_user($admin_id); EP_WP_Query_Integration::factory()->setup(); $this->setup_test_post_type(); /** * Most of our search test are bundled into core tests for legacy reasons */ ep_activate_module('search'); EP_Modules::factory()->setup_modules(); }
/** * Test case for when index is deleted, request for Elasticsearch should fall back to WP Query */ public function testSearchIndexDeleted() { global $wpdb; ep_activate_module('search'); EP_Modules::factory()->setup_modules(); $post_ids = array(); ep_create_and_sync_post(); ep_create_and_sync_post(); ep_create_and_sync_post(array('post_content' => 'findme')); ep_refresh_index(); add_action('ep_wp_query_search', array($this, 'action_wp_query_search'), 10, 0); $args = array('s' => 'findme'); $query = new WP_Query($args); $this->assertTrue("SELECT * FROM {$wpdb->posts} WHERE 1=0" == $query->request); ep_delete_index(); $query = new WP_Query($args); $this->assertTrue("SELECT * FROM {$wpdb->posts} WHERE 1=0" != $query->request); }
/** * Test setup modules * * @since 2.1 */ public function testSetupModules() { ep_register_module('test', array('title' => 'Test')); ep_activate_module('test'); $module = ep_get_registered_module('test'); $this->assertTrue(!empty($module)); $this->assertTrue(!$module->is_active()); EP_Modules::factory()->setup_modules(); $this->assertTrue($module->is_active()); }
/** * Test search integration is on in general * * @since 2.1 * @group woocommerce */ public function testSearchOnAllFrontEnd() { ep_activate_module('woocommerce'); EP_Modules::factory()->setup_modules(); add_action('ep_wp_query_search', array($this, 'action_wp_query_search'), 10, 0); $args = array('s' => 'findme'); $query = new WP_Query($args); $this->assertTrue(!empty($this->fired_actions['ep_wp_query_search'])); }
/** * Check posts filter by category in dashboard */ public function testAdminCategories() { set_current_screen('edit.php'); ep_activate_module('admin'); EP_Modules::factory()->setup_modules(); $cat1 = wp_create_category('category one'); $cat2 = wp_create_category('category two'); ep_create_and_sync_post(array('post_category' => array($cat1))); ep_create_and_sync_post(array('post_category' => array($cat2))); ep_create_and_sync_post(array('post_category' => array($cat1))); ep_refresh_index(); add_action('ep_wp_query_search', array($this, 'action_wp_query_search'), 10, 0); $query = new WP_Query(); global $wp_the_query; $wp_the_query = $query; $args = array('category_name' => 'category one'); $query->query($args); $this->assertTrue(!empty($this->fired_actions['ep_wp_query_search'])); $this->assertEquals(2, $query->post_count); $this->assertEquals(2, $query->found_posts); }
/** * Test for related post args filter */ public function testFindRelatedPostFilter() { $post_id = ep_create_and_sync_post(array('post_content' => 'findme test 1')); ep_create_and_sync_post(array('post_content' => 'findme test 2')); ep_create_and_sync_post(array('post_content' => 'findme test 3', 'post_type' => 'page')); ep_refresh_index(); ep_activate_module('related_posts'); EP_Modules::factory()->setup_modules(); add_filter('ep_find_related_args', array($this, 'find_related_posts_filter'), 10, 1); $related = ep_find_related($post_id); $this->assertEquals(2, sizeof($related)); remove_filter('ep_find_related_args', array($this, 'find_related_posts_filter')); $related = ep_find_related($post_id); $this->assertEquals(3, sizeof($related)); }