/**
  * Test set- and get- methods for schema properties
  */
 function testSchemaProperty()
 {
     $place_id = wl_create_post('Entity 1 Text', 'entity-1', 'Entity 1 Title', 'publish', 'entity');
     wl_schema_set_types($place_id, 'Place');
     wl_schema_add_value($place_id, 'sameAs', 'http://dbpedia.org/resource/my-place');
     wl_schema_add_value($place_id, 'sameAs', 'http://rdf.freebase.com/my-place');
     wl_schema_set_value($place_id, 'latitude', 40.12);
     $event_id = wl_create_post("Entity 2 Text", 'entity-2', "Entity 2 Title", 'publish', 'entity');
     wl_schema_set_types($event_id, 'Event');
     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, 'startDate', '2014-10-21');
     // Positive tests
     $value = wl_schema_get_value($place_id, 'sameAs');
     $this->assertEquals(array('http://rdf.freebase.com/my-place', 'http://dbpedia.org/resource/my-place'), $value);
     $value = wl_schema_get_value($place_id, 'latitude');
     $this->assertEquals(array(40.12), $value);
     $value = wl_schema_get_value($event_id, 'sameAs');
     $this->assertEquals(array('http://rdf.freebase.com/my-event', 'http://dbpedia.org/resource/my-event'), $value);
     $value = wl_schema_get_value($event_id, 'startDate');
     $this->assertEquals(array('2014-10-21'), $value);
     // Negative tests
     $value = wl_schema_get_value($place_id, null);
     $this->assertEquals(null, $value);
     $value = wl_schema_get_value($place_id, 'startDate');
     $this->assertEquals(null, $value);
     $value = wl_schema_get_value($place_id, 'http://invented_url/something');
     $this->assertEquals(null, $value);
     //TODO: manage case of multiple values per property.
 }
    function testMicrodataCompilingProperlyForAnEntityWithNestedEntities()
    {
        // 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, Wordlift_Schema_Service::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, Wordlift_Schema_Service::SCHEMA_EVENT_TYPE);
        // Trying out both the schema API and the classic WP method
        add_post_meta($event_id, Wordlift_Schema_Service::FIELD_DATE_START, '2014-10-21', true);
        wl_schema_set_value($event_id, 'endDate', '2015-10-26');
        wl_schema_set_value($event_id, 'sameAs', 'http://dbpedia.org/resource/my-event');
        wl_schema_add_value($event_id, 'sameAs', 'http://rdf.freebase.com/my-event');
        // 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');
        // Case 1 - Nested entity is referenced trough the wordpress entity ID
        add_post_meta($event_id, Wordlift_Schema_Service::FIELD_LOCATION, $place_id, true);
        // Set the recursion limit.
        $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), "Error on comparing markup when the entity type is not defined");
        delete_post_meta($event_id, Wordlift_Schema_Service::FIELD_LOCATION);
        // Check if meta were deleted properly
        $this->assertEquals(array(), get_post_meta($event_id, Wordlift_Schema_Service::FIELD_LOCATION));
        // Case 2 - Nested entity is referenced trough the an uri
        add_post_meta($event_id, Wordlift_Schema_Service::FIELD_LOCATION, wl_get_entity_uri($place_id), true);
        $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));
    }