Skip to content

Commit

Permalink
Merge pull request #4930 from magento-engcom/2.3-develop-prs
Browse files Browse the repository at this point in the history
[Magento Community Engineering] Community Contributions - 2.3-develop
  • Loading branch information
VladimirZaets authored Oct 30, 2019
2 parents 7e31850 + 1bd54a6 commit 65763df
Show file tree
Hide file tree
Showing 36 changed files with 1,283 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\AdvancedSearch\Test\Unit\Model\Recommendations;

use Magento\AdvancedSearch\Model\Recommendations\DataProvider;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\AdvancedSearch\Model\ResourceModel\Recommendations;
use Magento\AdvancedSearch\Model\ResourceModel\RecommendationsFactory;
use Magento\Search\Model\QueryResult;
use Magento\Search\Model\QueryResultFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
use Magento\Catalog\Model\Layer as SearchLayer;
use Magento\Store\Model\ScopeInterface;
use Magento\Search\Model\QueryInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*
* Class \Magento\AdvancedSearch\Test\Unit\Model\Recommendations\DataProviderTest
*/
class DataProviderTest extends \PHPUnit\Framework\TestCase
{
/**
* @var DataProvider;
*/
private $model;

/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ScopeConfigInterface
*/
private $scopeConfigMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Resolver
*/
private $layerResolverMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|SearchLayer
*/
private $searchLayerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|RecommendationsFactory
*/
private $recommendationsFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Recommendations
*/
private $recommendationsMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|Resolver
*/
private $queryResultFactory;

/**
* Set up test environment.
*
* @return void
*/
protected function setUp()
{
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->layerResolverMock = $this->getMockBuilder(Resolver::class)
->disableOriginalConstructor()
->setMethods(['get'])
->getMock();

$this->searchLayerMock = $this->createMock(SearchLayer::class);

$this->layerResolverMock->expects($this->any())
->method('get')
->will($this->returnValue($this->searchLayerMock));

$this->recommendationsFactoryMock = $this->getMockBuilder(RecommendationsFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->recommendationsMock = $this->createMock(Recommendations::class);

$this->queryResultFactory = $this->getMockBuilder(QueryResultFactory::class)
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->model = $this->objectManagerHelper->getObject(
DataProvider::class,
[
'scopeConfig' => $this->scopeConfigMock,
'layerResolver' => $this->layerResolverMock,
'recommendationsFactory' => $this->recommendationsFactoryMock,
'queryResultFactory' => $this->queryResultFactory
]
);
}

/**
* Test testGetItems() when Search Recommendations disabled.
*
* @return void
*/
public function testGetItemsWhenDisabledSearchRecommendations()
{
$isEnabledSearchRecommendations = false;

/** @var $queryInterfaceMock QueryInterface */
$queryInterfaceMock = $this->createMock(QueryInterface::class);

$this->scopeConfigMock->expects($this->any())
->method('isSetFlag')
->with('catalog/search/search_recommendations_enabled', ScopeInterface::SCOPE_STORE)
->willReturn($isEnabledSearchRecommendations);

$result = $this->model->getItems($queryInterfaceMock);
$this->assertEquals([], $result);
}

/**
* Test testGetItems() when Search Recommendations enabled.
*
* @return void
*/
public function testGetItemsWhenEnabledSearchRecommendations()
{
$storeId = 1;
$searchRecommendationsCountConfig = 2;
$isEnabledSearchRecommendations = true;
$queryText = 'test';

/** @var $queryInterfaceMock QueryInterface */
$queryInterfaceMock = $this->createMock(QueryInterface::class);
$queryInterfaceMock->expects($this->any())->method('getQueryText')->willReturn($queryText);

$this->scopeConfigMock->expects($this->any())
->method('isSetFlag')
->with('catalog/search/search_recommendations_enabled', ScopeInterface::SCOPE_STORE)
->willReturn($isEnabledSearchRecommendations);

$this->scopeConfigMock->expects($this->any())
->method('getValue')
->with('catalog/search/search_recommendations_count', ScopeInterface::SCOPE_STORE)
->willReturn($searchRecommendationsCountConfig);

$productCollectionMock = $this->createMock(ProductCollection::class);
$productCollectionMock->expects($this->any())->method('getStoreId')->willReturn($storeId);

$this->searchLayerMock->expects($this->any())->method('getProductCollection')
->willReturn($productCollectionMock);

$this->recommendationsFactoryMock->expects($this->any())->method('create')
->willReturn($this->recommendationsMock);

$this->recommendationsMock->expects($this->any())->method('getRecommendationsByQuery')
->with($queryText, ['store_id' => $storeId], $searchRecommendationsCountConfig)
->willReturn(
[
[
'query_text' => 'a',
'num_results' => 3
],
[
'query_text' => 'b',
'num_results' => 2
]
]
);
$queryResultMock = $this->createMock(QueryResult::class);
$this->queryResultFactory->expects($this->any())->method('create')->willReturn($queryResultMock);

$result = $this->model->getItems($queryInterfaceMock);
$this->assertEquals(2, count($result));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<test name="AdminCheckLocaleAndDeveloperConfigInDeveloperModeTest">
<annotations>
<features value="Backend"/>
<stories value="Menu Navigation"/>
<title value="Check locale dropdown and developer configuration page are available in developer mode"/>
<description value="Check locale dropdown and developer configuration page are available in developer mode"/>
<group value="backend"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<test name="AdminCheckLocaleAndDeveloperConfigInProductionModeTest">
<annotations>
<features value="Backend"/>
<stories value="Menu Navigation"/>
<title value="Check locale dropdown and developer configuration page are not available in production mode"/>
<description value="Check locale dropdown and developer configuration page are not available in production mode"/>
<testCaseId value="MC-14106" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<requiredEntity createDataKey="fixedBundleOption"/>
<requiredEntity createDataKey="createSimpleProductTwo"/>
</createData>
<magentoCLI command="indexer:reindex" arguments="cataloginventory_stock catalogsearch_fulltext" stepKey="reindex"/>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
</before>
<after>
<deleteData createDataKey="createDynamicBundle" stepKey="deleteDynamicBundleProduct"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CardinalCommerce\Test\Unit\Model\Response;

use Magento\CardinalCommerce\Model\Response\JwtParser;
use Magento\CardinalCommerce\Model\Config;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\CardinalCommerce\Model\JwtManagement;
use Magento\CardinalCommerce\Model\Response\JwtPayloadValidatorInterface;
use Magento\Framework\Exception\LocalizedException;

/**
* Class \Magento\CardinalCommerce\Test\Unit\Model\Response\JwtParserTest
*/
class JwtParserTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var JwtParser
*/
private $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject | Config
*/
private $configMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject | JwtManagement
*/
private $jwtManagementMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject | JwtPayloadValidatorInterface
*/
private $jwtPayloadValidatorMock;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->objectManager = new ObjectManager($this);

$this->configMock = $this->getMockBuilder(Config::class)
->setMethods(['getApiKey', 'isDebugModeEnabled'])
->disableOriginalConstructor()
->getMock();

$this->jwtManagementMock = $this->getMockBuilder(JwtManagement::class)
->setMethods(['decode'])
->disableOriginalConstructor()
->getMock();

$this->jwtPayloadValidatorMock = $this->getMockBuilder(JwtPayloadValidatorInterface::class)
->setMethods(['validate'])
->disableOriginalConstructor()
->getMock();

$this->model = $this->objectManager->getObject(
JwtParser::class,
[
'jwtManagement' => $this->jwtManagementMock,
'config' => $this->configMock,
'tokenValidator' => $this->jwtPayloadValidatorMock
]
);

$this->configMock->expects($this->any())
->method('getApiKey')
->willReturn('API Key');

$this->configMock->expects($this->any())
->method('isDebugModeEnabled')
->willReturn(false);

$this->jwtManagementMock->expects($this->any())
->method('decode')
->with('string_to_test', 'API Key')
->willReturn(['mockResult' => 'jwtPayload']);
}

/**
* Tests Jwt Parser execute with the result and no exception.
*/
public function testExecuteWithNoException()
{
/* Validate Success */
$this->jwtPayloadValidatorMock->expects($this->any())
->method('validate')
->with(['mockResult' => 'jwtPayload'])
->willReturn(true);

/* Assert the result of function */
$jwtPayload = $this->model->execute('string_to_test');
$this->assertEquals(
['mockResult' => 'jwtPayload'],
$jwtPayload
);
}

/**
* Tests Jwt Parser execute with exception and no result.
*/
public function testExecuteWithException()
{
/* Validate Fail */
$this->jwtPayloadValidatorMock->expects($this->any())
->method('validate')
->with(['mockResult' => 'jwtPayload'])
->willReturn(false);

$this->expectException(LocalizedException::class);
$this->expectExceptionMessage(
'Authentication Failed. Your card issuer cannot authenticate this card. ' .
'Please select another card or form of payment to complete your purchase.'
);

/* Execute function */
$this->model->execute('string_to_test');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<test name="DisplayRefreshCacheAfterChangingCategoryPageLayoutTest">
<annotations>
<features value="Catalog"/>
<stories value="Category Layout Change"/>
<title value="'Refresh cache' admin notification is displayed when changing category page layout"/>
<description value="'Refresh cache' message is not displayed when changing category page layout"/>
<severity value="MAJOR"/>
Expand Down
Loading

0 comments on commit 65763df

Please sign in to comment.