Skip to content

Commit

Permalink
Reset password e-mail as html and text. Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rochamarcelo committed Jan 15, 2020
1 parent e7f90c5 commit bd3a6c2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
4 changes: 0 additions & 4 deletions templates/email/html/reset_password.php
Expand Up @@ -9,10 +9,6 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

$activationUrl = \CakeDC\Users\Utility\UsersUrl::actionUrl('resetPassword', [
'_full' => true,
isset($token) ? $token : ''
]);
?>
<p>
<?= __d('cake_d_c/users', "Hi {0}", isset($first_name) ? $first_name : '') ?>,
Expand Down
9 changes: 0 additions & 9 deletions templates/email/text/reset_password.php
Expand Up @@ -8,15 +8,6 @@
* @copyright Copyright 2010 - 2018, Cake Development Corporation (https://www.cakedc.com)
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/

$activationUrl = [
'_full' => true,
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'resetPassword',
isset($token) ? $token : ''
];
?>
<?= __d('cake_d_c/users', "Hi {0}", isset($first_name) ? $first_name : '') ?>,

Expand Down
42 changes: 26 additions & 16 deletions tests/TestCase/Mailer/UsersMailerTest.php
Expand Up @@ -12,8 +12,10 @@
*/
namespace CakeDC\Users\Test\TestCase\Email;

use Cake\Mailer\Message;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Mailer\UsersMailer;

/**
* Test Case
Expand All @@ -29,6 +31,10 @@ class UsersMailerTest extends TestCase
'plugin.CakeDC/Users.SocialAccounts',
'plugin.CakeDC/Users.Users',
];
/**
* @var UsersMailer
*/
private $UsersMailer;

/**
* setUp
Expand Down Expand Up @@ -127,29 +133,33 @@ public function testSocialAccountValidation()
*/
public function testResetPassword()
{
$this->UsersMailer = new UsersMailer();
$table = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$data = [
$user = $table->newEntity([
'first_name' => 'FirstName',
'email' => 'test@example.com',
'token' => '12345',
]);
$expectedViewVars = [
'activationUrl' => [
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'Users',
'action' => 'resetPassword',
'_full' => true,
'12345'
],
'first_name' => 'FirstName',
'email' => 'test@example.com',
'token' => '12345',
];
$user = $table->newEntity($data);
$this->Email->expects($this->once())
->method('setTo')
->with($user['email'])
->will($this->returnValue($this->Email));

$this->Email->expects($this->once())
->method('setSubject')
->with('FirstName, Your reset password link')
->will($this->returnValue($this->Email));

$this->UsersMailer->expects($this->once())
->method('setViewVars')
->with($data)
->will($this->returnValue($this->UsersMailer));

$this->invokeMethod($this->UsersMailer, 'resetPassword', [$user]);
$this->assertSame(['test@example.com' => 'test@example.com'], $this->UsersMailer->getTo());
$this->assertSame('FirstName, Your reset password link', $this->UsersMailer->getSubject());
$this->assertSame(Message::MESSAGE_BOTH, $this->UsersMailer->getEmailFormat());
$this->assertSame($expectedViewVars, $this->UsersMailer->viewBuilder()->getVars());
$this->assertSame('CakeDC/Users.resetPassword', $this->UsersMailer->viewBuilder()->getTemplate());
}

/**
Expand Down

0 comments on commit bd3a6c2

Please sign in to comment.