Skip to content

Commit

Permalink
Merge forwardport of #11320 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11320.patch (created by @marinagociu) based on commit(s):
  1. 0888e8c
  2. 3fc3c1d
  3. 3c3168b
  4. 86f1419
  5. 16590f0

Fixed GitHub Issues in 2.3-develop branch:
  - #10502: Fatal error: Call getTranslateInline of null when generating some sitemap with errors (reported by @Koc)
  • Loading branch information
magento-engcom-team authored Feb 7, 2018
2 parents 1dcb55d + 2e90684 commit 3b58efc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
4 changes: 1 addition & 3 deletions app/code/Magento/Sitemap/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public function scheduledGenerateSitemaps()
$sitemap->generateXml();
} catch (\Exception $e) {
$errors[] = $e->getMessage();
throw $e;
}
}

Expand All @@ -122,8 +121,7 @@ public function scheduledGenerateSitemaps()
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
) {
$translate = $this->_translateModel->getTranslateInline();
$this->_translateModel->setTranslateInline(false);
$this->inlineTranslation->suspend();

$this->_transportBuilder->setTemplateIdentifier(
$this->_scopeConfig->getValue(
Expand Down
62 changes: 57 additions & 5 deletions app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

/**
* Class ObserverTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ObserverTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -96,11 +100,11 @@ protected function setUp()
);
}

/**
* @expectedException \Exception
*/
public function testScheduledGenerateSitemapsThrowsException()
public function testScheduledGenerateSitemapsSendsExceptionEmail()
{
$exception = 'Sitemap Exception';
$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);

$this->scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);

$this->collectionFactoryMock->expects($this->once())
Expand All @@ -111,7 +115,55 @@ public function testScheduledGenerateSitemapsThrowsException()
->method('getIterator')
->willReturn(new \ArrayIterator([$this->sitemapMock]));

$this->sitemapMock->expects($this->once())->method('generateXml')->willThrowException(new \Exception());
$this->sitemapMock->expects($this->once())
->method('generateXml')
->willThrowException(new \Exception($exception));

$this->scopeConfigMock->expects($this->at(1))
->method('getValue')
->with(
\Magento\Sitemap\Model\Observer::XML_PATH_ERROR_RECIPIENT,
\Magento\Store\Model\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' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
'store' => \Magento\Store\Model\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->observer->scheduledGenerateSitemaps();
}
Expand Down

0 comments on commit 3b58efc

Please sign in to comment.