/** * 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()); }
/** * List modules (either active or all) * * @synopsis [--all] [--network-wide] * @subcommand list-modules * @since 2.1 * @param array $args * @param array $assoc_args */ public function list_modules($args, $assoc_args) { if (empty($assoc_args['all'])) { if (!empty($assoc_args['network-wide'])) { $modules = get_site_option('ep_active_modules', array()); } else { $modules = get_option('ep_active_modules', array()); } WP_CLI::line(__('Active modules:', 'elasticpress')); } else { WP_CLI::line(__('Registered modules:', 'elasticpress')); $modules = wp_list_pluck(EP_Modules::factory()->registered_modules, 'slug'); } foreach ($modules as $module) { WP_CLI::line($module); } }
?> "></div> <div class="wrap"> <h1><?php esc_html_e('ElasticPress', 'elasticpress'); ?> </h1> <h2><?php esc_html_e("ElasticPress, the fast and flexible query engine for WordPress, let's you supercharge your website through a variety of modules. Activate the ones you need below:", 'elasticpress'); ?> </h2> <div class="ep-modules metabox-holder"> <?php $modules = EP_Modules::factory()->registered_modules; ?> <?php $left = ''; $right = ''; $i = 0; foreach ($modules as $module) { $i++; $module_classes = $module->is_active() ? 'module-active' : ''; if (!empty($index_meta) && !empty($index_meta['module_sync']) && $module->slug === $index_meta['module_sync']) { $module_classes .= ' module-syncing'; } $deps_met = $module->dependencies_met(); if (is_wp_error($deps_met)) { $module_classes .= ' module-dependencies-unmet';
/** * 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)); }
/** * Easy access function to get a EP_Module object from a slug * @param string $slug * @since 2.1 * @return EP_Module */ function ep_get_registered_module($slug) { if (empty(EP_Modules::factory()->registered_modules[$slug])) { return false; } return EP_Modules::factory()->registered_modules[$slug]; }