Пример #1
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $this->demo_user = array('user_login' => 'author1', 'user_nicename' => 'author-nicename', 'user_pass' => rand_str(), 'role' => 'author', 'display_name' => 'Michael Scott');
     $this->demo_user_id = $this->factory->user->create($this->demo_user);
     $this->demo_term = array('taxonomy' => 'category', 'name' => 'cat-a', 'slug' => 'cat-a');
     $this->demo_term_id = $this->factory->term->create($this->demo_term);
     $post_date = '';
     $this->demo_dates = array('post_date' => array('date' => '2013-02-28 01:23:45'), 'post_date_gmt' => array('date' => '2013-02-28 05:23:45'), 'post_modified' => array('date' => '2013-02-28 01:23:45'), 'post_modified_gmt' => array('date' => '2013-02-28 05:23:45'));
     foreach ($this->demo_dates as &$date) {
         $ts = strtotime($date['date']);
         $date = array('date' => strval($date['date']), 'year' => intval(date('Y', $ts)), 'month' => intval(date('m', $ts)), 'day' => intval(date('d', $ts)), 'hour' => intval(date('H', $ts)), 'minute' => intval(date('i', $ts)), 'second' => intval(date('s', $ts)), 'week' => intval(date('W', $ts)), 'day_of_week' => intval(date('N', $ts)), 'day_of_year' => intval(date('z', $ts)), 'seconds_from_day' => intval(mktime(date('H', $ts), date('i', $ts), date('s', $ts), 1, 1, 1970)), 'seconds_from_hour' => intval(mktime(0, date('i', $ts), date('s', $ts), 1, 1, 1970)));
     }
     $this->demo_post = array('post_author' => $this->demo_user_id, 'post_date' => $this->demo_dates['post_date']['date'], 'post_date_gmt' => $this->demo_dates['post_date_gmt']['date'], 'post_content' => 'Welcome to <a href="http://wp.dev/">Local WordPress Dev Sites</a>. This is your first post. Edit or delete it, then start blogging!', 'post_title' => 'Hello world!', 'post_excerpt' => 'Lorem ipsum dolor sit amet', 'post_status' => 'publish', 'post_password' => 'foobar', 'post_name' => 'hello-world', 'post_parent' => 123, 'menu_order' => 456, 'post_type' => 'post', 'post_mime_type' => 'image/jpeg', 'post_category' => array($this->demo_term_id));
     $this->demo_post_id = $this->factory->post->create($this->demo_post);
     add_post_meta($this->demo_post_id, 'test_string', 'foo');
     add_post_meta($this->demo_post_id, 'test_long', '123');
     add_post_meta($this->demo_post_id, 'test_double', '123.456');
     add_post_meta($this->demo_post_id, 'test_boolean_true', 'true');
     add_post_meta($this->demo_post_id, 'test_boolean_false', 'false');
     add_post_meta($this->demo_post_id, 'test_date', '2012-03-14 03:14:15');
     SP_Sync_Manager()->sync_post($this->demo_post_id);
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Пример #2
0
function sp_manually_load_plugin()
{
    // If your ES server is not at localhost:9200, you need to set $_ENV['SEARCHPRESS_HOST'].
    $host = getenv('SEARCHPRESS_HOST');
    if (empty($host)) {
        $host = 'http://localhost:9200';
    }
    update_option('sp_settings', array('host' => $host, 'must_init' => false, 'active' => true, 'last_beat' => false));
    require dirname(__FILE__) . '/../searchpress.php';
    SP_API()->index = 'searchpress-tests';
    // Make sure ES is running and responding
    $tries = 5;
    $sleep = 3;
    do {
        $response = wp_remote_get('http://localhost:9200/');
        if ('200' == wp_remote_retrieve_response_code($response)) {
            // Looks good!
            break;
        } else {
            printf("\nInvalid response from ES (%s), sleeping %d seconds and trying again...\n", wp_remote_retrieve_response_code($response), $sleep);
            sleep($sleep);
        }
    } while (--$tries);
    // If we didn't end with a 200 status code, exit
    sp_tests_verify_response_code($response);
    sp_index_flush_data();
}
Пример #3
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $this->post_id = $this->factory->post->create(array('post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00'));
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Пример #4
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $this->factory->post->create(array('post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'comment-test', 'post_date' => '2009-08-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'one-trackback', 'post_date' => '2009-09-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'many-trackbacks', 'post_date' => '2009-10-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'no-comments', 'post_date' => '2009-10-02 00:00:00'));
     $this->factory->post->create(array('post_title' => 'one-comment', 'post_date' => '2009-11-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'contributor-post-approved', 'post_date' => '2009-12-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'embedded-video', 'post_date' => '2010-01-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'simple-markup-test', 'post_date' => '2010-02-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'raw-html-code', 'post_date' => '2010-03-01 00:00:00'));
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Пример #5
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $cat_a = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-a'));
     $cat_b = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-b'));
     $cat_c = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-c'));
     $this->factory->post->create(array('post_title' => 'cats-a-b-c', 'post_date' => '2008-12-01 00:00:00', 'post_category' => array($cat_a, $cat_b, $cat_c)));
     $this->factory->post->create(array('post_title' => 'cats-a-and-b', 'post_date' => '2009-01-01 00:00:00', 'post_category' => array($cat_a, $cat_b)));
     $this->factory->post->create(array('post_title' => 'cats-b-and-c', 'post_date' => '2009-02-01 00:00:00', 'post_category' => array($cat_b, $cat_c)));
     $this->factory->post->create(array('post_title' => 'cats-a-and-c', 'post_date' => '2009-03-01 00:00:00', 'post_category' => array($cat_a, $cat_c)));
     $this->factory->post->create(array('post_title' => 'cat-a', 'post_date' => '2009-04-01 00:00:00', 'post_category' => array($cat_a)));
     $this->factory->post->create(array('post_title' => 'cat-b', 'post_date' => '2009-05-01 00:00:00', 'post_category' => array($cat_b)));
     $this->factory->post->create(array('post_title' => 'cat-c', 'post_date' => '2009-06-01 00:00:00', 'post_category' => array($cat_c)));
     $this->factory->post->create(array('post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00', 'post_category' => array($cat_a)));
     $this->factory->post->create(array('post_title' => 'comment-test', 'post_date' => '2009-08-01 00:00:00', 'post_category' => array($cat_a)));
     $this->factory->post->create(array('post_title' => 'one-trackback', 'post_date' => '2009-09-01 00:00:00', 'post_category' => array($cat_b)));
     $this->factory->post->create(array('post_title' => 'many-trackbacks', 'post_date' => '2009-10-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'no-comments', 'post_date' => '2009-10-02 00:00:00'));
     $this->factory->post->create(array('post_title' => 'one-comment', 'post_date' => '2009-11-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'contributor-post-approved', 'post_date' => '2009-12-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'embedded-video', 'post_date' => '2010-01-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'simple-markup-test', 'post_date' => '2010-02-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'raw-html-code', 'post_date' => '2010-03-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tags-a-b-c', 'tags_input' => array('tag-a', 'tag-b', 'tag-c'), 'post_date' => '2010-04-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tag-a', 'tags_input' => array('tag-a'), 'post_date' => '2010-05-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tag-a-2', 'tags_input' => array('tag-a'), 'post_date' => '2010-05-01 00:00:01'));
     $this->factory->post->create(array('post_title' => 'tag-a-3', 'tags_input' => array('tag-a'), 'post_date' => '2010-05-01 00:00:02'));
     $this->factory->post->create(array('post_title' => 'tag-b', 'tags_input' => array('tag-b'), 'post_date' => '2010-06-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tag-b-2', 'tags_input' => array('tag-b'), 'post_date' => '2010-06-01 00:00:01'));
     $this->factory->post->create(array('post_title' => 'tag-c', 'tags_input' => array('tag-c'), 'post_date' => '2010-07-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tags-a-and-b', 'tags_input' => array('tag-a', 'tag-b'), 'post_date' => '2010-08-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tags-b-and-c', 'tags_input' => array('tag-b', 'tag-c'), 'post_date' => '2010-09-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'tags-a-and-c', 'tags_input' => array('tag-a', 'tag-c'), 'post_date' => '2010-10-01 00:00:00'));
     $this->parent_one = $this->factory->post->create(array('post_title' => 'parent-one', 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:01'));
     $this->parent_two = $this->factory->post->create(array('post_title' => 'parent-two', 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:02'));
     $this->parent_three = $this->factory->post->create(array('post_title' => 'parent-three', 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:03'));
     $this->factory->post->create(array('post_title' => 'child-one', 'post_parent' => $this->parent_one, 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:04'));
     $this->factory->post->create(array('post_title' => 'child-two', 'post_parent' => $this->parent_one, 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:05'));
     $this->factory->post->create(array('post_title' => 'child-three', 'post_parent' => $this->parent_two, 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:06'));
     $this->factory->post->create(array('post_title' => 'child-four', 'post_parent' => $this->parent_two, 'post_type' => 'page', 'post_date' => '2007-01-01 00:00:07'));
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Пример #6
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
     $cat = $this->factory->term->create(array('taxonomy' => 'category', 'name' => 'cat-demo'));
     $tag = $this->factory->term->create(array('taxonomy' => 'post_tag', 'name' => 'tag-demo'));
     $this->factory->post->create(array('post_title' => 'lorem-ipsum', 'post_date' => '2009-07-01 00:00:00', 'post_category' => array($cat)));
     $this->factory->post->create(array('post_title' => 'comment-test', 'post_date' => '2009-08-01 00:00:00', 'post_category' => array($cat)));
     $this->factory->post->create(array('post_title' => 'one-trackback', 'post_date' => '2009-09-01 00:00:00', 'post_category' => array($cat)));
     $this->factory->post->create(array('post_title' => 'many-trackbacks', 'post_date' => '2009-10-01 00:00:00', 'post_category' => array($cat)));
     $this->factory->post->create(array('post_title' => 'no-comments', 'post_date' => '2009-10-02 00:00:00'));
     $this->factory->post->create(array('post_title' => 'one-comment', 'post_date' => '2009-11-01 00:00:00', 'tags_input' => array($tag)));
     $this->factory->post->create(array('post_title' => 'contributor-post-approved', 'post_date' => '2009-12-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'many-comments', 'post_date' => '2010-01-01 00:00:00'));
     $this->factory->post->create(array('post_title' => 'simple-markup-test', 'post_date' => '2010-02-01 00:00:00', 'tags_input' => array($tag)));
     $this->factory->post->create(array('post_title' => 'raw-html-code', 'post_date' => '2010-03-01 00:00:00', 'tags_input' => array($tag)));
     register_post_type('cpt', array('public' => true));
     $this->factory->post->create(array('post_title' => 'cpt', 'post_date' => '2010-01-01 00:00:00', 'post_type' => 'cpt'));
     $this->factory->post->create(array('post_title' => 'lorem-cpt', 'post_date' => '2010-01-01 00:00:00', 'post_type' => 'cpt'));
     // Force refresh the index so the data is available immediately
     SP_API()->post('_refresh');
 }
Пример #7
0
 function setUp()
 {
     parent::setUp();
     sp_index_flush_data();
 }
Пример #8
0
 function test_cron_index_non_200()
 {
     $posts = array($this->factory->post->create(array('post_title' => 'test one')), $this->factory->post->create(array('post_title' => 'test two')), $this->factory->post->create(array('post_title' => 'test three')), $this->factory->post->create(array('post_title' => 'test four')), $this->factory->post->create(array('post_title' => 'test five')), $this->factory->post->create(array('post_title' => 'test six')), $this->factory->post->create(array('post_title' => 'test seven')), $this->factory->post->create(array('post_title' => 'test eight')), $this->factory->post->create(array('post_title' => 'searchpress')));
     sp_index_flush_data();
     // This domain is used in unit tests, and we'll get a 404 from trying to use it with ES
     SP_Config()->update_settings(array('host' => 'http://asdftestblog1.files.wordpress.com', 'active' => false));
     // Because we changed the host, we have to re-init SP_API
     SP_API()->setup();
     SP_Sync_Manager()->do_cron_reindex();
     SP_Sync_Meta()->bulk = 3;
     SP_Sync_Meta()->save();
     $this->assertNotEmpty(wp_next_scheduled('sp_reindex'));
     $this->_fake_cron();
     $this->assertNotEmpty(SP_Sync_Meta()->messages['error']);
 }