View source
<?php
class PMPAPIWebTestCase extends DrupalWebTestCase {
protected $privileged_user;
const SLEEP_TIME = 1;
public static function getInfo() {
return array(
'name' => 'PMPAPI Tests',
'description' => 'Ensure that the basic PMPAPI functionality functions properly.',
'group' => 'PMPAPI',
);
}
public function setUp() {
parent::setUp(array(
'pmpapi',
));
$this->privileged_user = $this
->drupalCreateUser(array(
'administer PMP API',
));
$this
->drupalLogin($this->privileged_user);
module_load_include('php', 'pmpapi', 'tests/settings');
$vars = pmpapi_test_get_secret_vars();
variable_set('pmpapi_auth_client_id', $vars['client_id']);
variable_set('pmpapi_auth_client_secret', $vars['client_secret']);
variable_set('pmpapi_base_url', $vars['host']);
variable_set('pmpapi_cache', FALSE);
}
public function testPmpAPIGetValidGUID() {
$guid = pmpapi_guid();
$valid_guid = preg_match("/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}/", $guid);
$this
->assertTrue($valid_guid, 'generated a valid guid.');
}
public function testPmpAPIFetchDoc() {
module_load_include('php', 'pmpapi', 'tests/settings');
$vars = pmpapi_test_get_secret_vars();
$doc = pmpapi_fetch($vars['story_guid']);
$is_non_empty_object = is_object($doc) && !empty($doc) && empty($doc->errors['query']);
$this
->assertTrue($is_non_empty_object, 'successfully pulled, without errors, object that is not empty.');
}
public function testPmpAPIFailToFetchDoc() {
$doc = pmpapi_fetch('1234');
$pull_error = !empty($doc->errors['query']);
$this
->assertTrue($pull_error, 'pull error created when attempting to pull bogus doc.');
}
public function testPmpAPIDoQuery() {
module_load_include('php', 'pmpapi', 'tests/settings');
$vars = pmpapi_test_get_secret_vars();
$params = array(
'tag' => $vars['sample_tag'],
);
$doc = pmpapi_query($params);
$is_non_empty_object = is_object($doc) && !empty($doc) && empty($doc->errors['query']);
$this
->assertTrue($is_non_empty_object, 'successfully pulled, without errors, query that is not empty.');
}
public function testPmpAPISendDoc() {
$values = array(
'attributes' => array(
'title' => $this
->randomName(20),
'teaser' => $this
->randomName(10),
),
);
$doc = pmpapi_send($values);
sleep(self::SLEEP_TIME);
pmpapi_remove($doc->attributes->guid);
$this
->assertTrue(is_object($doc), 'successfully pushed a story to the PMP.');
}
}