-
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 pull request #1269 from magento-tsg/2.1.8-develop-pr21
[TSG] Backporting for 2.1 (pr21) (2.1.8)
- Loading branch information
Showing
84 changed files
with
7,187 additions
and
851 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
146 changes: 146 additions & 0 deletions
146
app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/CategoryTest.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,146 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Catalog\Test\Unit\Model\ResourceModel; | ||
|
||
use Magento\Catalog\Model\Factory; | ||
use Magento\Catalog\Model\ResourceModel\Category; | ||
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory; | ||
use Magento\Eav\Model\Config; | ||
use Magento\Eav\Model\Entity\Attribute; | ||
use Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend; | ||
use Magento\Eav\Model\Entity\Context; | ||
use Magento\Eav\Model\Entity\Type; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\DB\Adapter\AdapterInterface as Adapter; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class CategoryTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Category | ||
*/ | ||
protected $category; | ||
|
||
/** | ||
* @var Context|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $contextMock; | ||
|
||
/** | ||
* @var Select|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $selectMock; | ||
|
||
/** | ||
* @var Adapter|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $connectionMock; | ||
|
||
/** | ||
* @var ResourceConnection|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $resourceMock; | ||
|
||
/** | ||
* @var Config|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $eavConfigMock; | ||
|
||
/** | ||
* @var Type|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $entityType; | ||
|
||
/** | ||
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $storeManagerMock; | ||
|
||
/** | ||
* @var Factory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $factoryMock; | ||
|
||
/** | ||
* @var ManagerInterface|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $managerMock; | ||
|
||
/** | ||
* @var Category\TreeFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $treeFactoryMock; | ||
|
||
/** | ||
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
protected $collectionFactoryMock; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
protected function setUp() | ||
{ | ||
$this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); | ||
$this->selectMock->expects($this->at(2))->method('where')->willReturnSelf(); | ||
$this->selectMock->expects($this->once())->method('from')->willReturnSelf(); | ||
$this->selectMock->expects($this->once())->method('joinLeft')->willReturnSelf(); | ||
$this->connectionMock = $this->getMockBuilder(Adapter::class)->getMockForAbstractClass(); | ||
$this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock); | ||
$this->resourceMock = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock(); | ||
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); | ||
$this->connectionMock->expects($this->any())->method('getTableName')->willReturn('TableName'); | ||
$this->resourceMock->expects($this->any())->method('getTableName')->willReturn('TableName'); | ||
$this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); | ||
$this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); | ||
$this->entityType = $this->getMockBuilder(Type::class)->disableOriginalConstructor()->getMock(); | ||
$this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityType); | ||
$this->contextMock->expects($this->any())->method('getEavConfig')->willReturn($this->eavConfigMock); | ||
$this->contextMock->expects($this->any())->method('getResource')->willReturn($this->resourceMock); | ||
$this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMock(); | ||
$this->factoryMock = $this->getMockBuilder(Factory::class)->disableOriginalConstructor()->getMock(); | ||
$this->managerMock = $this->getMockBuilder(ManagerInterface::class)->getMock(); | ||
$this->treeFactoryMock = $this->getMockBuilder(Category\TreeFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
$this->category = new Category( | ||
$this->contextMock, | ||
$this->storeManagerMock, | ||
$this->factoryMock, | ||
$this->managerMock, | ||
$this->treeFactoryMock, | ||
$this->collectionFactoryMock, | ||
[] | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testFindWhereAttributeIs() | ||
{ | ||
$entityIdsFilter = [1, 2]; | ||
$expectedValue = 123; | ||
$attribute = $this->getMockBuilder(Attribute::class)->disableOriginalConstructor()->getMock(); | ||
$backendModel = $this->getMockBuilder(AbstractBackend::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$attribute->expects($this->any())->method('getBackend')->willReturn($backendModel); | ||
$this->connectionMock->expects($this->once())->method('fetchCol')->willReturn(['result']); | ||
|
||
$result = $this->category->findWhereAttributeIs($entityIdsFilter, $attribute, $expectedValue); | ||
$this->assertEquals(['result'], $result); | ||
} | ||
} |
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.