/** * Set up the test. */ function setUp() { parent::setUp(); // Configure WordPress with the test settings. wl_configure_wordpress_test(); // Empty the blog. wl_empty_blog(); // Creating 2 fake entities $entities = array(wl_create_post('content', 'entity1', 'title1', 'publish', 'entity'), wl_create_post('content', 'entity2', 'title2', 'publish', 'entity')); // Creating a fake post self::$FIRST_POST_ID = wl_create_post('content', 'post1', 'title1', 'publish', 'post'); wl_core_add_relation_instances(self::$FIRST_POST_ID, WL_WHAT_RELATION, $entities); // Creating another fake post and entity (the most connected one) // Creating a fake post $new_post = wl_create_post('content', 'post2', 'title2', 'publish', 'post'); // Create the most connected entity self::$MOST_CONNECTED_ENTITY_ID = wl_create_post('content', 'entity2', 'title2', 'publish', 'entity'); wl_core_add_relation_instance($new_post, WL_WHAT_RELATION, self::$MOST_CONNECTED_ENTITY_ID); wl_core_add_relation_instance(self::$FIRST_POST_ID, WL_WHAT_RELATION, self::$MOST_CONNECTED_ENTITY_ID); }
/** * 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, 'http://schema.org/Event'); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_CAL_DATE_START, '2014-01-01', true); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_CAL_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, 'http://schema.org/Event'); add_post_meta($entity_2_id, WL_CUSTOM_FIELD_CAL_DATE_START, '2014-01-02', true); add_post_meta($entity_2_id, WL_CUSTOM_FIELD_CAL_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, WL_CUSTOM_FIELD_GEO_LATITUDE, 45.12, true); add_post_meta($entity_3_id, WL_CUSTOM_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 = wl_shortcode_timeline_get_events(null); $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); }
public function test_shortcode_geomap_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("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); wl_set_entity_main_type($entity_1_id, 'http://schema.org/Place'); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_GEO_LATITUDE, 40.12, true); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 72.3, true); $entity_2_id = wl_create_post("Entity 2 Text", 'entity-2', "Entity 2 Title", 'publish', 'entity'); wl_set_entity_main_type($entity_2_id, 'http://schema.org/Place'); add_post_meta($entity_2_id, WL_CUSTOM_FIELD_GEO_LATITUDE, 41.2, true); add_post_meta($entity_2_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 78.2, true); wl_core_add_relation_instances($post_id, WL_WHAT_RELATION, array($entity_1_id, $entity_2_id)); $_REQUEST['post_id'] = $post_id; wl_shortcode_geomap_ajax(); $headers = xdebug_get_headers(); $this->assertTrue(in_array('Content-Type: application/json', $headers)); }
function testWlCoreAddRelationInstances() { // Create a post and 2 entities $post_1_id = wl_create_post('', 'post1', 'A post'); $entity_1_id = wl_create_post('', 'entity1', 'An Entity', 'draft', 'entity'); $entity_2_id = wl_create_post('', 'entity2', 'An Entity', 'draft', 'entity'); // Stress method with strange parmeters $result = wl_core_add_relation_instances('', WL_WHAT_RELATION, array($entity_1_id, $entity_2_id)); $this->assertFalse($result); $result = wl_core_add_relation_instances($post_1_id, WL_WHAT_RELATION, null); $this->assertFalse($result); $result = wl_core_add_relation_instances($post_1_id, WL_WHAT_RELATION, array()); $this->assertFalse($result); $result = wl_core_add_relation_instances($post_1_id, 'ulabadula', array($entity_1_id, $entity_2_id)); $this->assertFalse($result); $result = wl_core_add_relation_instances($post_1_id, 'ulabadula', array()); $this->assertFalse($result); // Nothing has been inserted as relation so far. $result = wl_core_get_related_entity_ids($post_1_id); $this->assertTrue(is_array($result)); $this->assertEmpty($result); // Insert relation and verify it $result = wl_core_add_relation_instances($post_1_id, WL_WHAT_RELATION, array($entity_1_id, $entity_2_id)); $this->assertTrue(is_numeric($result[0])); // The methods return an array of record ids $this->assertTrue(is_numeric($result[1])); // The methods return an array of record ids $this->assertCount(2, $result); $result = wl_core_get_related_entity_ids($post_1_id); $this->assertEquals(array($entity_1_id, $entity_2_id), $result); }
/** * Test saving entities passed via a metabox. */ function testEntitiesViaArray() { // Create a post. $post_id = $this->createPost(); $this->assertTrue(is_numeric($post_id)); $post = get_post($post_id); $this->assertNotNull($post); // Read the entities from the mock-up analysis. $analysis_results = wl_parse_file(dirname(__FILE__) . '/' . self::FILENAME . '.json'); $this->assertTrue(is_array($analysis_results)); // For each entity get the label, type, description and thumbnails. $this->assertTrue(isset($analysis_results['entities'])); // Get a reference to the entities. $text_annotations = $analysis_results['text_annotations']; $best_entities = array(); foreach ($text_annotations as $id => $text_annotation) { $entity_annotation = wl_get_entity_annotation_best_match($text_annotation['entities']); $entity = $entity_annotation['entity']; $entity_id = $entity->{'@id'}; if (!array_key_exists($entity_id, $best_entities)) { $best_entities[$entity_id] = $entity; } } // Accumulate the entities in an array. $entities = array(); foreach ($best_entities as $uri => $entity) { // Label if (!isset($entity->{'http://www.w3.org/2000/01/rdf-schema#label'}->{'@value'})) { var_dump($entity); } $this->assertTrue(isset($entity->{'http://www.w3.org/2000/01/rdf-schema#label'}->{'@value'})); $label = $entity->{'http://www.w3.org/2000/01/rdf-schema#label'}->{'@value'}; $this->assertFalse(empty($label)); // Type // $type = wl_get_entity_type($entity); // $this->assertFalse(empty($type)); // Description $description = wl_get_entity_description($entity); $this->assertNotNull($description); // Images $images = wl_get_entity_thumbnails($entity); $this->assertTrue(is_array($images)); // Save the entity to the entities array. $entities = array_merge_recursive($entities, array($uri => array('uri' => $uri, 'label' => $label, 'main_type' => 'http://schema.org/Thing', 'type' => array(), 'description' => $description, 'images' => $images))); } // Save the entities in the array. $entity_posts = wl_save_entities($entities); // Publish $entity_post_ids = array_map(function ($item) { return $item->ID; }, $entity_posts); foreach ($entity_post_ids as $entity_id) { wp_publish_post($entity_id); } // TODO: need to bind entities with posts. wl_core_add_relation_instances($post_id, WL_WHAT_RELATION, $entity_post_ids); $this->assertCount(sizeof($entity_post_ids), wl_core_get_related_entity_ids($post_id)); // TODO: synchronize data. // NOTICE: this requires a published post! wl_linked_data_push_to_redlink($post_id); // Check that the entities are created in WordPress. $this->assertCount(count($entities), $entity_posts); // Check that each entity is bound to the post. $entity_ids = array(); foreach ($entity_posts as $post) { // Store the entity IDs for future checks. array_push($entity_ids, $post->ID); // Get the related posts IDs. $rel_posts = wl_core_get_related_post_ids($post->ID); $this->assertCount(1, $rel_posts); // The post must be the one the test created. $this->assertEquals($post_id, $rel_posts[0]); } // Check that the post references the entities. $rel_entities = wl_core_get_related_entity_ids($post_id); $this->assertEquals(count($entity_ids), count($rel_entities)); foreach ($entity_ids as $id) { $this->assertTrue(in_array($id, $rel_entities)); } // Check that the locally saved entities and the remotely saved ones match. $this->checkEntities($entity_posts); // Check that the locally saved post data match the ones on Redlink. $this->checkPost($post_id); // Check the post references, that they match between local and remote. $this->checkPostReferences($post_id); // Delete the post. $this->deletePost($post_id); }