Skip to content

Commit d421566

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into JS-472
2 parents b10bdc1 + 9bf93a3 commit d421566

File tree

23 files changed

+575
-190
lines changed

23 files changed

+575
-190
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Ui;
7+
8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
9+
use Magento\Catalog\Ui\AllowedProductTypes;
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
12+
class AllowedProductTypesTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var ObjectManagerHelper
16+
*/
17+
protected $objectManagerHelper;
18+
19+
/**
20+
* @return void
21+
*/
22+
public function testGetAllowedProductTypesWithoutConstructorArguments()
23+
{
24+
/** @var AllowedProductTypes $testedClass */
25+
$testedClass = (new ObjectManagerHelper($this))->getObject(AllowedProductTypes::class);
26+
$this->assertSame([], $testedClass->getAllowedProductTypes());
27+
}
28+
29+
/**
30+
* @return void
31+
*/
32+
public function testGetAllowedProductTypes()
33+
{
34+
$productTypes = ['simple', 'virtual'];
35+
/** @var AllowedProductTypes $testedClass */
36+
$testedClass = (new ObjectManagerHelper($this))->getObject(
37+
AllowedProductTypes::class,
38+
['productTypes' => $productTypes]
39+
);
40+
41+
$this->assertSame($productTypes, $testedClass->getAllowedProductTypes());
42+
}
43+
44+
/**
45+
* @param string $typeId
46+
* @param bool $expectedResult
47+
* @dataProvider isAllowedProductTypeDataProvider
48+
*/
49+
public function testIsAllowedProductType($typeId, $expectedResult)
50+
{
51+
$productTypes = ['simple', 'virtual'];
52+
$productMock = $this->getMock(ProductInterface::class);
53+
$productMock->expects($this->once())
54+
->method('getTypeId')
55+
->willReturn($typeId);
56+
57+
/** @var AllowedProductTypes $testedClass */
58+
$testedClass = (new ObjectManagerHelper($this))->getObject(
59+
AllowedProductTypes::class,
60+
['productTypes' => $productTypes]
61+
);
62+
63+
$this->assertSame($expectedResult, $testedClass->isAllowedProductType($productMock));
64+
}
65+
66+
/**
67+
* @return array
68+
*/
69+
public function isAllowedProductTypeDataProvider()
70+
{
71+
return [
72+
['typeId' => 'simple', 'expectedResult' => true],
73+
['typeId' => 'downloadable', 'expectedResult' => false],
74+
];
75+
}
76+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Ui;
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
10+
/**
11+
* Class AllowedProductTypes contains product types on which some product type can be displayed
12+
*/
13+
class AllowedProductTypes
14+
{
15+
/**
16+
* @var array
17+
*/
18+
protected $allowedProductTypes = [];
19+
20+
/**
21+
* @param array $productTypes
22+
*/
23+
public function __construct(array $productTypes = [])
24+
{
25+
$this->allowedProductTypes = $productTypes;
26+
}
27+
28+
/**
29+
* Get allowed product types
30+
*
31+
* @return array
32+
*/
33+
public function getAllowedProductTypes()
34+
{
35+
return $this->allowedProductTypes;
36+
}
37+
38+
/**
39+
* Check that product type is allowed
40+
*
41+
* @param ProductInterface $product
42+
* @return bool
43+
*/
44+
public function isAllowedProductType(ProductInterface $product)
45+
{
46+
return in_array(
47+
$product->getTypeId(),
48+
$this->allowedProductTypes
49+
);
50+
}
51+
}

0 commit comments

Comments
 (0)