Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
KeywordTypeTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
8 namespace
10 
13  as FieldTypeConverterInterface;
16 
20 class KeywordTypeTest extends \PHPUnit\Framework\TestCase
21 {
25  private $resolver;
26 
30  private $fieldTypeConverter;
31 
37  protected function setUp()
38  {
39  $this->fieldTypeConverter = $this->getMockBuilder(FieldTypeConverterInterface::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['convert'])
42  ->getMockForAbstractClass();
43 
44  $objectManager = new ObjectManagerHelper($this);
45 
46  $this->resolver = $objectManager->getObject(
47  KeywordType::class,
48  [
49  'fieldTypeConverter' => $this->fieldTypeConverter,
50  ]
51  );
52  }
53 
63  public function testGetFieldType($isComplexType, $isSearchable, $isAlwaysIndexable, $isFilterable, $expected)
64  {
65  $attributeMock = $this->getMockBuilder(AttributeAdapter::class)
66  ->disableOriginalConstructor()
67  ->setMethods(['isComplexType', 'isSearchable', 'isAlwaysIndexable', 'isFilterable'])
68  ->getMock();
69  $attributeMock->expects($this->any())
70  ->method('isComplexType')
71  ->willReturn($isComplexType);
72  $attributeMock->expects($this->any())
73  ->method('isSearchable')
74  ->willReturn($isSearchable);
75  $attributeMock->expects($this->any())
76  ->method('isAlwaysIndexable')
77  ->willReturn($isAlwaysIndexable);
78  $attributeMock->expects($this->any())
79  ->method('isFilterable')
80  ->willReturn($isFilterable);
81  $this->fieldTypeConverter->expects($this->any())
82  ->method('convert')
83  ->willReturn('something');
84 
85  $this->assertEquals(
86  $expected,
87  $this->resolver->getFieldType($attributeMock)
88  );
89  }
90 
94  public function getFieldTypeProvider()
95  {
96  return [
97  [true, true, true, true, 'something'],
98  [true, false, false, false, 'something'],
99  [true, false, false, true, 'something'],
100  [false, false, false, true, 'something'],
101  [false, false, false, false, ''],
102  [false, false, true, false, ''],
103  [false, true, false, false, ''],
104  ];
105  }
106 }
$objectManager
Definition: bootstrap.php:17