Skip to content

Commit

Permalink
Merge pull request #267 from magento-nord/develop
Browse files Browse the repository at this point in the history
[NORD] Bug fixes
  • Loading branch information
vpelipenko committed May 5, 2015
2 parents 10f06c6 + e164e56 commit b0c7944
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ protected function getExportData()
}
}
} catch (\Exception $e) {
$this->_logger->logException($e);
$this->_logger->critical($e);
}
return $exportData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,6 @@ public function getConfigurableOptions($product, $attributes)
implode(
' AND ',
[
$this->_getReadAdapter()->quoteInto(
'entity_value.entity_type_id = ?',
$product->getEntityTypeId()
),
'entity_value.attribute_id = super_attribute.attribute_id',
'entity_value.store_id = 0',
'entity_value.entity_id = product_link.product_id'
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Newsletter/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@ public function subscribe($email)
$this->setStatusChanged(true);

try {
$this->save();
if ($isConfirmNeed === true
&& $isOwnSubscribes === false
) {
$this->sendConfirmationRequestEmail();
} else {
$this->sendConfirmationSuccessEmail();
}
$this->save();
return $this->getStatus();
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
Expand Down
164 changes: 164 additions & 0 deletions app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Newsletter\Test\Unit\Model;

class SubscriberTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Newsletter\Helper\Data|\PHPUnit_Framework_MockObject_MockObject
*/
protected $newsletterData;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $scopeConfig;

/**
* @var \Magento\Framework\Mail\Template\TransportBuilder|\PHPUnit_Framework_MockObject_MockObject
*/
protected $transportBuilder;

/**
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $storeManager;

/**
* @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject
*/
protected $customerSession;

/**
* @var \Magento\Customer\Api\CustomerRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $customerRepository;

/**
* @var \Magento\Customer\Api\AccountManagementInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $customerAccountManagement;

/**
* @var \Magento\Framework\Translate\Inline\StateInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $inlineTranslation;

/**
* @var \Magento\Newsletter\Model\Resource\Subscriber|\PHPUnit_Framework_MockObject_MockObject
*/
protected $resource;

/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManager;

/**
* @var \Magento\Newsletter\Model\Subscriber
*/
protected $subscriber;

public function setUp()
{
$this->newsletterData = $this->getMock('Magento\Newsletter\Helper\Data', [], [], '', false);
$this->scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface');
$this->transportBuilder = $this->getMock(
'Magento\Framework\Mail\Template\TransportBuilder',
[
'setTemplateIdentifier',
'setTemplateOptions',
'setTemplateVars',
'setFrom',
'addTo',
'getTransport'
],
[],
'',
false
);
$this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface');
$this->customerSession = $this->getMock(
'Magento\Customer\Model\Session',
[
'isLoggedIn',
'getCustomerDataObject',
'getCustomerId'
],
[],
'',
false
);
$this->customerRepository = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface');
$this->customerAccountManagement = $this->getMock('Magento\Customer\Api\AccountManagementInterface');
$this->inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface');
$this->resource = $this->getMock(
'Magento\Newsletter\Model\Resource\Subscriber',
[
'loadByEmail',
'getIdFieldName',
'save'
],
[],
'',
false
);
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->subscriber = $this->objectManager->getObject(
'Magento\Newsletter\Model\Subscriber',
[
'newsletterData' => $this->newsletterData,
'scopeConfig' => $this->scopeConfig,
'transportBuilder' => $this->transportBuilder,
'storeManager' => $this->storeManager,
'customerSession' => $this->customerSession,
'customerRepository' => $this->customerRepository,
'customerAccountManagement' => $this->customerAccountManagement,
'inlineTranslation' => $this->inlineTranslation,
'resource' => $this->resource
]
);
}

public function testSubscribe()
{
$email = '[email protected]';
$this->resource->expects($this->any())->method('loadByEmail')->willReturn(
[
'subscriber_status' => 3,
'subscriber_email' => $email,
'name' => 'subscriber_name'
]
);
$this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field');
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true);
$this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true);
$customerDataModel = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface');
$this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel);
$this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getEmail')->willReturn($email);
$this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel);
$customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1);
$customerDataModel->expects($this->any())->method('getId')->willReturn(1);
$this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf();
$this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf();
$storeModel = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false);
$this->scopeConfig->expects($this->any())->method('getValue')->willReturn('[email protected]');
$this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel);
$storeModel->expects($this->any())->method('getId')->willReturn(1);
$transport = $this->getMock('\Magento\Framework\Mail\TransportInterface');
$this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport);
$transport->expects($this->any())->method('sendMessage')->willReturnSelf();
$inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface');
$inlineTranslation->expects($this->any())->method('resume')->willReturnSelf();
$this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf();
$this->assertEquals(1, $this->subscriber->subscribe($email));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,50 @@ public function verifyRow(array $rowData)
);
}
}

/**
* Verifies if exception processing works properly
*
* @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php
*/
public function testExceptionInGetExportData()
{
$exception = new \Exception('Error');

$rowCustomizerMock = $this->getMockBuilder('Magento\CatalogImportExport\Model\Export\RowCustomizerInterface')
->disableOriginalConstructor()
->getMock();

$loggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();

$directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
$directoryMock->expects($this->any())->method('getParentDirectory')->will($this->returnValue('some#path'));
$directoryMock->expects($this->any())->method('isWritable')->will($this->returnValue(true));

$filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
$filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock));

$exportAdapter = new \Magento\ImportExport\Model\Export\Adapter\Csv($filesystemMock);

$rowCustomizerMock->expects($this->once())->method('prepareData')->willThrowException($exception);
$loggerMock->expects($this->once())->method('critical')->with($exception);

$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'\Magento\Catalog\Model\Resource\Product\Collection'
);

/** @var \Magento\CatalogImportExport\Model\Export\Product $model */
$model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\CatalogImportExport\Model\Export\Product',
[
'rowCustomizer' => $rowCustomizerMock,
'logger' => $loggerMock,
'collection' => $collection
]
);


$data = $model->setWriter($exportAdapter)->export();
$this->assertEmpty($data);
}
}

0 comments on commit b0c7944

Please sign in to comment.