/** * Test the wl_entity_get_by_title method. */ function testGetByTitle1() { // We're starting up with no entities, we expect 0 entities. $posts_1 = wl_entity_get_by_title('Test Entity'); $this->assertCount(0, $posts_1); // Create an entity and see that it is found. $post_id_2 = wl_create_post('Lorem Ipsum', 'test-entity-2', 'Test Entity', 'draft', WL_ENTITY_TYPE_NAME); $posts_2 = wl_entity_get_by_title('Test Entity'); $this->assertCount(1, $posts_2); $this->assertEquals($post_id_2, $posts_2[0]->id); // Create another entity and see that it is found too. $post_id_3 = wl_create_post('Lorem Ipsum', 'test-entity-3', 'Test Entity', 'publish', WL_ENTITY_TYPE_NAME); $posts_3 = wl_entity_get_by_title('Test Entity'); $this->assertCount(2, $posts_3); $this->assertEquals($post_id_2, $posts_3[0]->id); $this->assertEquals($post_id_3, $posts_3[1]->id); // Create another entity and see that it is NOT found. $post_id_4 = wl_create_post('Lorem Ipsum', 'test-entity-4', 'Test Entity 4', 'publish', WL_ENTITY_TYPE_NAME); $posts_4 = wl_entity_get_by_title('Test Entity'); $this->assertCount(2, $posts_3); $this->assertEquals($post_id_2, $posts_4[0]->id); $this->assertEquals($post_id_3, $posts_4[1]->id); // Now make a LIKE search and see that it is found. $posts_5 = wl_entity_get_by_title('Test Entity%'); $this->assertCount(3, $posts_5); $this->assertEquals($post_id_2, $posts_5[0]->id); $this->assertEquals($post_id_3, $posts_5[1]->id); $this->assertEquals($post_id_4, $posts_5[2]->id); }
/** * Test the {@link get_alternative_labels} function by creating an entity and checking that the number of alternative * labels matches the one we set via {@link save_post}. * * @since 3.2.0 */ function test_get_alternative_labels() { $entity_service = Wordlift_Entity_Service::get_instance(); // Create a test entity. $entity_id = wl_create_post('This is Entity 1', 'entity-1', 'Entity 1', 'publish', 'entity'); wl_set_entity_main_type($entity_id, 'http://schema.org/Thing'); // Check that we have no alternative labels. $this->assertCount(0, $entity_service->get_alternative_labels($entity_id)); // Call save_post to set the alternative labels, mock the request first. $_REQUEST['wl_alternative_label'] = array('ABC 1', 'ABD 2', 'EFG 3'); $entity_service->save_post($entity_id, null, null); // Check that we have 3 alternative labels. $this->assertCount(3, $entity_service->get_alternative_labels($entity_id)); $this->assertCount(2, wl_entity_get_by_title('AB', true)); // Call save_post to set the alternative labels, mock the request first. $_REQUEST['wl_alternative_label'] = array('ABC 1', 'ABD 2'); $entity_service->save_post($entity_id, null, null); // Check that we have 2 alternative labels. $this->assertCount(2, $entity_service->get_alternative_labels($entity_id)); $this->assertCount(2, wl_entity_get_by_title('AB', true)); // Call save_post to set the alternative labels, mock the request first. $_REQUEST['wl_alternative_label'] = array(); $entity_service->save_post($entity_id, null, null); // Check that we have no alternative labels. $this->assertCount(0, $entity_service->get_alternative_labels($entity_id)); $this->assertCount(0, wl_entity_get_by_title('AB')); }
function testSaveEventWithStartAndEndDates() { $entity_1_id = wl_create_post('', 'entity-1', 'Entity 1', 'draft', 'entity'); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_CAL_DATE_START, '2013-01-02'); add_post_meta($entity_1_id, WL_CUSTOM_FIELD_CAL_DATE_END, '2013-02-03'); wl_set_entity_main_type($entity_1_id, 'http://schema.org/Event'); wp_update_post(array('ID' => $entity_1_id, 'post_content' => 'Lorem Ipsum.')); // TODO: add checks for SPARQL query. }
function testEntityUriWithMissingDatasetUri() { $post_id = wl_create_post('A body', 'post-1', uniqid('post', true), 'draft', 'post'); $dataset_uri = wl_configuration_get_redlink_dataset_uri(); $this->assertNotEmpty($dataset_uri); // Remove the dataset uri wl_configuration_set_redlink_dataset_uri(''); $entity_uri = wl_get_entity_uri($post_id); // Check the wl_get_entity_uri properly returns null $this->assertNull($entity_uri); // Check the are not custom meta set for the current post $this->assertEmpty(get_post_meta($post_id, WL_ENTITY_URL_META_NAME)); // Set the dataset uri again wl_configuration_set_redlink_dataset_uri($dataset_uri); }
/** * Test the wl_entity_get_by_title method. */ function testGetByTitle1() { // We're starting up with no entities, we expect 0 entities. $posts_1 = wl_entity_get_by_title('Test Entity'); $this->assertCount(0, $posts_1); // Create an entity and see that it is found. $post_id_2 = wl_create_post('Lorem Ipsum', 'test-entity-2', 'Test Entity', 'draft', Wordlift_Entity_Service::TYPE_NAME); $posts_2 = wl_entity_get_by_title('Test Entity'); $this->assertCount(1, $posts_2); $this->assertEquals($post_id_2, $posts_2[0]->id); // Create another entity and see that it is found too. $post_id_3 = wl_create_post('Lorem Ipsum', 'test-entity-3', 'Test Entity', 'publish', Wordlift_Entity_Service::TYPE_NAME); $posts_3 = wl_entity_get_by_title('Test Entity'); $this->assertCount(2, $posts_3); $this->assertEquals($post_id_2, $posts_3[0]->id); $this->assertEquals($post_id_3, $posts_3[1]->id); // Create another entity and see that it is NOT found. $post_id_4 = wl_create_post('Lorem Ipsum', 'test-entity-4', 'Test Entity 4', 'publish', Wordlift_Entity_Service::TYPE_NAME); $posts_4 = wl_entity_get_by_title('Test Entity'); $this->assertCount(2, $posts_3); $this->assertEquals($post_id_2, $posts_4[0]->id); $this->assertEquals($post_id_3, $posts_4[1]->id); // Now make a LIKE search by hacking on the search param and see that it is found. $posts_5 = wl_entity_get_by_title('Test Entity%'); $this->assertCount(3, $posts_5); $this->assertEquals($post_id_2, $posts_5[0]->id); $this->assertEquals($post_id_3, $posts_5[1]->id); $this->assertEquals($post_id_4, $posts_5[2]->id); // Now make a LIKE search using the $autocomplete param $posts_5 = wl_entity_get_by_title('Test Entity', true); $this->assertCount(3, $posts_5); $this->assertEquals($post_id_2, $posts_5[0]->id); $this->assertEquals($post_id_3, $posts_5[1]->id); $this->assertEquals($post_id_4, $posts_5[2]->id); // Entity service instance $entity_service = Wordlift_Entity_Service::get_instance(); // Verify non existence of 'an alias' $this->assertCount(0, wl_entity_get_by_title('an alias', false, true)); // Assign alias to entity 2 and verify it gets found $entity_service->set_alternative_labels($post_id_2, 'an alias'); $this->assertCount(1, wl_entity_get_by_title('an alias')); // The alias above should not be found if we don't ask for aliases $this->assertCount(0, wl_entity_get_by_title('an alias', false, false)); }
/** * Test set- and get- methods for schema types */ function testSchemaType() { // Create entity $place_id = wl_create_post("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); // Type not specified, so it must be a schema.org/Thing $type = wl_schema_get_types($place_id); $this->assertEquals(1, count($type)); $this->assertEquals('http://schema.org/Thing', $type[0]); // Assign a non supported type wl_schema_set_types($place_id, 'Ulabadoola'); // Verify still a Thing $type = wl_schema_get_types($place_id); $this->assertEquals(1, count($type)); $this->assertEquals('http://schema.org/Thing', $type[0]); // Assign supported type wl_schema_set_types($place_id, 'Place'); // Verify it is now a Place $type = wl_schema_get_types($place_id); $this->assertEquals(array('http://schema.org/Place'), $type); }
/** * 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); }
public function testPostsSelectionStartingFromAnEntity() { // Create 2 posts and 2 entities $entity_1_id = wl_create_post('', 'entity0', 'An Entity', 'draft', 'entity'); $post_1_id = wl_create_post('', 'post1', 'A post', 'publish'); // Insert relations wl_core_add_relation_instance($post_1_id, WL_WHAT_RELATION, $entity_1_id); // Set $_GET variable: this means we will perform data selection for $entity_1_id $_GET['post_id'] = $entity_1_id; // Mock php://input $mock_http_raw_data = json_encode(array()); try { $this->_handleAjax('wordlift_related_posts', $mock_http_raw_data); } catch (WPAjaxDieContinueException $e) { } $response = json_decode($this->_last_response); $this->assertInternalType('array', $response); $this->assertCount(1, $response); $this->assertEquals('post', $response[0]->post_type); $this->assertEquals($post_1_id, $response[0]->ID); }
/** * Create: * * 1 Post * * 3 Place entities referenced by the Post * * 1 Person entity reference by the Post * */ function testFieldShortcode() { $place_id = wl_create_post("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); wl_set_entity_main_type($place_id, 'http://schema.org/Place'); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LATITUDE, 40.12, true); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 72.3, true); // Correct use $result = do_shortcode("[wl_field id={$place_id} name='latitude']"); $this->assertContains('40.12', $result); // Implicit ID (like we inserted the shortcode in the entity editor) $GLOBALS['post'] = get_post($place_id); // Set manually post_id $result = do_shortcode("[wl_field name='latitude']"); $this->assertEquals('40.12', $result); // Invalid ID (will ignore it) $result = do_shortcode("[wl_field id='yea' name='latitude']"); $this->assertEquals('40.12', $result); unset($GLOBALS['post']); // Invalid property name $result = do_shortcode("[wl_field id={$place_id} name='tuhdaaaa!']"); $this->assertEquals('', $result); }
/** * 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); }
/** * Create: * * 2 Posts * * 1 Place entity referenced by both posts * * Check that the geomap popup of the place contains a link to the two posts. */ function testPlacePopupRelatedPosts() { // Create two posts. $post_id_1 = wl_create_post('', 'post-1', 'Post 1', 'publish', 'post'); $post_id_2 = wl_create_post('', 'post-2', 'Post 2', 'publish', 'post'); // Create a place- $place_id = wl_create_post("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); wl_set_entity_main_type($place_id, 'http://schema.org/Place'); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LATITUDE, 40.12, true); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 72.3, true); // Reference place from both posts- wl_core_add_relation_instance($post_id_1, WL_WHERE_RELATION, $place_id); wl_core_add_relation_instance($post_id_2, WL_WHERE_RELATION, $place_id); // Check referencing. $places = wl_shortcode_geomap_get_places($post_id_1); $this->assertCount(1, $places); $this->assertEquals($places[0]->ID, $place_id); // Check json formatted data. $response = wl_shortcode_geomap_prepare_map($places); // Check object attributes $poi = $response['features'][0]; $this->assertTrue(isset($poi)); $this->assertTrue(isset($poi['properties'])); $this->assertTrue(isset($poi['properties']['popupContent'])); // Check if popup contains links to the two posts $popup = $poi['properties']['popupContent']; $link1 = esc_attr(get_permalink($post_id_1)); $this->assertContains($link1, $popup); $link2 = esc_attr(get_permalink($post_id_2)); $this->assertContains($link2, $popup); // Check no thumbnail has been echoed $this->assertNotContains('<img', $popup); }
function createSampleEntity() { $entity_post_id = wl_create_post('Lorem Ipsum', 'honda', 'Honda', 'publish', 'entity'); wl_schema_set_value($entity_post_id, 'sameAs', 'http://dbpedia.org/resource/Honda'); }
function testWL_Metabox_Field_uri_data() { // Create an entity of type Person $person_id = wl_create_post('', 'p', 'A person', 'publish', Wordlift_Entity_Service::TYPE_NAME); wl_set_entity_main_type($person_id, 'http://schema.org/Person'); wl_schema_set_value($person_id, 'author', 43); // Create an entity of type CreativeWork $creative_work_id = wl_create_post('', 'cw', 'A creative work', 'publish', Wordlift_Entity_Service::TYPE_NAME); wl_set_entity_main_type($creative_work_id, 'http://schema.org/CreativeWork'); wl_schema_set_value($creative_work_id, 'author', $person_id); // Set authorship // Create fake context global $post; $post = get_post($creative_work_id); // Build a single Field $author_custom_field = $this->getSampleCustomField(Wordlift_Schema_Service::DATA_TYPE_URI); $field = new WL_Metabox_Field_uri($author_custom_field); // Verify data is loaded correctly from DB $field->get_data(); $this->assertEquals(array($person_id), $field->data); // Save new DB values (third value is invalid and fourth is a new entity) $field->save_data(array($person_id, 'http://some-triplestore/person2', null, 'Annibale')); // Verify data is loaded correctly from DB $new_entity = get_page_by_title('Annibale', OBJECT, Wordlift_Entity_Service::TYPE_NAME); $field->get_data(); $this->assertEquals(array($person_id, 'http://some-triplestore/person2', $new_entity->ID), $field->data); }
function testMicrodataCompilingRecursivityLimitation() { // A place $place_id = wl_create_post('Just a place', 'my-place', 'MyPlace', 'publish', 'entity'); wl_set_entity_main_type($place_id, 'http://schema.org/Place'); // Trying out both the schema API and the classic WP method wl_schema_set_value($place_id, 'latitude', 40.12); add_post_meta($place_id, WL_CUSTOM_FIELD_GEO_LONGITUDE, 72.3, true); // An Event having as location the place above $event_id = wl_create_post('Just an event', 'my-event', 'MyEvent', 'publish', 'entity'); wl_set_entity_main_type($event_id, 'http://schema.org/Event'); add_post_meta($event_id, WL_CUSTOM_FIELD_CAL_DATE_START, '2014-10-21', true); add_post_meta($event_id, WL_CUSTOM_FIELD_CAL_DATE_END, '2015-10-26', true); wl_schema_set_value($event_id, 'sameAs', array('http://rdf.freebase.com/my-event', 'http://dbpedia.org/resource/my-event')); //wl_schema_set_value($event_id, 'sameAs', 'http://dbpedia.org/resource/my-event'); add_post_meta($event_id, WL_CUSTOM_FIELD_LOCATION, $place_id, true); // Create an annotated post containing the entities $entity_uri = wl_get_entity_uri($event_id); $content = <<<EOF <span itemid="{$entity_uri}">MyEvent</span> EOF; $post_id = wl_create_post($content, 'post', 'A post'); // Set to 0 the recursivity limitation on entity metadata compiling $this->setRecursionDepthLimit(0); // The expected mark-up expects color coding to be on. wl_configuration_set_enable_color_coding(true); // Compile markup for the given content $compiled_markup = _wl_content_embed_microdata($post_id, $content); $expected_markup = file_get_contents(dirname(__FILE__) . '/assets/microdata_compiling_recursivity_limitation.txt'); // Verify correct markup $this->assertEquals($this->prepareMarkup($expected_markup), $this->prepareMarkup($compiled_markup)); $this->setRecursionDepthLimit(1); // Compile markup for the given content $compiled_markup = _wl_content_embed_microdata($post_id, $content); $expected_markup = file_get_contents(dirname(__FILE__) . '/assets/microdata_compiling_for_an_entity_with_nested_entities.txt'); // Verify correct markup $this->assertEquals($this->prepareMarkup($expected_markup), $this->prepareMarkup($compiled_markup)); }
/** * Create a test post. * @return int */ function createPost() { // Get the post contents. $input = dirname(__FILE__) . '/' . self::FILENAME; $content = file_get_contents($input); $this->assertTrue(false != $content); // Create the post. $post_id = wl_create_post($content, self::SLUG, self::TITLE, 'publish'); $this->assertTrue(is_numeric($post_id)); return $post_id; }
function testEntityWithAlternativeLabelIsProperlyOverridden() { $original_label = uniqid('entity-original', true); // Create an entity $entity_id = wl_create_post('', 'entity-1', $original_label, 'draft', 'entity'); // Check that there are no related posts for the entity $related_post_ids = wl_core_get_related_post_ids($entity_id, array("predicate" => "what")); $this->assertCount(0, $related_post_ids); // Generate e label and set it as alternative label for the new entity $alternative_label = uniqid('entity-alternative', true); Wordlift_Entity_Service::get_instance()->set_alternative_labels($entity_id, $alternative_label); // Check that the alternative label is properly set $labels = Wordlift_Entity_Service::get_instance()->get_alternative_labels($entity_id); $this->assertCount(1, $labels); $this->assertContains($alternative_label, $labels); // Force post status to publish: this triggers the save_post hook wl_update_post_status($entity_id, 'publish'); // Check that entity label is properly mapped on entity post title $this->assertEquals($original_label, get_post($entity_id)->post_title); // Notice that the uri is generated trough the original label // while the current label is the alternative one $fake = $this->prepareFakeGlobalPostArrayFromFile('/assets/fake_global_post_array_with_one_existing_entity_linked_as_what.json', array('CURRENT_URI' => $this->buildEntityUriForLabel($original_label), 'CURRENT_LABEL' => $alternative_label)); $_POST = $fake; // Retrieve the entity uri (the first key in wl_entities associative aray) $original_entity_uri = current(array_keys($fake['wl_entities'])); // Reference the entity to the post content trough its alternative label $content = <<<EOF <span itemid="{$original_entity_uri}">{$alternative_label}</span> EOF; // Create a post referincing to the created entity $post_id = wl_create_post($content, 'my-post', 'A post', 'draft'); // Check that entity label is STILL properly mapped on entity post title $this->assertEquals($original_label, get_post($entity_id)->post_title); $expected_entity_uri = $this->buildEntityUriForLabel($original_label); $entity_uri = wl_get_entity_uri($entity_id); $this->assertEquals($entity_uri, $expected_entity_uri); // And it should be related to the post as what predicate $related_entity_ids = wl_core_get_related_entity_ids($post_id, array("predicate" => "what")); $this->assertCount(1, $related_entity_ids); $this->assertContains($entity_id, $related_entity_ids); }
function testWlCoreGetRelatedEntityIdsForAnEntity() { // Create 2 posts and 1 entities $entity_0_id = wl_create_post('', 'entity0', 'An Entity', 'draft', 'entity'); $entity_1_id = wl_create_post('', 'entity1', 'An Entity', 'draft', 'entity'); $entity_2_id = wl_create_post('', 'entity2', 'An Entity', 'draft', 'entity'); // Insert relations wl_core_add_relation_instance($entity_0_id, WL_WHERE_RELATION, $entity_1_id); wl_core_add_relation_instance($entity_0_id, WL_WHO_RELATION, $entity_2_id); // Check relation are retrieved as expected $result = wl_core_get_related_entity_ids($entity_0_id); $this->assertCount(2, $result); $this->assertTrue(in_array($entity_1_id, $result)); $this->assertTrue(in_array($entity_2_id, $result)); $result = wl_core_get_related_entity_ids($entity_0_id, array('predicate' => WL_WHERE_RELATION)); $this->assertCount(1, $result); $this->assertTrue(in_array($entity_1_id, $result)); $result = wl_core_get_related_entity_ids($entity_0_id, array('predicate' => WL_WHO_RELATION)); $this->assertCount(1, $result); $this->assertTrue(in_array($entity_2_id, $result)); }
function testEntityMetadataAreProperlyUpdated() { $fake = $this->prepareFakeGlobalPostArrayFromFile('/assets/fake_global_post_array_with_one_entity_linked_as_what.json'); $_POST = $fake; // Retrieve the entity uri (the first key in wl_entities associative aray) $original_entity_uri = current(array_keys($fake['wl_entities'])); // Reference the entity to the post content $content = <<<EOF <span itemid="{$original_entity_uri}">My entity</span> EOF; // Create a post referincing to the created entity $post_id = wl_create_post($content, 'my-post', 'A post', 'draft'); // Here the entity should have been created $original_entity = wl_get_entity_post_by_uri($original_entity_uri); $this->assertNotNull($original_entity); // Store entity type, images and sameAs (needed later) $original_type = wl_schema_get_types($original_entity->ID); $original_thumbnails = $this->getThumbs($original_entity->ID); $original_sameAs = wl_schema_get_value($original_entity->ID, 'sameAs'); // Query the same entity using the Redlink URI $entity_uri = wl_get_entity_uri($original_entity->ID); $e = wl_get_entity_post_by_uri($entity_uri); $this->assertEquals($original_entity, $e); // The entity description should be the same we expect $raw_entity = current(array_values($fake['wl_entities'])); $this->assertEquals($raw_entity['description'], $original_entity->post_content); // The entity is related as what predicate $related_entity_ids = wl_core_get_related_entity_ids($post_id, array("predicate" => "what")); $this->assertCount(1, $related_entity_ids); // Ensure there are no other relation instances $relation_instances = wl_tests_get_relation_instances_for($post_id); $this->assertCount(1, $relation_instances); /* Now Post is saved again with the same mentioned entity: * - with different type * - with different description * - with one more image * - with one modified sameAs * - as WHO instead fo WHAT */ $fake = $this->prepareFakeGlobalPostArrayFromFile('/assets/fake_global_post_array_with_one_entity_linked_as_who_and_modified_data.json'); $_POST = $fake; // The entity url should be the same we expect $raw_entity = current(array_values($fake['wl_entities'])); $raw_entity_uri = $raw_entity['uri']; $new_content = <<<EOF <span itemid="{$raw_entity_uri}">My entity</span> EOF; // Update the post content (to force existing entities update) wp_update_post(array('ID' => $post_id, 'post_content' => $new_content)); // Verify the mentioned entity was already into DB... $updated_entity = wl_get_entity_post_by_uri($raw_entity_uri); $this->assertEquals($original_entity->ID, $updated_entity->ID); $this->assertEquals($original_entity->post_title, $updated_entity->post_title); // ... but some properties changed! $this->assertNotEquals($original_entity, $updated_entity); // Verify entity type has been updated $updated_type = wl_schema_get_types($updated_entity->ID); $this->assertNotEquals($original_type, $updated_type); $this->assertEquals(array('http://schema.org/Organization'), $updated_type); // Verify entity description has been updated $this->assertEquals($raw_entity['description'], $updated_entity->post_content); // Verify entity images have been updated (one was added) $updated_thumbnails = $this->getThumbs($updated_entity->ID); $this->assertNotEquals($original_thumbnails, $updated_thumbnails); $this->assertContains($original_thumbnails[0], $updated_thumbnails); $this->assertCount(2, $updated_thumbnails); // There is one more $this->assertContains('Netherlands_vs_Ivory_Coast', $updated_thumbnails[1]); // ... about soccer // Verify entity sameAs have been updated $updated_sameAs = wl_schema_get_value($updated_entity->ID, 'sameAs'); $this->assertNotEquals($original_sameAs, $updated_sameAs); $this->assertContains($original_sameAs[1], $updated_sameAs); $this->assertNotContains($original_sameAs[0], $updated_sameAs); $this->assertContains('http://sv.dbpedia.org/page/Reason', $updated_sameAs); // Verify the entity is now related as who predicate $related_entity_ids = wl_core_get_related_entity_ids($post_id, array("predicate" => "who")); $this->assertCount(1, $related_entity_ids); // Ensure there are no other relation instances $relation_instances = wl_tests_get_relation_instances_for($post_id); $this->assertCount(1, $relation_instances); }
function testMicrodataCompilingForAnEntityPage() { // A place $place_id = wl_create_post('', 'my-place', 'MyPlace', 'publish', 'entity'); wl_set_entity_main_type($place_id, 'http://schema.org/Place'); wl_schema_set_value($place_id, 'latitude', 40.12); wl_schema_set_value($place_id, 'longitude', 72.3); wl_schema_set_value($place_id, 'streetAddress', 'via del ciuccio 23'); // Compile markup for the given content $compiled_markup = _wl_content_embed_microdata($place_id, ''); $expected_markup = file_get_contents(dirname(__FILE__) . '/assets/microdata_compiling_entity_page.txt'); // Verify correct markup $this->assertEquals($this->prepareMarkup($expected_markup), $this->prepareMarkup($compiled_markup)); }
function testWlEntityTaxonomyMicrodataTemplateInheritance() { // Create entity and set type $business_id = wl_create_post("Entity 1 Text", 'entity-1', "Entity 1 Title", 'publish', 'entity'); wl_set_entity_main_type($business_id, 'http://schema.org/LocalBusiness'); // Get microdata template $entity_type_details = wl_entity_type_taxonomy_get_type($business_id); $microdata_template = $entity_type_details['microdata_template']; // Check inherited microdata templates: // latitude from Place with 'itemtype="http://schema.org/GeoCoordinates"' markup $this->assertContains('itemtype="http://schema.org/GeoCoordinates"', $microdata_template); $this->assertContains('{{latitude}}', $microdata_template); // founder from Organization $this->assertContains('{{founder}}', $microdata_template); // negative test $this->assertNotContains('{{startDate}}', $microdata_template); }
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)); }
public function testFacetsSelection() { // Create 2 posts and 2 entities $entity_1_id = wl_create_post('', 'entity0', 'An Entity', 'draft', 'entity'); $entity_2_id = wl_create_post('', 'entity1', 'Another Entity', 'draft', 'entity'); $post_1_id = wl_create_post('', 'post1', 'A post', 'publish'); $post_2_id = wl_create_post('', 'post2', 'A post', 'publish'); // Insert relations wl_core_add_relation_instance($post_1_id, WL_WHAT_RELATION, $entity_1_id); wl_core_add_relation_instance($post_2_id, WL_WHAT_RELATION, $entity_1_id); wl_core_add_relation_instance($post_2_id, WL_WHAT_RELATION, $entity_2_id); // Set $_GET variable: this means we will perform data selection for $entity_1_id $_GET['entity_id'] = $entity_1_id; $_GET['type'] = 'facets'; try { $this->_handleAjax('wl_faceted_search'); } catch (WPAjaxDieContinueException $e) { } $response = json_decode($this->_last_response); $this->assertInternalType('array', $response); $this->assertCount(1, $response); $entity_uris = array($response[0]->id); $this->assertNotContains(wl_get_entity_uri($entity_1_id), $entity_uris); $this->assertContains(wl_get_entity_uri($entity_2_id), $entity_uris); }
/** * Test saving a post without a title. Check the URI. */ function testSavePostWithoutTitle() { $post_id = wl_create_post('Sample Post', 'post-1', '', 'publish'); $uri = wl_get_entity_uri($post_id); $expected_uri = wl_configuration_get_redlink_dataset_uri() . "/post/id/{$post_id}"; $this->assertEquals($expected_uri, $uri); }