-
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 #526 from magento-tango/MAGETWO-51659
[Tango] Bugfixes
- Loading branch information
Showing
23 changed files
with
575 additions
and
190 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
app/code/Magento/Catalog/Test/Unit/Ui/AllowedProductTypesTest.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,76 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Test\Unit\Ui; | ||
|
||
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; | ||
use Magento\Catalog\Ui\AllowedProductTypes; | ||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
class AllowedProductTypesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerHelper | ||
*/ | ||
protected $objectManagerHelper; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetAllowedProductTypesWithoutConstructorArguments() | ||
{ | ||
/** @var AllowedProductTypes $testedClass */ | ||
$testedClass = (new ObjectManagerHelper($this))->getObject(AllowedProductTypes::class); | ||
$this->assertSame([], $testedClass->getAllowedProductTypes()); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetAllowedProductTypes() | ||
{ | ||
$productTypes = ['simple', 'virtual']; | ||
/** @var AllowedProductTypes $testedClass */ | ||
$testedClass = (new ObjectManagerHelper($this))->getObject( | ||
AllowedProductTypes::class, | ||
['productTypes' => $productTypes] | ||
); | ||
|
||
$this->assertSame($productTypes, $testedClass->getAllowedProductTypes()); | ||
} | ||
|
||
/** | ||
* @param string $typeId | ||
* @param bool $expectedResult | ||
* @dataProvider isAllowedProductTypeDataProvider | ||
*/ | ||
public function testIsAllowedProductType($typeId, $expectedResult) | ||
{ | ||
$productTypes = ['simple', 'virtual']; | ||
$productMock = $this->getMock(ProductInterface::class); | ||
$productMock->expects($this->once()) | ||
->method('getTypeId') | ||
->willReturn($typeId); | ||
|
||
/** @var AllowedProductTypes $testedClass */ | ||
$testedClass = (new ObjectManagerHelper($this))->getObject( | ||
AllowedProductTypes::class, | ||
['productTypes' => $productTypes] | ||
); | ||
|
||
$this->assertSame($expectedResult, $testedClass->isAllowedProductType($productMock)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function isAllowedProductTypeDataProvider() | ||
{ | ||
return [ | ||
['typeId' => 'simple', 'expectedResult' => true], | ||
['typeId' => 'downloadable', 'expectedResult' => false], | ||
]; | ||
} | ||
} |
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,51 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Catalog\Ui; | ||
|
||
use Magento\Catalog\Api\Data\ProductInterface; | ||
|
||
/** | ||
* Class AllowedProductTypes contains product types on which some product type can be displayed | ||
*/ | ||
class AllowedProductTypes | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $allowedProductTypes = []; | ||
|
||
/** | ||
* @param array $productTypes | ||
*/ | ||
public function __construct(array $productTypes = []) | ||
{ | ||
$this->allowedProductTypes = $productTypes; | ||
} | ||
|
||
/** | ||
* Get allowed product types | ||
* | ||
* @return array | ||
*/ | ||
public function getAllowedProductTypes() | ||
{ | ||
return $this->allowedProductTypes; | ||
} | ||
|
||
/** | ||
* Check that product type is allowed | ||
* | ||
* @param ProductInterface $product | ||
* @return bool | ||
*/ | ||
public function isAllowedProductType(ProductInterface $product) | ||
{ | ||
return in_array( | ||
$product->getTypeId(), | ||
$this->allowedProductTypes | ||
); | ||
} | ||
} |
Oops, something went wrong.