Skip to content

Commit

Permalink
e-mail message as html and text. Moved link to mailer. Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rochamarcelo committed Jan 15, 2020
1 parent 1ae4b89 commit 06be36f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
10 changes: 0 additions & 10 deletions templates/email/html/social_account_validation.php
Expand Up @@ -16,16 +16,6 @@
<p>
<strong><?php
$text = __d('cake_d_c/users', 'Activate your social login here');
$activationUrl = [
'_full' => true,
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'SocialAccounts',
'action' => 'validateAccount',
$socialAccount['provider'],
$socialAccount['reference'],
$socialAccount['token'],
];
echo $this->Html->link($text, $activationUrl);
?></strong>
</p>
Expand Down
11 changes: 0 additions & 11 deletions templates/email/text/social_account_validation.php
Expand Up @@ -8,17 +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' => 'SocialAccounts',
'action' => 'validateAccount',
$socialAccount['provider'],
$socialAccount['reference'],
$socialAccount['token'],
];
?>
<?= __d('cake_d_c/users', "Hi {0}", $user['first_name']) ?>,

Expand Down
48 changes: 22 additions & 26 deletions tests/TestCase/Mailer/UsersMailerTest.php
Expand Up @@ -16,6 +16,7 @@
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Mailer\UsersMailer;
use CakeDC\Users\Model\Entity\User;

/**
* Test Case
Expand Down Expand Up @@ -43,15 +44,8 @@ class UsersMailerTest extends TestCase
*/
public function setUp(): void
{
$this->UsersMailer = new UsersMailer();
parent::setUp();
$this->Email = $this->getMockBuilder('Cake\Mailer\Message')
->setMethods(['setTo', 'setSubject', 'setViewVars', 'setTemplate'])
->getMock();

$this->UsersMailer = $this->getMockBuilder('CakeDC\Users\Mailer\UsersMailer')
->setMethods(['setViewVars'])
->getMock();
$this->UsersMailer->setMessage($this->Email);
}

/**
Expand All @@ -62,7 +56,6 @@ public function setUp(): void
public function tearDown(): void
{
unset($this->UsersMailer);
unset($this->Email);
parent::tearDown();
}

Expand All @@ -73,7 +66,6 @@ public function tearDown(): void
*/
public function testValidation()
{
$this->UsersMailer = new UsersMailer();
$table = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$expectedViewVars = [
'activationUrl' => [
Expand Down Expand Up @@ -113,23 +105,28 @@ public function testSocialAccountValidation()
{
$social = TableRegistry::getTableLocator()->get('CakeDC/Users.SocialAccounts')
->get('00000000-0000-0000-0000-000000000001', ['contain' => 'Users']);

$this->Email->expects($this->once())
->method('setTo')
->with('user-1@test.com')
->will($this->returnValue($this->Email));

$this->Email->expects($this->once())
->method('setSubject')
->with('first1, Your social account validation link')
->will($this->returnValue($this->Email));

$this->UsersMailer->expects($this->once())
->method('setViewVars')
->with(['user' => $social->user, 'socialAccount' => $social])
->will($this->returnValue($this->UsersMailer));
$this->assertInstanceOf(User::class, $social->user);
$expectedViewVars = [
'user' => $social->user,
'socialAccount' => $social,
'activationUrl' => [
'_full' => true,
'prefix' => false,
'plugin' => 'CakeDC/Users',
'controller' => 'SocialAccounts',
'action' => 'validateAccount',
'Facebook',
'reference-1-1234',
'token-1234'
],
];

$this->invokeMethod($this->UsersMailer, 'socialAccountValidation', [$social->user, $social]);
$this->assertSame(['user-1@test.com' => 'user-1@test.com'], $this->UsersMailer->getTo());
$this->assertSame('first1, Your social account validation link', $this->UsersMailer->getSubject());
$this->assertSame(Message::MESSAGE_BOTH, $this->UsersMailer->getEmailFormat());
$this->assertSame($expectedViewVars, $this->UsersMailer->viewBuilder()->getVars());
$this->assertSame('CakeDC/Users.socialAccountValidation', $this->UsersMailer->viewBuilder()->getTemplate());
}

/**
Expand All @@ -139,7 +136,6 @@ public function testSocialAccountValidation()
*/
public function testResetPassword()
{
$this->UsersMailer = new UsersMailer();
$table = TableRegistry::getTableLocator()->get('CakeDC/Users.Users');
$user = $table->newEntity([
'first_name' => 'FirstName',
Expand Down

0 comments on commit 06be36f

Please sign in to comment.