diff --git a/tests/functional/ServicesResourceUserTests.test b/tests/functional/ServicesResourceUserTests.test index 3752a8c..8b8d464 100644 --- a/tests/functional/ServicesResourceUserTests.test +++ b/tests/functional/ServicesResourceUserTests.test @@ -194,7 +194,7 @@ class ServicesResourceUsertests extends ServicesWebtestCase { function testUpdateUserName() { // Create user. $account = $this->drupalCreateUser(); - $name = $this->randomName(); + $name = $this->randomName(); // Update mail of the user. $updated_account = array( 'name' => $name, @@ -636,4 +636,37 @@ class ServicesResourceUsertests extends ServicesWebtestCase { $this->assertTrue(strpos($response['status'], 'User is not logged in'), 'User cannot logout when is anonymous', 'UserResource: Logout'); } + + /** + * Test request_new_password method. + */ + 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'); + + $this->assertMailPattern('subject', 'Replacement login information', 1); + + // 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'); + + $this->assertMailPattern('subject', 'Replacement login information', 1); + + // 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'); + } } diff --git a/tests/services.test b/tests/services.test index ee5131e..d34e52c 100644 --- a/tests/services.test +++ b/tests/services.test @@ -501,6 +501,9 @@ class ServicesWebTestCase extends DrupalWebTestCase { 'register' => array( 'enabled' => 1, ), + 'request_new_password' => array( + 'enabled' => 1, + ), ), 'targeted_actions' => array( 'cancel' => array(