populateEndpointFAPI() ; $endpoint = new stdClass; $endpoint->disabled = FALSE; $endpoint->api_version = 3; $endpoint->name = $edit['name']; $endpoint->server = $edit['server']; $endpoint->path = $edit['path']; $endpoint->authentication = array( 'services' => 'services', ); $endpoint->server_settings = array( 'formatters' => array( 'php' => TRUE, ), 'parsers' => array( 'application/x-yaml' => TRUE, 'application/json' => TRUE, 'application/vnd.php.serialized' => TRUE, 'application/plist' => TRUE, 'application/plist+xml' => TRUE, 'application/x-www-form-urlencoded' => FALSE, ), ); $endpoint->resources = array( 'user' => array( 'actions' => array( 'login' => array( 'enabled' => 1, ), 'logout' => array( 'enabled' => 1, ), ), ), ); $endpoint->debug = 1; $endpoint->export_type = FALSE; services_endpoint_save($endpoint); $endpoint = services_endpoint_load($endpoint->name); $this->assertTrue($endpoint->name == $edit['name'], 'Endpoint successfully created'); $this->endpoint = $endpoint; } /** * Implementation of getInfo(). */ public static function getInfo() { return array( 'name' => 'Parser', 'description' => 'Test the Parser functionality.', 'group' => 'Services', ); } /** * Testing parser functionality. */ public function testParser() { $account = $this->drupalCreateUser(); // Logout first. $this->drupalLogout(); // Try to login. By default servicesPost uses // 'application/x-www-form-urlencoded' type. So it should be refused. $response = $this->servicesPost($this->endpoint->path . '/user/login', array('username' => $account->name, 'password' => $account->pass_raw)); $this->assertTrue(strpos($response['header'], '406 Not Acceptable : Unsupported request content type application/x-www-form-urlencoded') !== FALSE, 'Do not accept application/x-www-form-urlencoded if disabled.', 'Parser'); } /** * Do JSON call. Ensure it is parsed properly. */ public function testJSONCall() { $account = $this->drupalCreateUser(); // Logout first. $this->drupalLogout(); // Do JSON call to login. $response = $this->servicesPost($this->endpoint->path . '/user/login', array('username' => $account->name, 'password' => $account->pass_raw), array(), 'json'); $body = $response['body']; $proper_answer = isset($body->sessid) && isset($body->user) && $body->user->name == $account->name; $this->assertTrue($proper_answer, 'User successfully logged in via JSON call.', 'JSON Call: Login'); } }