public function setUp() { parent::setUp(); // Be careful modifying this. Tests are coded to expect this exact sample data. $post_dates = array('1972-05-24 14:53:45', '1984-07-28 19:28:56', '2003-05-27 22:45:07', '2004-01-03 08:54:10', '2004-05-22 12:34:12', '2005-02-17 00:00:15', '2005-12-31 23:59:20', '2007-01-22 03:49:21', '2007-05-16 17:32:22', '2007-09-24 07:17:23', '2008-03-29 09:04:25', '2008-07-15 11:32:26', '2008-12-10 13:06:27', '2009-06-11 21:30:28', '2009-12-18 10:42:29', '2010-06-17 17:09:30', '2011-02-23 12:12:31', '2011-07-04 01:56:32', '2011-12-12 16:39:33', '2012-06-13 14:03:34', '2025-04-20 10:13:00', '2025-04-20 10:13:01', '2025-05-20 10:13:01'); foreach ($post_dates as $post_date) { $this->factory->post->create(array('post_date' => $post_date)); } es_wp_query_index_test_data(); unset($this->q); $this->q = new ES_WP_Query(); }
function setUp() { parent::setUp(); $i = 0; $start_date = strtotime('2014-01-01'); foreach (get_post_stati() as $status) { $year = 'future' == $status ? 2029 : 2014; $date = $start_date + DAY_IN_SECONDS * $i++; $this->factory->post->create(array('post_status' => $status, 'post_date' => date($year . '-m-d 00:00:00', $date))); } es_wp_query_index_test_data(); unset($this->q); $this->q = new ES_WP_Query(); }
function test_wp_query_data_changes_between_queries() { $posts = $this->q->query('tag=tag-a&es=true'); $expected = array('tags-a-and-c', 'tags-a-and-b', 'tag-a', 'tags-a-b-c'); $this->assertCount(4, $posts); $this->assertEquals($expected, wp_list_pluck($posts, 'post_name')); $this->assertEquals(1, substr_count($this->q->request, 'ES_WP_Query Shoehorn')); $this->factory->post->create(array('post_title' => 'between_queries', 'tags_input' => array('tag-a'), 'post_date' => '2010-11-01 00:00:00')); es_wp_query_index_test_data(); $posts = $this->q->get_posts(); $expected = array('between_queries', 'tags-a-and-c', 'tags-a-and-b', 'tag-a', 'tags-a-b-c'); $this->assertCount(5, $posts); $this->assertEquals($expected, wp_list_pluck($posts, 'post_name')); $this->assertEquals(1, substr_count($this->q->request, 'ES_WP_Query Shoehorn')); }
function test_query_author_vars() { $author_1 = $this->factory->user->create(array('user_login' => 'admin1', 'user_pass' => rand_str(), 'role' => 'author')); $post_1 = $this->factory->post->create(array('post_title' => rand_str(), 'post_author' => $author_1, 'post_date' => '2007-01-01 00:00:00')); $author_2 = $this->factory->user->create(array('user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author')); $post_2 = $this->factory->post->create(array('post_title' => rand_str(), 'post_author' => $author_2, 'post_date' => '2007-01-01 00:00:00')); $author_3 = $this->factory->user->create(array('user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author')); $post_3 = $this->factory->post->create(array('post_title' => rand_str(), 'post_author' => $author_3, 'post_date' => '2007-01-01 00:00:00')); $author_4 = $this->factory->user->create(array('user_login' => rand_str(), 'user_pass' => rand_str(), 'role' => 'author')); $post_4 = $this->factory->post->create(array('post_title' => rand_str(), 'post_author' => $author_4, 'post_date' => '2007-01-01 00:00:00')); es_wp_query_index_test_data(); $posts = $this->q->query(array('author' => '', 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_2, $author_3, $author_4), $author_ids); $posts = $this->q->query(array('author' => 0, 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_2, $author_3, $author_4), $author_ids); $posts = $this->q->query(array('author' => '0', 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_2, $author_3, $author_4), $author_ids); $posts = $this->q->query(array('author' => $author_1, 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1), $author_ids); $posts = $this->q->query(array('author' => "{$author_1}", 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1), $author_ids); $posts = $this->q->query(array('author' => "{$author_1},{$author_2}", 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_2), $author_ids); $posts = $this->q->query(array('author' => "-{$author_1},{$author_2}", 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_2, $author_3, $author_4), $author_ids); $posts = $this->q->query(array('author' => "{$author_1},-{$author_2}", 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_3, $author_4), $author_ids); $posts = $this->q->query(array('author' => "-{$author_1},-{$author_2}", 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_3, $author_4), $author_ids); $posts = $this->q->query(array('author__in' => array($author_1, $author_2), 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1, $author_2), $author_ids); $posts = $this->q->query(array('author__not_in' => array($author_1, $author_2), 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_3, $author_4), $author_ids); $posts = $this->q->query(array('author_name' => 'admin1', 'post__in' => array($post_1, $post_2, $post_3, $post_4))); $author_ids = array_unique(wp_list_pluck($posts, 'post_author')); $this->assertEqualSets(array($author_1), $author_ids); }
function test_taxonomy_include_children() { $cat_a = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'Australia')); $cat_b = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'Sydney', 'parent' => $cat_a)); $cat_c = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'East Syndney', 'parent' => $cat_b)); $cat_d = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'West Syndney', 'parent' => $cat_b)); $post_a = $this->factory->post->create(array('post_category' => array($cat_a))); $post_b = $this->factory->post->create(array('post_category' => array($cat_b))); $post_c = $this->factory->post->create(array('post_category' => array($cat_c))); $post_d = $this->factory->post->create(array('post_category' => array($cat_d))); es_wp_query_index_test_data(); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_a))))); $this->assertEquals(4, count($posts)); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_a), 'include_children' => false)))); $this->assertEquals(1, count($posts)); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_b))))); $this->assertEquals(3, count($posts)); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_b), 'include_children' => false)))); $this->assertEquals(1, count($posts)); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_c))))); $this->assertEquals(1, count($posts)); $posts = es_get_posts(array('tax_query' => array(array('taxonomy' => 'category', 'field' => 'id', 'terms' => array($cat_c), 'include_children' => false)))); $this->assertEquals(1, count($posts)); }