function ServicesResourceUsertests::testRequestNewPassword in Services 7.3
Test request_new_password method.
File
- tests/
functional/ ServicesResourceUserTests.test, line 643 - Call the endpoint tests when no authentication is being used.
Class
- ServicesResourceUsertests
- Run test cases for the endpoint with no authentication turned on.
Code
function testRequestNewPassword() {
// Create user.
$account = $this
->drupalCreateUser(array(
'administer services',
));
// Request new password for user by name.
$data = array(
'name' => $account->name,
);
$response = $this
->servicesPost($this->endpoint->path . '/user/request_new_password', $data);
$this
->assertTrue($response['body'], 'Resource to request a new password for user name has been called successfully.', 'UserResource: request_new_password');
// Request new password for user by e-mail address.
$data = array(
'name' => $account->mail,
);
$response = $this
->servicesPost($this->endpoint->path . '/user/request_new_password', $data);
$this
->assertTrue($response['body'], 'Resource to request a new password for user name has been called successfully.', 'UserResource: request_new_password');
// Assert 406 response for user that does not exist.
$data = array(
'name' => $this
->randomName(10) . '@example.com',
);
$response = $this
->servicesPost($this->endpoint->path . '/user/request_new_password', $data);
$this
->assertEqual(406, $response['code'], 'Resource to request new password for non-existing user name returned content not acceptable.', 'UserResource: request_new_password');
// Assert that 2 e-mails were sent in this test. The drupalGetMails()
// method does not provide immediate feedback about e-mails sent during the
// test, and so this assertion can only be done at this point.
$mails = $this
->drupalGetMails();
$this
->assertEqual(2, count($mails), 'Only 2 e-mails were sent during this test.');
}