|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection\Collection; |
| 9 | + |
| 10 | +use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier; |
| 11 | +use Magento\Framework\DB\Select; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Test selection collection filter applier |
| 16 | + */ |
| 17 | +class FilterApplierTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var FilterApplier |
| 21 | + */ |
| 22 | + private $model; |
| 23 | + |
| 24 | + /** |
| 25 | + * @inheritdoc |
| 26 | + */ |
| 27 | + protected function setUp(): void |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + $this->model = new FilterApplier(); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @param $field |
| 35 | + * @param $value |
| 36 | + * @param $conditionType |
| 37 | + * @param $expectedCondition |
| 38 | + * @param $expectedValue |
| 39 | + * @dataProvider applyDataProvider |
| 40 | + */ |
| 41 | + public function testApply($field, $value, $conditionType, $expectedCondition, $expectedValue): void |
| 42 | + { |
| 43 | + $tableName = 'catalog_product_bundle_selection'; |
| 44 | + $select = $this->createMock(Select::class); |
| 45 | + $collection = $this->createMock(\Magento\Bundle\Model\ResourceModel\Selection\Collection::class); |
| 46 | + $collection->method('getSelect') |
| 47 | + ->willReturn($select); |
| 48 | + $collection->method('getTable') |
| 49 | + ->willReturnArgument(0); |
| 50 | + $select->method('getPart') |
| 51 | + ->willReturnMap( |
| 52 | + [ |
| 53 | + [ |
| 54 | + 'from', |
| 55 | + [ |
| 56 | + 'selection' => [ |
| 57 | + 'tableName' => $tableName |
| 58 | + ] |
| 59 | + ] |
| 60 | + ] |
| 61 | + ] |
| 62 | + ); |
| 63 | + $select->expects($this->once()) |
| 64 | + ->method('where') |
| 65 | + ->with($expectedCondition, $expectedValue); |
| 66 | + $this->model->apply($collection, $field, $value, $conditionType); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return array |
| 71 | + */ |
| 72 | + public function applyDataProvider(): array |
| 73 | + { |
| 74 | + return [ |
| 75 | + [ |
| 76 | + 'id', |
| 77 | + 1, |
| 78 | + 'eq', |
| 79 | + 'selection.id = ?', |
| 80 | + 1 |
| 81 | + ], |
| 82 | + [ |
| 83 | + 'id', |
| 84 | + [1, 3], |
| 85 | + 'in', |
| 86 | + 'selection.id IN (?)', |
| 87 | + [1, 3] |
| 88 | + ] |
| 89 | + ]; |
| 90 | + } |
| 91 | +} |
0 commit comments