|
15 | 15 | use Magento\CatalogWidget\Model\Rule\Condition\Product as ProductWidget;
|
16 | 16 | use Magento\Eav\Model\Config;
|
17 | 17 | use Magento\Eav\Model\Entity\AbstractEntity;
|
18 |
| -use Magento\Framework\DB\Adapter\AdapterInterface; |
| 18 | +use Magento\Framework\DB\Adapter\Pdo\Mysql; |
19 | 19 | use Magento\Framework\DB\Select;
|
20 | 20 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
|
21 | 21 | use Magento\SalesRule\Model\Rule;
|
@@ -63,7 +63,10 @@ protected function setUp(): void
|
63 | 63 | $this->productResource = $this->createMock(Product::class);
|
64 | 64 | $this->productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf();
|
65 | 65 | $this->productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]);
|
66 |
| - $connection = $this->getMockForAbstractClass(AdapterInterface::class); |
| 66 | + $connection = $this->getMockBuilder(Mysql::class) |
| 67 | + ->onlyMethods(['_connect']) |
| 68 | + ->disableOriginalConstructor() |
| 69 | + ->getMockForAbstractClass(); |
67 | 70 | $this->productResource->method('getConnection')->willReturn($connection);
|
68 | 71 | $productCategoryList = $this->getMockBuilder(ProductCategoryList::class)
|
69 | 72 | ->disableOriginalConstructor()
|
@@ -191,6 +194,89 @@ public function getMappedSqlFieldPriceDataProvider(): array
|
191 | 194 | ];
|
192 | 195 | }
|
193 | 196 |
|
| 197 | + /** |
| 198 | + * @param array $conditionArray |
| 199 | + * @param array $attributeConfig |
| 200 | + * @param array $attributeValues |
| 201 | + * @param mixed $expected |
| 202 | + * @dataProvider getBindArgumentValueDataProvider |
| 203 | + */ |
| 204 | + public function testGetBindArgumentValue( |
| 205 | + array $conditionArray, |
| 206 | + array $attributeConfig, |
| 207 | + array $attributeValues, |
| 208 | + $expected |
| 209 | + ): void { |
| 210 | + $conditionArray['type'] = ProductWidget::class; |
| 211 | + $attributeConfig['getAttributeCode'] = $conditionArray['attribute']; |
| 212 | + $collectionMock = $this->mockCollection( |
| 213 | + [ |
| 214 | + 'getAllAttributeValues' => $attributeValues, |
| 215 | + ] |
| 216 | + ); |
| 217 | + $this->mockAttribute($attributeConfig); |
| 218 | + $this->model->loadArray($conditionArray); |
| 219 | + $this->model->collectValidatedAttributes($collectionMock); |
| 220 | + $this->assertEquals($expected, $this->model->getBindArgumentValue()); |
| 221 | + } |
| 222 | + |
| 223 | + /** |
| 224 | + * @return array |
| 225 | + */ |
| 226 | + public function getBindArgumentValueDataProvider(): array |
| 227 | + { |
| 228 | + return [ |
| 229 | + [ |
| 230 | + [ |
| 231 | + 'attribute' => 'attr_1', |
| 232 | + 'value' => '2', |
| 233 | + 'operator' => '==', |
| 234 | + ], |
| 235 | + [ |
| 236 | + 'isScopeGlobal' => false, |
| 237 | + 'getBackendType' => 'int' |
| 238 | + ], |
| 239 | + [ |
| 240 | + 1 => [ |
| 241 | + 0 => 1, |
| 242 | + 1 => 2 |
| 243 | + ], |
| 244 | + 2 => [ |
| 245 | + 0 => 1 |
| 246 | + ], |
| 247 | + 3 => [ |
| 248 | + 1 => 2 |
| 249 | + ] |
| 250 | + ], |
| 251 | + new \Zend_Db_Expr('1, 3') |
| 252 | + ], |
| 253 | + [ |
| 254 | + [ |
| 255 | + 'attribute' => 'attr_1', |
| 256 | + 'value' => '2', |
| 257 | + 'operator' => '==', |
| 258 | + ], |
| 259 | + [ |
| 260 | + 'isScopeGlobal' => true, |
| 261 | + 'getBackendType' => 'int' |
| 262 | + ], |
| 263 | + [ |
| 264 | + 1 => [ |
| 265 | + 0 => 1, |
| 266 | + 1 => 2 |
| 267 | + ], |
| 268 | + 2 => [ |
| 269 | + 0 => 1 |
| 270 | + ], |
| 271 | + 3 => [ |
| 272 | + 1 => 2 |
| 273 | + ] |
| 274 | + ], |
| 275 | + '2' |
| 276 | + ], |
| 277 | + ]; |
| 278 | + } |
| 279 | + |
194 | 280 | /**
|
195 | 281 | * @param array $configuration
|
196 | 282 | */
|
|
0 commit comments