-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2.2-develop' into 10128
- Loading branch information
Showing
48 changed files
with
1,070 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/ConfigTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Test\Unit\Model\ResourceModel; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
|
||
/** | ||
* Test for Magento\Catalog\Model\ResourceModel\Config | ||
*/ | ||
class ConfigTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var \Magento\Catalog\Model\ResourceModel\Config | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $eavConfig; | ||
|
||
protected function setUp() | ||
{ | ||
$objectManager = new ObjectManager($this); | ||
|
||
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); | ||
$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); | ||
$this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class); | ||
|
||
$this->model = $objectManager->getObject( | ||
\Magento\Catalog\Model\ResourceModel\Config::class, | ||
[ | ||
'resource' => $this->resource, | ||
'storeManager' => $this->storeManager, | ||
'eavConfig' => $this->eavConfig, | ||
] | ||
); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testGetAttributesUsedForSortBy() | ||
{ | ||
$expression = 'someExpression'; | ||
$storeId = 1; | ||
$entityTypeId = 4; | ||
|
||
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); | ||
$selectMock = $this->createMock(\Magento\Framework\DB\Select::class); | ||
$storeMock = $this->createMock(\Magento\Store\Api\Data\StoreInterface::class); | ||
$entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class); | ||
|
||
$this->resource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock); | ||
|
||
$connectionMock->expects($this->once())->method('getCheckSql') | ||
->with('al.value IS NULL', 'main_table.frontend_label', 'al.value') | ||
->willReturn($expression); | ||
$connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($selectMock); | ||
|
||
$this->resource->expects($this->exactly(3))->method('getTableName')->withConsecutive( | ||
['eav_attribute'], | ||
['catalog_eav_attribute'], | ||
['eav_attribute_label'] | ||
)->willReturnOnConsecutiveCalls('eav_attribute', 'catalog_eav_attribute', 'eav_attribute_label'); | ||
|
||
$this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock); | ||
$storeMock->expects($this->once())->method('getId')->willReturn($storeId); | ||
|
||
$this->eavConfig->expects($this->once())->method('getEntityType')->willReturn($entityTypeMock); | ||
$entityTypeMock->expects($this->once())->method('getId')->willReturn($entityTypeId); | ||
|
||
$selectMock->expects($this->once())->method('from') | ||
->with(['main_table' => 'eav_attribute'])->willReturn($selectMock); | ||
$selectMock->expects($this->once())->method('join')->with( | ||
['additional_table' => 'catalog_eav_attribute'], | ||
'main_table.attribute_id = additional_table.attribute_id' | ||
)->willReturn($selectMock); | ||
$selectMock->expects($this->once())->method('joinLeft') | ||
->with( | ||
['al' => 'eav_attribute_label'], | ||
'al.attribute_id = main_table.attribute_id AND al.store_id = ' . $storeId, | ||
['store_label' => $expression] | ||
)->willReturn($selectMock); | ||
$selectMock->expects($this->exactly(2))->method('where')->withConsecutive( | ||
['main_table.entity_type_id = ?', $entityTypeId], | ||
['additional_table.used_for_sort_by = ?', 1] | ||
)->willReturn($selectMock); | ||
|
||
$connectionMock->expects($this->once())->method('fetchAll')->with($selectMock); | ||
|
||
$this->model->getAttributesUsedForSortBy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Storage/DbStorageTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Storage; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
use Magento\CatalogUrlRewrite\Model\Storage\DbStorage; | ||
use PHPUnit\Framework\TestCase; | ||
use Magento\UrlRewrite\Service\V1\Data\UrlRewriteFactory; | ||
use PHPUnit_Framework_MockObject_MockObject as Mock; | ||
use Magento\Framework\Api\DataObjectHelper; | ||
use Magento\Framework\DB\Adapter\AdapterInterface; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; | ||
|
||
class DbStorageTest extends TestCase | ||
{ | ||
/** | ||
* @var DbStorage | ||
*/ | ||
private $storage; | ||
|
||
/** | ||
* @var UrlRewriteFactory|Mock | ||
*/ | ||
private $urlRewriteFactory; | ||
|
||
/** | ||
* @var DataObjectHelper|Mock | ||
*/ | ||
private $dataObjectHelper; | ||
|
||
/** | ||
* @var AdapterInterface|Mock | ||
*/ | ||
private $connectionMock; | ||
|
||
/** | ||
* @var Select|Mock | ||
*/ | ||
private $select; | ||
|
||
/** | ||
* @var ResourceConnection|Mock | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @inheritDoc | ||
* | ||
* Preparing mocks and target object. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->urlRewriteFactory = $this | ||
->getMockBuilder(UrlRewriteFactory::class) | ||
->setMethods(['create']) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->dataObjectHelper = $this->createMock(DataObjectHelper::class); | ||
$this->connectionMock = $this->createMock(AdapterInterface::class); | ||
$this->select = $this->createPartialMock( | ||
Select::class, | ||
['from', 'where', 'deleteFromSelect', 'joinLeft'] | ||
); | ||
$this->resource = $this->createMock(ResourceConnection::class); | ||
|
||
$this->resource->expects($this->any()) | ||
->method('getConnection') | ||
->will($this->returnValue($this->connectionMock)); | ||
$this->connectionMock->expects($this->any()) | ||
->method('select') | ||
->will($this->returnValue($this->select)); | ||
|
||
$this->storage = (new ObjectManager($this))->getObject( | ||
DbStorage::class, | ||
[ | ||
'urlRewriteFactory' => $this->urlRewriteFactory, | ||
'dataObjectHelper' => $this->dataObjectHelper, | ||
'resource' => $this->resource, | ||
] | ||
); | ||
} | ||
|
||
public function testPrepareSelect() | ||
{ | ||
//Passing expected parameters, checking select built. | ||
$entityType = 'custom'; | ||
$entityId= 42; | ||
$storeId = 0; | ||
$categoryId = 2; | ||
$redirectType = 301; | ||
//Expecting this methods to be called on select | ||
$this->select | ||
->expects($this->at(2)) | ||
->method('where') | ||
->with('url_rewrite.entity_id IN (?)', $entityId) | ||
->willReturn($this->select); | ||
$this->select | ||
->expects($this->at(3)) | ||
->method('where') | ||
->with('url_rewrite.entity_type IN (?)', $entityType) | ||
->willReturn($this->select); | ||
$this->select | ||
->expects($this->at(4)) | ||
->method('where') | ||
->with('url_rewrite.store_id IN (?)', $storeId) | ||
->willReturn($this->select); | ||
$this->select | ||
->expects($this->at(5)) | ||
->method('where') | ||
->with('url_rewrite.redirect_type IN (?)', $redirectType) | ||
->willReturn($this->select); | ||
$this->select | ||
->expects($this->at(6)) | ||
->method('where') | ||
->with('relation.category_id = ?', $categoryId) | ||
->willReturn($this->select); | ||
//Preparing mocks to be used | ||
$this->select | ||
->expects($this->any()) | ||
->method('from') | ||
->willReturn($this->select); | ||
$this->select | ||
->expects($this->any()) | ||
->method('joinLeft') | ||
->willReturn($this->select); | ||
//Indirectly calling prepareSelect | ||
$this->storage->findOneByData([ | ||
UrlRewrite::ENTITY_ID => $entityId, | ||
UrlRewrite::ENTITY_TYPE => $entityType, | ||
UrlRewrite::STORE_ID => $storeId, | ||
UrlRewrite::REDIRECT_TYPE => $redirectType, | ||
UrlRewrite::METADATA => ['category_id' => $categoryId] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.