Ejemplo n.º 1
0
 public function testBuildDocument()
 {
     update_option('fields', array('field1' => 1, 'post_date' => 1));
     register_post_type('post');
     register_taxonomy('tax1', 'post');
     register_taxonomy('tax2', 'post');
     wp_insert_term('Term 1', 'tax1', array('slug' => 'term1'));
     wp_insert_term('Term 2', 'tax1', array('slug' => 'term2', 'parent' => 1));
     wp_insert_term('Term 3', 'tax1', array('slug' => 'term3', 'parent' => 2));
     wp_insert_term('Term 4', 'tax2', array('slug' => 'term4'));
     wp_insert_term('Term 5', 'tax2', array('slug' => 'term5'));
     wp_insert_term('Term 6', 'tax2', array('slug' => 'term6', 'parent' => 1));
     wp_set_object_terms(2, array(3), 'tax1');
     wp_set_object_terms(2, array(2, 3), 'tax2');
     $post = (object) array('field1' => 'value1', 'ID' => 2, 'post_date' => '10/24/1988 00:00:00 CST', 'post_type' => 'post');
     $tz = date_default_timezone_get();
     date_default_timezone_set('America/Chicago');
     $document = Indexer::_build_document($post);
     date_default_timezone_set($tz);
     $this->assertEquals(array('field1' => 'value1', 'post_date' => '1988-10-24T01:00:00-05:00', 'tax1' => array('term3', 'term2', 'term1'), 'tax2' => array('term5', 'term6', 'term4'), 'tax1_name' => array('Term 3', 'Term 2', 'Term 1'), 'tax2_name' => array('Term 5', 'Term 6', 'Term 4'), 'blog_id' => 1), $document);
 }
 public function testBuildDocumentOmitsEmptyCustomFields()
 {
     update_option('fields', array());
     update_option('meta_fields', array('name' => 1, 'empty_field' => 1));
     register_post_type('post');
     $post = (object) array('ID' => 2, 'post_type' => 'post');
     add_post_meta($post->ID, 'name', 'RubyOnRails');
     $document = Indexer::_build_document($post);
     $this->assertEquals(array('name' => 'RubyOnRails', 'blog_id' => 1), $document);
 }