Skip to content

Commit

Permalink
Merge pull request #526 from magento-tango/MAGETWO-51659
Browse files Browse the repository at this point in the history
[Tango] Bugfixes
  • Loading branch information
Momotenko,Natalia(nmomotenko) committed Apr 8, 2016
2 parents ec436ce + 67d1d1d commit 9bf93a3
Show file tree
Hide file tree
Showing 23 changed files with 575 additions and 190 deletions.
76 changes: 76 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Ui/AllowedProductTypesTest.php
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],
];
}
}
51 changes: 51 additions & 0 deletions app/code/Magento/Catalog/Ui/AllowedProductTypes.php
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
);
}
}
Loading

0 comments on commit 9bf93a3

Please sign in to comment.