-
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.
MAGETWO-52717: [GitHub] Configurable product disabling lowest price a…
…ssociated product still shows its price #4419 -- refactoring -- test coverage
- Loading branch information
vnayda
committed
Oct 5, 2016
1 parent
7c9547e
commit eacec0e
Showing
13 changed files
with
494 additions
and
85 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...agento/Catalog/Test/Unit/Model/ResourceModel/Product/CompositeBaseSelectProcessorTest.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,54 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; | ||
use Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
|
||
class CompositeBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ObjectManager | ||
*/ | ||
private $objectManager; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = new ObjectManager($this); | ||
} | ||
|
||
/** | ||
* @expectedException \Magento\Framework\Exception\InputException | ||
*/ | ||
public function testInitializeWithWrongProcessorInstance() | ||
{ | ||
$processorValid = $this->getMock(BaseSelectProcessorInterface::class); | ||
$processorInvalid = $this->getMock(\stdClass::class); | ||
|
||
$this->objectManager->getObject(CompositeBaseSelectProcessor::class, [ | ||
'baseSelectProcessors' => [$processorValid, $processorInvalid], | ||
]); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$processorFirst = $this->getMock(BaseSelectProcessorInterface::class); | ||
$processorFirst->expects($this->once())->method('process')->with($select)->willReturn($select); | ||
|
||
$processorSecond = $this->getMock(BaseSelectProcessorInterface::class); | ||
$processorSecond->expects($this->once())->method('process')->with($select)->willReturn($select); | ||
|
||
/** @var CompositeBaseSelectProcessor $baseSelectProcessors */ | ||
$baseSelectProcessors = $this->objectManager->getObject(CompositeBaseSelectProcessor::class, [ | ||
'baseSelectProcessors' => [$processorFirst, $processorSecond], | ||
]); | ||
$this->assertEquals($select, $baseSelectProcessors->process($select)); | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...e/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/StatusBaseSelectProcessorTest.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,102 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Test\Unit\Model\ResourceModel\Product; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Catalog\Model\Product\Attribute\Source\Status; | ||
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; | ||
use Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor; | ||
use Magento\Eav\Model\Config; | ||
use Magento\Eav\Model\Entity\Attribute\AttributeInterface; | ||
use Magento\Framework\DB\Select; | ||
use Magento\Framework\EntityManager\EntityMetadataInterface; | ||
use Magento\Framework\EntityManager\MetadataPool; | ||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; | ||
|
||
class StatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Config|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $eavConfig; | ||
|
||
/** | ||
* @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $metadataPool; | ||
|
||
/** | ||
* @var Select|\PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $select; | ||
|
||
/** | ||
* @var StatusBaseSelectProcessor | ||
*/ | ||
private $statusBaseSelectProcessor; | ||
|
||
protected function setUp() | ||
{ | ||
$this->eavConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock(); | ||
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock(); | ||
$this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); | ||
|
||
$this->statusBaseSelectProcessor = (new ObjectManager($this))->getObject(StatusBaseSelectProcessor::class, [ | ||
'eavConfig' => $this->eavConfig, | ||
'metadataPool' => $this->metadataPool, | ||
]); | ||
} | ||
|
||
public function testProcess() | ||
{ | ||
$linkField = 'link_field'; | ||
$backendTable = 'backend_table'; | ||
$attributeId = 'attribute_id'; | ||
|
||
$metadata = $this->getMock(EntityMetadataInterface::class); | ||
$metadata->expects($this->once()) | ||
->method('getLinkField') | ||
->willReturn($linkField); | ||
$this->metadataPool->expects($this->once()) | ||
->method('getMetadata') | ||
->with(ProductInterface::class) | ||
->willReturn($metadata); | ||
|
||
$statusAttribute = $this->getMockBuilder(AttributeInterface::class) | ||
->setMethods(['getBackendTable', 'getAttributeId']) | ||
->getMock(); | ||
$statusAttribute->expects($this->once()) | ||
->method('getBackendTable') | ||
->willReturn($backendTable); | ||
$statusAttribute->expects($this->once()) | ||
->method('getAttributeId') | ||
->willReturn($attributeId); | ||
$this->eavConfig->expects($this->once()) | ||
->method('getAttribute') | ||
->with(Product::ENTITY, ProductInterface::STATUS) | ||
->willReturn($statusAttribute); | ||
|
||
$this->select->expects($this->once()) | ||
->method('join') | ||
->with( | ||
['status_attr' => $backendTable], | ||
sprintf('status_attr.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS), | ||
[] | ||
) | ||
->willReturnSelf(); | ||
$this->select->expects($this->at(1)) | ||
->method('where') | ||
->with('status_attr.attribute_id = ?', $attributeId) | ||
->willReturnSelf(); | ||
$this->select->expects($this->at(2)) | ||
->method('where') | ||
->with('status_attr.value = ?', Status::STATUS_ENABLED) | ||
->willReturnSelf(); | ||
|
||
$this->assertEquals($this->select, $this->statusBaseSelectProcessor->process($this->select)); | ||
} | ||
} |
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
Oops, something went wrong.