-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Graham Wharton
committed
Oct 16, 2018
1 parent
16afc09
commit 47c5f72
Showing
4 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
lib/internal/Magento/Framework/Mail/Template/TransportBuilderByStore.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Mail\Template; | ||
|
||
use Magento\Framework\Mail\MessageInterface; | ||
|
||
/** | ||
* Class TransportBuilderByStore | ||
* | ||
* @deprecated The ability to set From address based on store is now available | ||
* in the \Magento\Framework\Mail\Template\TransportBuilder class | ||
* @see \Magento\Framework\Mail\Template\TransportBuilder::setFromByStore | ||
*/ | ||
class TransportBuilderByStore | ||
{ | ||
/** | ||
* Message. | ||
* | ||
* @var \Magento\Framework\Mail\Message | ||
*/ | ||
protected $message; | ||
|
||
/** | ||
* Sender resolver. | ||
* | ||
* @var \Magento\Framework\Mail\Template\SenderResolverInterface | ||
*/ | ||
private $senderResolver; | ||
|
||
/** | ||
* @param MessageInterface $message | ||
* @param SenderResolverInterface $senderResolver | ||
*/ | ||
public function __construct( | ||
MessageInterface $message, | ||
SenderResolverInterface $senderResolver | ||
) { | ||
$this->message = $message; | ||
$this->senderResolver = $senderResolver; | ||
} | ||
|
||
/** | ||
* Set mail from address by store. | ||
* | ||
* @param string|array $from | ||
* @param string|int $store | ||
* | ||
* @return $this | ||
*/ | ||
public function setFromByStore($from, $store) | ||
{ | ||
$result = $this->senderResolver->resolve($from, $store); | ||
$this->message->clearFrom(); | ||
$this->message->setFrom($result['email'], $result['name']); | ||
|
||
return $this; | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
lib/internal/Magento/Framework/Mail/Test/Unit/Template/TransportBuilderByStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Mail\Test\Unit\Template; | ||
|
||
use Magento\Framework\Mail\Template\TransportBuilderByStore; | ||
|
||
class TransportBuilderByStoreTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \Magento\Framework\Mail\Template\TransportBuilderByStore | ||
*/ | ||
protected $model; | ||
|
||
/** | ||
* @var \Magento\Framework\Mail\Message | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $messageMock; | ||
|
||
/** | ||
* @var \Magento\Framework\Mail\Template\SenderResolverInterface | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $senderResolverMock; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function setUp() | ||
{ | ||
$objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); | ||
$this->messageMock = $this->createMock(\Magento\Framework\Mail\Message::class); | ||
$this->senderResolverMock = $this->createMock(\Magento\Framework\Mail\Template\SenderResolverInterface::class); | ||
|
||
$this->model = $objectManagerHelper->getObject( | ||
TransportBuilderByStore::class, | ||
[ | ||
'message' => $this->messageMock, | ||
'senderResolver' => $this->senderResolverMock, | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testSetFromByStore() | ||
{ | ||
$sender = ['email' => 'from@example.com', 'name' => 'name']; | ||
$store = 1; | ||
$this->senderResolverMock->expects($this->once()) | ||
->method('resolve') | ||
->with($sender, $store) | ||
->willReturn($sender); | ||
$this->messageMock->expects($this->once()) | ||
->method('setFrom') | ||
->with('from@example.com', 'name') | ||
->willReturnSelf(); | ||
$this->messageMock->expects($this->once()) | ||
->method('clearFrom') | ||
->willReturnSelf(); | ||
|
||
$this->model->setFromByStore($sender, $store); | ||
} | ||
} |