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(); 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'); $request = calais_api_build_xml_request('Calais API Test', $date, $body); $results = calais_api_analyze($request, array('contentType' => 'TEXT/XML')); $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'); } function arrayContains($haystack, $needle, $message) { $this->assertTrue(in_array($needle, array_values($haystack)), t($message)); } function get_test_content() { $str = <<