Skip to content

Commit

Permalink
MAGETWO-69668: [#7291] Change the default contact form email template…
Browse files Browse the repository at this point in the history
… to HTML #9786

 - fixed issue with current store id
  • Loading branch information
Oleksii Korshenko committed Jun 21, 2017
1 parent 2bc0c82 commit d7c4eb2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
17 changes: 15 additions & 2 deletions app/code/Magento/Contact/Model/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
namespace Magento\Contact\Model;

use Magento\Framework\Mail\Template\TransportBuilder;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Translate\Inline\StateInterface;
use Magento\Store\Model\StoreManagerInterface;

class Mail implements MailInterface
{
Expand All @@ -26,18 +28,29 @@ class Mail implements MailInterface
private $inlineTranslation;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* Initialize dependencies.
*
* @param ConfigInterface $contactsConfig
* @param TransportBuilder $transportBuilder
* @param StateInterface $inlineTranslation
* @param StoreManagerInterface|null $storeManager
*/
public function __construct(
ConfigInterface $contactsConfig,
TransportBuilder $transportBuilder,
StateInterface $inlineTranslation
StateInterface $inlineTranslation,
StoreManagerInterface $storeManager = null
) {
$this->contactsConfig = $contactsConfig;
$this->transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->storeManager = $storeManager ?:
ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand All @@ -59,7 +72,7 @@ public function send($replyTo, array $variables)
->setTemplateOptions(
[
'area' => 'frontend',
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
Expand Down
21 changes: 18 additions & 3 deletions app/code/Magento/Contact/Test/Unit/Model/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

use Magento\Contact\Model\ConfigInterface;
use Magento\Contact\Model\Mail;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;

class MailTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -32,6 +34,11 @@ class MailTest extends \PHPUnit_Framework_TestCase
*/
private $inlineTranslationMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $storeManagerMock;

/**
* @var Mail
*/
Expand All @@ -50,10 +57,13 @@ protected function setUp()
)->disableOriginalConstructor(
)->getMock();

$this->storeManagerMock = $this->getMock(StoreManagerInterface::class);

$this->mail = new Mail(
$this->configMock,
$this->transportBuilderMock,
$this->inlineTranslationMock
$this->inlineTranslationMock,
$this->storeManagerMock
);
}

Expand All @@ -64,15 +74,20 @@ public function testSendMail()

$transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false);

$store = $this->getMock(StoreInterface::class);
$store->expects($this->once())->method('getId')->willReturn(555);

$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($store);

$this->transportBuilderMock->expects($this->once())
->method('setTemplateIdentifier')
->will($this->returnSelf());

$this->transportBuilderMock->expects($this->once())
->method('setTemplateOptions')
->with([
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
'area' => 'frontend',
'store' => 555,
])
->will($this->returnSelf());

Expand Down

0 comments on commit d7c4eb2

Please sign in to comment.