Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] add hasReplyTo method to Mailable class #21093

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,18 @@ public function replyTo($address, $name = null)
return $this->setAddress($address, $name, 'replyTo');
}

/**
* Determine if the given recipient is set on the mailable.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs here should say "Determine if the given replyTo is set on the mailable."

They are not a recipient of the mailable.

*
* @param object|array|string $address
* @param string|null $name
* @return bool
*/
public function hasReplyTo($address, $name = null)
{
return $this->hasRecipient($address, $name, 'replyTo');
}

/**
* Set the recipients of the message.
*
Expand Down
47 changes: 47 additions & 0 deletions tests/Mail/MailMailableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,53 @@ public function testMailableSetsRecipientsCorrectly()
$this->assertTrue($mailable->hasTo('taylor@laravel.com'));
}

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

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

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

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

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

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

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

public function testMailableBuildsViewData()
{
$mailable = new WelcomeMailableStub;
Expand Down