public function test_shortcode_timeline_ajax() { // TODO: fix content-type tests. $this->markTestSkipped('Content Type tests are failing, needs fix'); if (!function_exists('xdebug_get_headers')) { $this->markTestSkipped('xdebug is required for this test'); } $post_id = wl_create_post('This is Post 1', 'post-1', 'Post 1', 'publish'); $entity_1_id = wl_create_post('This is Entity 1', 'entity-1', 'Entity 1', 'publish', 'entity'); wl_set_entity_main_type($entity_1_id, 'http://schema.org/Thing'); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-02', true); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-03', true); $entity_2_id = wl_create_post('This is Entity 2', 'entity-2', 'Entity 2', 'publish', 'entity'); wl_set_entity_main_type($entity_2_id, 'http://schema.org/Thing'); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-03', true); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-04', true); wl_core_add_relation_instances($post_id, WL_WHAT_RELATION, array($entity_1_id, $entity_2_id)); $_REQUEST['post_id'] = $post_id; Wordlift_Timeline_Service::get_instance()->ajax_timeline(); $headers = xdebug_get_headers(); $this->assertTrue(in_array('Content-Type: application/json', $headers)); }
/** * Create: * * 2 Post * * 2 Event entities referenced, one per Post * * 1 Place entity as a distractor * Check that the 2 events are retrieved from the global timeline (no post specified). */ function testGlobalTimeline() { // Create posts $post_1_id = wl_create_post('', 'post-1', 'Post 1', 'publish', 'post'); $post_2_id = wl_create_post('', 'post-2', 'Post 2', 'publish', 'post'); // Create entities (2 events and one place) $entity_1_id = wl_create_post("Entity 1's Text", 'entity-1', "Entity 1's Title", 'publish', 'entity'); wl_set_entity_main_type($entity_1_id, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-01', true); add_post_meta($entity_1_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-07', true); $entity_2_id = wl_create_post("Entity 2's Text", 'entity-2', "Entity 2's Title", 'publish', 'entity'); wl_set_entity_main_type($entity_2_id, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-01-02', true); add_post_meta($entity_2_id, Wordlift_Schema_Service::FIELD_DATE_END, '2014-01-08', true); $entity_3_id = wl_create_post('Entity 3 Text', 'entity-3', 'Entity 3 Title', 'publish', 'entity'); wl_set_entity_main_type($entity_2_id, 'http://schema.org/Place'); add_post_meta($entity_3_id, Wordlift_Schema_Service::FIELD_GEO_LATITUDE, 45.12, true); add_post_meta($entity_3_id, Wordlift_Schema_Service::FIELD_GEO_LONGITUDE, 90.3, true); wl_core_add_relation_instances($post_1_id, WL_WHAT_RELATION, array($entity_1_id, $entity_3_id)); wl_core_add_relation_instance($post_2_id, WL_WHAT_RELATION, $entity_2_id); // Call retrieving function with null argument (i.e. global timeline) $events = Wordlift_Timeline_Service::get_instance()->get_events(); $this->assertCount(2, $events); $event_ids = array_map(function ($item) { return $item->ID; }, $events); $this->assertContains($entity_1_id, $event_ids); $this->assertContains($entity_2_id, $event_ids); }
/** * Create a Wordlift_Timeline_Service instance. * * @since 3.1.0 * * @param \Wordlift_Entity_Service $entity_service The Entity service. */ public function __construct($entity_service) { $this->log_service = Wordlift_Log_Service::get_logger('Wordlift_Timeline_Service'); $this->entity_service = $entity_service; self::$instance = $this; }