Skip to content

Commit b0c7944

Browse files
committed
Merge pull request #267 from magento-nord/develop
[NORD] Bug fixes
2 parents 10f06c6 + e164e56 commit b0c7944

File tree

5 files changed

+212
-6
lines changed

5 files changed

+212
-6
lines changed

app/code/Magento/CatalogImportExport/Model/Export/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ protected function getExportData()
802802
}
803803
}
804804
} catch (\Exception $e) {
805-
$this->_logger->logException($e);
805+
$this->_logger->critical($e);
806806
}
807807
return $exportData;
808808
}

app/code/Magento/ConfigurableProduct/Model/Resource/Product/Type/Configurable.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ public function getConfigurableOptions($product, $attributes)
180180
implode(
181181
' AND ',
182182
[
183-
$this->_getReadAdapter()->quoteInto(
184-
'entity_value.entity_type_id = ?',
185-
$product->getEntityTypeId()
186-
),
187183
'entity_value.attribute_id = super_attribute.attribute_id',
188184
'entity_value.store_id = 0',
189185
'entity_value.entity_id = product_link.product_id'

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,14 @@ public function subscribe($email)
442442
$this->setStatusChanged(true);
443443

444444
try {
445-
$this->save();
446445
if ($isConfirmNeed === true
447446
&& $isOwnSubscribes === false
448447
) {
449448
$this->sendConfirmationRequestEmail();
450449
} else {
451450
$this->sendConfirmationSuccessEmail();
452451
}
452+
$this->save();
453453
return $this->getStatus();
454454
} catch (\Exception $e) {
455455
throw new \Exception($e->getMessage());
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Newsletter\Test\Unit\Model;
7+
8+
class SubscriberTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Newsletter\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
12+
*/
13+
protected $newsletterData;
14+
15+
/**
16+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $scopeConfig;
19+
20+
/**
21+
* @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject
22+
*/
23+
protected $transportBuilder;
24+
25+
/**
26+
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
protected $storeManager;
29+
30+
/**
31+
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
protected $customerSession;
34+
35+
/**
36+
* @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $customerRepository;
39+
40+
/**
41+
* @var \Magento\Customer\Api\AccountManagementInterface|\PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
protected $customerAccountManagement;
44+
45+
/**
46+
* @var \Magento\Framework\Translate\Inline\StateInterface|\PHPUnit_Framework_MockObject_MockObject
47+
*/
48+
protected $inlineTranslation;
49+
50+
/**
51+
* @var \Magento\Newsletter\Model\Resource\Subscriber|\PHPUnit_Framework_MockObject_MockObject
52+
*/
53+
protected $resource;
54+
55+
/**
56+
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
57+
*/
58+
protected $objectManager;
59+
60+
/**
61+
* @var \Magento\Newsletter\Model\Subscriber
62+
*/
63+
protected $subscriber;
64+
65+
public function setUp()
66+
{
67+
$this->newsletterData = $this->getMock('Magento\Newsletter\Helper\Data', [], [], '', false);
68+
$this->scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
69+
$this->transportBuilder = $this->getMock(
70+
'Magento\Framework\Mail\Template\TransportBuilder',
71+
[
72+
'setTemplateIdentifier',
73+
'setTemplateOptions',
74+
'setTemplateVars',
75+
'setFrom',
76+
'addTo',
77+
'getTransport'
78+
],
79+
[],
80+
'',
81+
false
82+
);
83+
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
84+
$this->customerSession = $this->getMock(
85+
'Magento\Customer\Model\Session',
86+
[
87+
'isLoggedIn',
88+
'getCustomerDataObject',
89+
'getCustomerId'
90+
],
91+
[],
92+
'',
93+
false
94+
);
95+
$this->customerRepository = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface');
96+
$this->customerAccountManagement = $this->getMock('Magento\Customer\Api\AccountManagementInterface');
97+
$this->inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface');
98+
$this->resource = $this->getMock(
99+
'Magento\Newsletter\Model\Resource\Subscriber',
100+
[
101+
'loadByEmail',
102+
'getIdFieldName',
103+
'save'
104+
],
105+
[],
106+
'',
107+
false
108+
);
109+
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
110+
111+
$this->subscriber = $this->objectManager->getObject(
112+
'Magento\Newsletter\Model\Subscriber',
113+
[
114+
'newsletterData' => $this->newsletterData,
115+
'scopeConfig' => $this->scopeConfig,
116+
'transportBuilder' => $this->transportBuilder,
117+
'storeManager' => $this->storeManager,
118+
'customerSession' => $this->customerSession,
119+
'customerRepository' => $this->customerRepository,
120+
'customerAccountManagement' => $this->customerAccountManagement,
121+
'inlineTranslation' => $this->inlineTranslation,
122+
'resource' => $this->resource
123+
]
124+
);
125+
}
126+
127+
public function testSubscribe()
128+
{
129+
$email = '[email protected]';
130+
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
131+
[
132+
'subscriber_status' => 3,
133+
'subscriber_email' => $email,
134+
'name' => 'subscriber_name'
135+
]
136+
);
137+
$this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
138+
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
139+
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
140+
$customerDataModel = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface');
141+
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
142+
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
143+
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
144+
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
145+
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
146+
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
147+
$this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
148+
$this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
149+
$this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
150+
$this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
151+
$this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
152+
$storeModel = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false);
153+
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn('[email protected]');
154+
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
155+
$storeModel->expects($this->any())->method('getId')->willReturn(1);
156+
$transport = $this->getMock('\Magento\Framework\Mail\TransportInterface');
157+
$this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
158+
$transport->expects($this->any())->method('sendMessage')->willReturnSelf();
159+
$inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface');
160+
$inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
161+
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
162+
$this->assertEquals(1, $this->subscriber->subscribe($email));
163+
}
164+
}

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,50 @@ public function verifyRow(array $rowData)
125125
);
126126
}
127127
}
128+
129+
/**
130+
* Verifies if exception processing works properly
131+
*
132+
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
133+
*/
134+
public function testExceptionInGetExportData()
135+
{
136+
$exception = new \Exception('Error');
137+
138+
$rowCustomizerMock = $this->getMockBuilder('Magento\CatalogImportExport\Model\Export\RowCustomizerInterface')
139+
->disableOriginalConstructor()
140+
->getMock();
141+
142+
$loggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
143+
144+
$directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
145+
$directoryMock->expects($this->any())->method('getParentDirectory')->will($this->returnValue('some#path'));
146+
$directoryMock->expects($this->any())->method('isWritable')->will($this->returnValue(true));
147+
148+
$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
149+
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));
150+
151+
$exportAdapter = new \Magento\ImportExport\Model\Export\Adapter\Csv($filesystemMock);
152+
153+
$rowCustomizerMock->expects($this->once())->method('prepareData')->willThrowException($exception);
154+
$loggerMock->expects($this->once())->method('critical')->with($exception);
155+
156+
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
157+
'\Magento\Catalog\Model\Resource\Product\Collection'
158+
);
159+
160+
/** @var \Magento\CatalogImportExport\Model\Export\Product $model */
161+
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
162+
'Magento\CatalogImportExport\Model\Export\Product',
163+
[
164+
'rowCustomizer' => $rowCustomizerMock,
165+
'logger' => $loggerMock,
166+
'collection' => $collection
167+
]
168+
);
169+
170+
171+
$data = $model->setWriter($exportAdapter)->export();
172+
$this->assertEmpty($data);
173+
}
128174
}

0 commit comments

Comments
 (0)