-
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
1 parent
85a2a56
commit a04cbf2
Showing
2 changed files
with
176 additions
and
66 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
app/code/Magento/Sitemap/Test/Unit/Model/EmailNotificationTest.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,134 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types = 1); | ||
|
||
namespace Magento\Sitemap\Test\Unit\Model; | ||
|
||
use Magento\Backend\App\Area\FrontNameResolver; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\Mail\Template\TransportBuilder; | ||
use Magento\Framework\Mail\TransportInterface; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\Framework\Translate\Inline\StateInterface; | ||
use Magento\Sitemap\Model\EmailNotification; | ||
use Magento\Sitemap\Model\Observer; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Store\Model\Store; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Test for Magento\Sitemap\Model\EmailNotification | ||
*/ | ||
class EmailNotificationTest extends TestCase | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var EmailNotification | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $scopeConfigMock; | ||
|
||
/** | ||
* @var TransportBuilder|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $transportBuilderMock; | ||
|
||
/** | ||
* @var StateInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $inlineTranslationMock; | ||
|
||
/** | ||
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $objectManagerMock; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class) | ||
->getMock(); | ||
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class) | ||
->getMock(); | ||
$this->transportBuilderMock = $this->getMockBuilder(TransportBuilder::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->inlineTranslationMock = $this->getMockBuilder(StateInterface::class) | ||
->getMock(); | ||
|
||
$this->objectManager = new ObjectManager($this); | ||
$this->model = $this->objectManager->getObject( | ||
EmailNotification::class, | ||
[ | ||
'inlineTranslation' => $this->inlineTranslationMock, | ||
'scopeConfig' => $this->scopeConfigMock, | ||
'transportBuilder' => $this->transportBuilderMock, | ||
] | ||
); | ||
} | ||
|
||
public function testSendErrors() | ||
{ | ||
$exception = 'Sitemap Exception'; | ||
$transport = $this->createMock(TransportInterface::class); | ||
|
||
$this->scopeConfigMock->expects($this->at(0)) | ||
->method('getValue') | ||
->with( | ||
Observer::XML_PATH_ERROR_TEMPLATE, | ||
ScopeInterface::SCOPE_STORE | ||
) | ||
->willReturn('error-recipient@example.com'); | ||
|
||
$this->inlineTranslationMock->expects($this->once()) | ||
->method('suspend'); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('setTemplateIdentifier') | ||
->will($this->returnSelf()); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('setTemplateOptions') | ||
->with([ | ||
'area' => FrontNameResolver::AREA_CODE, | ||
'store' => Store::DEFAULT_STORE_ID, | ||
]) | ||
->will($this->returnSelf()); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('setTemplateVars') | ||
->with(['warnings' => $exception]) | ||
->will($this->returnSelf()); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('setFrom') | ||
->will($this->returnSelf()); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('addTo') | ||
->will($this->returnSelf()); | ||
|
||
$this->transportBuilderMock->expects($this->once()) | ||
->method('getTransport') | ||
->willReturn($transport); | ||
|
||
$transport->expects($this->once()) | ||
->method('sendMessage'); | ||
|
||
$this->inlineTranslationMock->expects($this->once()) | ||
->method('resume'); | ||
|
||
$this->model->sendErrors(['Sitemap Exception']); | ||
} | ||
} |
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