Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeAdapterTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14  as FieldTypeConverterInterface;
15 
19 class AttributeAdapterTest extends \PHPUnit\Framework\TestCase
20 {
24  private $adapter;
25 
29  private $attribute;
30 
36  protected function setUp()
37  {
38  $this->attribute = $this->getMockBuilder(CustomAttributesDataInterface::class)
39  ->disableOriginalConstructor()
40  ->setMethods([
41  'getIsFilterable',
42  'getIsFilterableInSearch',
43  'getIsSearchable',
44  'getIsVisibleInAdvancedSearch',
45  'getBackendType',
46  'getFrontendInput',
47  'usesSource',
48  ])
49  ->getMockForAbstractClass();
50 
51  $objectManager = new ObjectManagerHelper($this);
52 
53  $this->adapter = $objectManager->getObject(
54  \Magento\Elasticsearch\Model\Adapter\FieldMapper\Product\AttributeAdapter::class,
55  [
56  'attribute' => $this->attribute,
57  'attributeCode' => 'code',
58  ]
59  );
60  }
61 
69  public function testIsFilterable($isFilterable, $isFilterableInSearch, $expected)
70  {
71  $this->attribute
72  ->method('getIsFilterable')
73  ->willReturn($isFilterable);
74  $this->attribute
75  ->method('getIsFilterableInSearch')
76  ->willReturn($isFilterableInSearch);
77  $this->assertEquals(
78  $expected,
79  $this->adapter->isFilterable()
80  );
81  }
82 
92  public function testIsSearchable(
93  $isSearchable,
94  $isVisibleInAdvancedSearch,
95  $isFilterable,
96  $isFilterableInSearch,
97  $expected
98  ) {
99  $this->attribute
100  ->method('getIsSearchable')
101  ->willReturn($isSearchable);
102  $this->attribute
103  ->method('getIsVisibleInAdvancedSearch')
104  ->willReturn($isVisibleInAdvancedSearch);
105  $this->attribute
106  ->method('getIsFilterable')
107  ->willReturn($isFilterable);
108  $this->attribute
109  ->method('getIsFilterableInSearch')
110  ->willReturn($isFilterableInSearch);
111  $this->assertEquals(
112  $expected,
113  $this->adapter->isSearchable()
114  );
115  }
116 
122  public function testIsAlwaysIndexable($expected)
123  {
124  $this->assertEquals(
125  $expected,
126  $this->adapter->isAlwaysIndexable()
127  );
128  }
129 
136  public function testIsDateTimeType($backendType, $expected)
137  {
138  $this->attribute
139  ->method('getBackendType')
140  ->willReturn($backendType);
141  $this->assertEquals(
142  $expected,
143  $this->adapter->isDateTimeType()
144  );
145  }
146 
153  public function testIsFloatType($backendType, $expected)
154  {
155  $this->attribute
156  ->method('getBackendType')
157  ->willReturn($backendType);
158  $this->assertEquals(
159  $expected,
160  $this->adapter->isFloatType()
161  );
162  }
163 
170  public function testIsIntegerType($backendType, $expected)
171  {
172  $this->attribute
173  ->method('getBackendType')
174  ->willReturn($backendType);
175  $this->assertEquals(
176  $expected,
177  $this->adapter->isIntegerType()
178  );
179  }
180 
188  public function testIsBooleanType($frontendInput, $backendType, $expected)
189  {
190  $this->attribute
191  ->method('getBackendType')
192  ->willReturn($backendType);
193  $this->attribute
194  ->method('getFrontendInput')
195  ->willReturn($frontendInput);
196  $this->assertEquals(
197  $expected,
198  $this->adapter->isBooleanType()
199  );
200  }
201 
209  public function testIsComplexType($frontendInput, $usesSource, $expected)
210  {
211  $this->attribute
212  ->method('usesSource')
213  ->willReturn($usesSource);
214  $this->attribute
215  ->method('getFrontendInput')
216  ->willReturn($frontendInput);
217  $this->assertEquals(
218  $expected,
219  $this->adapter->isComplexType()
220  );
221  }
222 
228  public function testIsEavAttribute($expected)
229  {
230  $this->assertEquals(
231  $expected,
232  $this->adapter->isEavAttribute()
233  );
234  }
235 
239  public function isEavAttributeProvider()
240  {
241  return [
242  [false],
243  ];
244  }
245 
249  public function isComplexTypeProvider()
250  {
251  return [
252  ['select', true, true],
253  ['multiselect', true, true],
254  ['multiselect', false, true],
255  ['int', false, false],
256  ['int', true, true],
257  ];
258  }
259 
263  public function isBooleanTypeProvider()
264  {
265  return [
266  ['select', 'int', true],
267  ['boolean', 'int', true],
268  ['boolean', 'varchar', false],
269  ['select', 'varchar', false],
270  ['int', 'varchar', false],
271  ['int', 'int', false],
272  ];
273  }
274 
278  public function isIntegerTypeProvider()
279  {
280  return [
281  ['smallint', true],
282  ['int', true],
283  ['string', false],
284  ];
285  }
286 
290  public function isFloatTypeProvider()
291  {
292  return [
293  ['decimal', true],
294  ['int', false],
295  ];
296  }
297 
301  public function isDateTimeTypeProvider()
302  {
303  return [
304  ['timestamp', true],
305  ['datetime', true],
306  ['int', false],
307  ];
308  }
309 
313  public function isAlwaysIndexableProvider()
314  {
315  return [
316  [false]
317  ];
318  }
319 
323  public function isSearchableProvider()
324  {
325  return [
326  [true, false, false, false, true],
327  [false, false, false, false, false],
328  [false, true, false, false, true],
329  [false, false, true, false, true],
330  [true, true, true, false, true],
331  [true, true, false, false, true],
332  ];
333  }
334 
338  public function isFilterableProvider()
339  {
340  return [
341  [true, false, true,],
342  [true, false, true,],
343  [false, false, false,]
344  ];
345  }
346 
351  {
352  return [
353  ['string', 'text', false,],
354  ['text', 'text', true,]
355  ];
356  }
357 
361  public function getFieldNameProvider()
362  {
363  return [
364  ['name', [], 'name']
365  ];
366  }
367 
371  public function getFieldTypeProvider()
372  {
373  return [
374  ['type', 'type']
375  ];
376  }
377 
381  public function getFieldIndexProvider()
382  {
383  return [
384  ['type', 'no', 'no']
385  ];
386  }
387 }
$objectManager
Definition: bootstrap.php:17
testIsSearchable( $isSearchable, $isVisibleInAdvancedSearch, $isFilterable, $isFilterableInSearch, $expected)