View source
<?php
require_once 'ServicesWebTestCase.php';
class ServicesResourceSystemTests extends ServicesWebtestCase {
protected $privileged_user = NULL;
protected $endpoint = NULL;
public function setUp() {
parent::setUp('autoload', 'ctools', 'services', 'rest_server', 'inputstream');
$this->endpoint = $this
->saveNewEndpoint();
$this->privileged_user = $this
->drupalCreateUser(array(
'get a system variable',
'set a system variable',
));
$this
->drupalLogin($this->privileged_user);
}
public static function getInfo() {
return array(
'name' => t('Resource System'),
'description' => t('Test the resource System methods.'),
'group' => t('Services'),
);
}
function testSystemConnect() {
$path = $this->endpoint->path;
$response = $this
->servicesPost($path . '/system/connect');
$response_user = $response['body']->user;
$this
->assertEqual($response_user->uid, $this->privileged_user->uid, t('User account received for authenticated user.'), 'SystemResource: Connect');
$this
->drupalLogout();
$response = $this
->servicesPost($path . '/system/connect');
$response_user = $response['body']->user;
$this
->assertEqual($response_user->uid, 0, t('User account received for anonymous user.'), 'SystemResource: Connect');
}
function testSystemGetVariable() {
$path = $this->endpoint->path;
$name = $this
->randomName();
$value = $this
->randomString();
variable_set($name, $value);
$response = $this
->servicesPost($path . '/system/get_variable', array(
'name' => $name,
'default' => $this
->randomString(),
));
$this
->assertEqual($value, $response['body'], t('Variable get value.'), 'SystemResource: get_variable');
$name = $this
->randomName();
$default = $this
->randomString();
$response = $this
->servicesPost($path . '/system/get_variable', array(
'name' => $name,
'default' => $default,
));
$this
->assertEqual($default, $response['body'], t('Variable get value default.'), 'SystemResource: get_variable');
}
function testSystemSetVariable() {
$path = $this->endpoint->path;
$name = $this
->randomName();
$value = $this
->randomString();
$response = $this
->servicesPost($path . '/system/set_variable', array(
'name' => $name,
'value' => $value,
));
$variable = unserialize(db_result(db_query('SELECT value FROM {variable} WHERE name = "%s"', $name)));
$this
->assertEqual($value, $variable, t('Variable set value.'), 'SystemResource: set_variable');
}
function testSystemDelVariable() {
$path = $this->endpoint->path;
$name = $this
->randomName();
$value = $this
->randomString();
variable_set($name, $value);
$response = $this
->servicesPost($path . '/system/del_variable', array(
'name' => $name,
));
$newvalue = $this
->randomString();
$response = $this
->servicesPost($path . '/system/get_variable', array(
'name' => $name,
'default' => $newvalue,
));
$this
->assertEqual($newvalue, $response['body'], t('Variable deleted.'), 'SystemResource: get_variable');
}
}