Skip to content

Commit

Permalink
Merge branch '7.x' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Aug 12, 2020
2 parents 2aa0563 + fdf3d4a commit 0001ade
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 51 deletions.
6 changes: 6 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Expand Up @@ -641,6 +641,12 @@ protected function addressesToArray($address, $name)
protected function normalizeRecipient($recipient)
{
if (is_array($recipient)) {
if (array_values($recipient) === $recipient) {
return (object) array_map(function ($email) {
return compact('email');
}, $recipient);
}

return (object) $recipient;
} elseif (is_string($recipient)) {
return (object) ['email' => $recipient];
Expand Down
7 changes: 2 additions & 5 deletions src/Illuminate/Notifications/Channels/MailChannel.php
Expand Up @@ -89,11 +89,8 @@ protected function messageBuilder($notifiable, $notification, $message)
*/
protected function buildView($message)
{
if ($message->view || $message->textView) {
return [
'html' => $message->view,
'text' => $message->textView,
];
if ($message->view) {
return $message->view;
}

if (property_exists($message, 'theme') && ! is_null($message->theme)) {
Expand Down
32 changes: 3 additions & 29 deletions src/Illuminate/Notifications/Messages/MailMessage.php
Expand Up @@ -17,13 +17,6 @@ class MailMessage extends SimpleMessage implements Renderable
*/
public $view;

/**
* The plain text view to use for the message.
*
* @var string
*/
public $textView;

/**
* The view data for the message.
*
Expand Down Expand Up @@ -111,28 +104,13 @@ class MailMessage extends SimpleMessage implements Renderable
public function view($view, array $data = [])
{
$this->view = $view;
$this->viewData = array_merge($this->viewData, $data);
$this->viewData = $data;

$this->markdown = null;

return $this;
}

/**
* Set the plain text view for the message.
*
* @param string $textView
* @param array $data
* @return $this
*/
public function text($textView, array $data = [])
{
$this->textView = $textView;
$this->viewData = array_merge($this->viewData, $data);

return $this;
}

/**
* Set the Markdown template for the notification.
*
Expand Down Expand Up @@ -331,13 +309,9 @@ protected function arrayOfAddresses($address)
*/
public function render()
{
if (isset($this->view) || isset($this->textView)) {
if (isset($this->view)) {
return Container::getInstance()->make('mailer')->render(
[
'html' => $this->view,
'text' => $this->textView,
],
$this->data()
$this->view, $this->data()
);
}

Expand Down
14 changes: 11 additions & 3 deletions src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Expand Up @@ -74,9 +74,9 @@ protected function createClient(array $config)
return tap(new Redis, function ($client) use ($config) {
if ($client instanceof RedisFacade) {
throw new LogicException(
extension_loaded('redis')
? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
: 'Please make sure the PHP Redis extension is installed and enabled.'
extension_loaded('redis')
? 'Please remove or rename the Redis facade alias in your "app" configuration file in order to avoid collision with the PHP Redis extension.'
: 'Please make sure the PHP Redis extension is installed and enabled.'
);
}

Expand Down Expand Up @@ -127,6 +127,10 @@ protected function establishConnection($client, array $config)
$parameters[] = Arr::get($config, 'read_timeout', 0.0);
}

if (version_compare(phpversion('redis'), '5.3.0', '>=')) {
$parameters[] = Arr::get($config, 'context', []);
}

$client->{($persistent ? 'pconnect' : 'connect')}(...$parameters);
}

Expand All @@ -151,6 +155,10 @@ protected function createRedisClusterInstance(array $servers, array $options)
$parameters[] = $options['password'] ?? null;
}

if (version_compare(phpversion('redis'), '5.3.2', '>=')) {
$parameters[] = Arr::get($options, 'context', []);
}

return tap(new RedisCluster(...$parameters), function ($client) use ($options) {
if (! empty($options['prefix'])) {
$client->setOption(RedisCluster::OPT_PREFIX, $options['prefix']);
Expand Down
15 changes: 6 additions & 9 deletions tests/Integration/Notifications/SendingMailNotificationsTest.php
Expand Up @@ -259,7 +259,7 @@ public function testMailIsSentUsingMailMessageWithHtmlAndPlain()
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'html', 'text' => 'plain'],
['html', 'plain'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
Expand Down Expand Up @@ -291,7 +291,7 @@ public function testMailIsSentUsingMailMessageWithHtmlOnly()
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => 'html', 'text' => null],
'html',
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
Expand Down Expand Up @@ -323,7 +323,7 @@ public function testMailIsSentUsingMailMessageWithPlainOnly()
]);

$this->mailer->shouldReceive('send')->once()->with(
['html' => null, 'text' => 'plain'],
[null, 'plain'],
array_merge($notification->toMail($user)->toArray(), [
'__laravel_notification_id' => $notification->id,
'__laravel_notification' => get_class($notification),
Expand Down Expand Up @@ -438,8 +438,7 @@ public function via($notifiable)
public function toMail($notifiable)
{
return (new MailMessage)
->view('html')
->text('plain');
->view(['html', 'plain']);
}
}

Expand All @@ -453,8 +452,7 @@ public function via($notifiable)
public function toMail($notifiable)
{
return (new MailMessage)
->view('html')
->text(null);
->view('html');
}
}

Expand All @@ -468,7 +466,6 @@ public function via($notifiable)
public function toMail($notifiable)
{
return (new MailMessage)
->view(null)
->text('plain');
->view([null, 'plain']);
}
}
112 changes: 112 additions & 0 deletions tests/Mail/MailMailableTest.php
Expand Up @@ -54,6 +54,118 @@ public function testMailableSetsRecipientsCorrectly()
$this->assertTrue($mailable->hasTo('taylor@laravel.com'));
}

public function testMailableSetsCcRecipientsCorrectly()
{
$mailable = new WelcomeMailableStub;
$mailable->cc('taylor@laravel.com');
$this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc('taylor@laravel.com', 'Taylor Otwell');
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell'));
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc(['taylor@laravel.com']);
$this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));
$this->assertFalse($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell'));

$mailable = new WelcomeMailableStub;
$mailable->cc([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]);
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell'));
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc(new MailableTestUserStub);
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc(new MailableTestUserStub));
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc(collect([new MailableTestUserStub]));
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc);
$this->assertTrue($mailable->hasCc(new MailableTestUserStub));
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc(collect([new MailableTestUserStub, new MailableTestUserStub]));
$this->assertEquals([
['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com'],
['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com'],
], $mailable->cc);
$this->assertTrue($mailable->hasCc(new MailableTestUserStub));
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->cc(['taylor@laravel.com', 'not-taylor@laravel.com']);
$this->assertEquals([
['name' => null, 'address' =>'taylor@laravel.com'],
['name' => null, 'address' =>'not-taylor@laravel.com'],
], $mailable->cc);
$this->assertTrue($mailable->hasCc('taylor@laravel.com'));
$this->assertTrue($mailable->hasCc('not-taylor@laravel.com'));
}

public function testMailableSetsBccRecipientsCorrectly()
{
$mailable = new WelcomeMailableStub;
$mailable->bcc('taylor@laravel.com');
$this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc('taylor@laravel.com', 'Taylor Otwell');
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell'));
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc(['taylor@laravel.com']);
$this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));
$this->assertFalse($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell'));

$mailable = new WelcomeMailableStub;
$mailable->bcc([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]);
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell'));
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc(new MailableTestUserStub);
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc(new MailableTestUserStub));
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc(collect([new MailableTestUserStub]));
$this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc);
$this->assertTrue($mailable->hasBcc(new MailableTestUserStub));
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc(collect([new MailableTestUserStub, new MailableTestUserStub]));
$this->assertEquals([
['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com'],
['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com'],
], $mailable->bcc);
$this->assertTrue($mailable->hasBcc(new MailableTestUserStub));
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));

$mailable = new WelcomeMailableStub;
$mailable->bcc(['taylor@laravel.com', 'not-taylor@laravel.com']);
$this->assertEquals([
['name' => null, 'address' =>'taylor@laravel.com'],
['name' => null, 'address' =>'not-taylor@laravel.com'],
], $mailable->bcc);
$this->assertTrue($mailable->hasBcc('taylor@laravel.com'));
$this->assertTrue($mailable->hasBcc('not-taylor@laravel.com'));
}

public function testMailableSetsReplyToCorrectly()
{
$mailable = new WelcomeMailableStub;
Expand Down
24 changes: 20 additions & 4 deletions tests/Notifications/NotificationMailMessageTest.php
Expand Up @@ -18,11 +18,27 @@ public function testTemplate()
$this->assertSame('notifications::foo', $message->markdown);
}

public function testHtmlAndPlainView()
{
$message = new MailMessage;

$this->assertNull($message->view);
$this->assertSame([], $message->viewData);

$message->view(['notifications::foo', 'notifications::bar'], [
'foo' => 'bar',
]);

$this->assertSame('notifications::foo', $message->view[0]);
$this->assertSame('notifications::bar', $message->view[1]);
$this->assertSame(['foo' => 'bar'], $message->viewData);
}

public function testHtmlView()
{
$message = new MailMessage;

$this->assertSame(null, $message->view);
$this->assertNull($message->view);
$this->assertSame([], $message->viewData);

$message->view('notifications::foo', [
Expand All @@ -37,14 +53,14 @@ public function testPlainView()
{
$message = new MailMessage;

$this->assertSame(null, $message->textView);
$this->assertNull($message->view);
$this->assertSame([], $message->viewData);

$message->text('notifications::foo', [
$message->view([null, 'notifications::foo'], [
'foo' => 'bar',
]);

$this->assertSame('notifications::foo', $message->textView);
$this->assertSame('notifications::foo', $message->view[1]);
$this->assertSame(['foo' => 'bar'], $message->viewData);
}

Expand Down
11 changes: 10 additions & 1 deletion tests/Notifications/NotificationSendQueuedNotificationTest.php
Expand Up @@ -3,11 +3,12 @@
namespace Illuminate\Tests\Notifications;

use Illuminate\Contracts\Database\ModelIdentifier;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\AnonymousNotifiable;
use Illuminate\Notifications\ChannelManager;
use Illuminate\Notifications\Notifiable;
use Illuminate\Notifications\SendQueuedNotifications;
use Illuminate\Support\Collection;
use Illuminate\Tests\Integration\Notifications\NotifiableUser;
use Mockery as m;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -52,3 +53,11 @@ public function testSerializationOfNormalNotifiable()
$this->assertStringContainsString($serializedNotifiable, $serialized);
}
}

class NotifiableUser extends Model
{
use Notifiable;

public $table = 'users';
public $timestamps = false;
}

0 comments on commit 0001ade

Please sign in to comment.