t('Calais API Test'), 'description' => t('Verify that a Calais request returns expected results.'), 'group' => t('Calais') ); } function setUp() { // Get the configured API key before generating a new $db_prefix $api_key = variable_get('calais_api_key', ''); parent::setUp('calais_api'); variable_set('calais_api_key', $api_key); } function tearDown() { parent::tearDown(); } function testAnalyze() { $body = filter_xss($this->get_test_content()); $date = format_date(time(), 'custom', 'r'); $calais = new Calais(array('host' => 'http://beta.opencalais.com')); $results = $calais->analyzeXML('Calais API Test', $body, $date); $this->arrayContains($results->City, 'Denver', 'Denver is a City'); $this->arrayContains($results->City, 'Philadelphia', 'Philadelphia is a City'); $this->arrayContains($results->City, 'Chicago', 'Chicago is a City'); $this->arrayContains($results->Company, 'CBS', 'CBS is a Company'); $this->arrayContains($results->Person, 'Hillary Clinton', 'Hillary Clinton is a Person'); $this->arrayContains($results->Person, 'Barack Obama', 'Barack Obama is a Person'); $this->arrayContains($results->Person, 'Howard Dean', 'Howard Dean is a Person'); $this->arrayContains($results->Person, 'Al Gore', 'Al Gore is a Person'); $this->arrayContains($results->PublishedMedium, 'The Wall Street Journal', 'The Wall Street Journal is a PublishedMedium'); $this->arrayContains($results->ProvinceOrState, 'Indiana', 'Indiana is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Ohio', 'Ohio is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Florida', 'Florida is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'North Carolina', 'North Carolina is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Iowa', 'Iowa is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Pennsylvania', 'Pennsylvania is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Michigan', 'Michigan is a ProvinceOrState'); $this->arrayContains($results->ProvinceOrState, 'Vermont', 'Vermont is a ProvinceOrState'); $this->arrayContains($results->TVShow, '60 Minutes', '60 Minutes is a TVShow'); $this->arrayContains($results->Organization, 'Democratic National Committee', 'Democratic National Committee is a Organization'); $this->arrayContains($results->EventsFacts, 'Person Political', 'Person Political is an Event/Fact'); $this->arrayContains($results->EventsFacts, 'Quotation', 'Quotation is an Event/Fact'); $this->assertFalse(property_exists($results, 'Geo'), 'Geo is not an entity type, mishandling of Geo data.'); $this->assertGeoData($results->ProvinceOrState, 'Indiana', '40.006603', '-86.2914'); $this->assertGeoData($results->ProvinceOrState, 'North Carolina', '35.483364', '-79.40023'); } function arrayContains($haystack, $needle, $message) { $this->assertTrue($haystack->has_term_value($needle), t($message)); } function assertGeoData($data, $entity, $lat, $lon) { $term = $data->get_term_by_value($entity); $this->assertEqual($term->lat, $lat, "Latitude {$term->lat} for $entity was incorrect"); $this->assertEqual($term->lon, $lon, "Longitude {$term->lon} for $entity was incorrect"); } function get_test_content() { $str = <<