Skip to content

Commit 2e90684

Browse files
⏫ Forwardport of #11320 to 2.3-develop branch
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)
1 parent 8e77e2f commit 2e90684

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

app/code/Magento/Sitemap/Model/Observer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ public function scheduledGenerateSitemaps()
113113
$sitemap->generateXml();
114114
} catch (\Exception $e) {
115115
$errors[] = $e->getMessage();
116-
throw $e;
117116
}
118117
}
119118

@@ -122,8 +121,7 @@ public function scheduledGenerateSitemaps()
122121
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
123122
)
124123
) {
125-
$translate = $this->_translateModel->getTranslateInline();
126-
$this->_translateModel->setTranslateInline(false);
124+
$this->inlineTranslation->suspend();
127125

128126
$this->_transportBuilder->setTemplateIdentifier(
129127
$this->_scopeConfig->getValue(

app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

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

10+
/**
11+
* Class ObserverTest
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
1014
class ObserverTest extends \PHPUnit\Framework\TestCase
1115
{
1216
/**
@@ -96,11 +100,11 @@ protected function setUp()
96100
);
97101
}
98102

99-
/**
100-
* @expectedException \Exception
101-
*/
102-
public function testScheduledGenerateSitemapsThrowsException()
103+
public function testScheduledGenerateSitemapsSendsExceptionEmail()
103104
{
105+
$exception = 'Sitemap Exception';
106+
$transport = $this->createMock(\Magento\Framework\Mail\TransportInterface::class);
107+
104108
$this->scopeConfigMock->expects($this->once())->method('isSetFlag')->willReturn(true);
105109

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

114-
$this->sitemapMock->expects($this->once())->method('generateXml')->willThrowException(new \Exception());
118+
$this->sitemapMock->expects($this->once())
119+
->method('generateXml')
120+
->willThrowException(new \Exception($exception));
121+
122+
$this->scopeConfigMock->expects($this->at(1))
123+
->method('getValue')
124+
->with(
125+
\Magento\Sitemap\Model\Observer::XML_PATH_ERROR_RECIPIENT,
126+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
127+
)
128+
->willReturn('[email protected]');
129+
130+
$this->inlineTranslationMock->expects($this->once())
131+
->method('suspend');
132+
133+
$this->transportBuilderMock->expects($this->once())
134+
->method('setTemplateIdentifier')
135+
->will($this->returnSelf());
136+
137+
$this->transportBuilderMock->expects($this->once())
138+
->method('setTemplateOptions')
139+
->with([
140+
'area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE,
141+
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
142+
])
143+
->will($this->returnSelf());
144+
145+
$this->transportBuilderMock->expects($this->once())
146+
->method('setTemplateVars')
147+
->with(['warnings' => $exception])
148+
->will($this->returnSelf());
149+
150+
$this->transportBuilderMock->expects($this->once())
151+
->method('setFrom')
152+
->will($this->returnSelf());
153+
154+
$this->transportBuilderMock->expects($this->once())
155+
->method('addTo')
156+
->will($this->returnSelf());
157+
158+
$this->transportBuilderMock->expects($this->once())
159+
->method('getTransport')
160+
->willReturn($transport);
161+
162+
$transport->expects($this->once())
163+
->method('sendMessage');
164+
165+
$this->inlineTranslationMock->expects($this->once())
166+
->method('resume');
115167

116168
$this->observer->scheduledGenerateSitemaps();
117169
}

0 commit comments

Comments
 (0)