|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Rule\Model\Condition\Sql; |
| 8 | + |
| 9 | +use Magento\TestFramework\Helper\Bootstrap; |
| 10 | + |
| 11 | +class BuilderTest extends \PHPUnit\Framework\TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @var \Magento\Rule\Model\Condition\Sql\Builder |
| 15 | + */ |
| 16 | + private $model; |
| 17 | + |
| 18 | + protected function setUp() |
| 19 | + { |
| 20 | + $this->model = Bootstrap::getObjectManager()->create(\Magento\Rule\Model\Condition\Sql\Builder::class); |
| 21 | + } |
| 22 | + |
| 23 | + public function testAttachConditionToCollection() |
| 24 | + { |
| 25 | + /** @var \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $collectionFactory */ |
| 26 | + $collectionFactory = Bootstrap::getObjectManager()->create( |
| 27 | + \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory::class |
| 28 | + ); |
| 29 | + /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */ |
| 30 | + $collection = $collectionFactory->create(); |
| 31 | + |
| 32 | + /** @var \Magento\CatalogWidget\Model\RuleFactory $ruleFactory */ |
| 33 | + $ruleFactory = Bootstrap::getObjectManager()->create(\Magento\CatalogWidget\Model\RuleFactory::class); |
| 34 | + /** @var \Magento\CatalogWidget\Model\Rule $rule */ |
| 35 | + $rule = $ruleFactory->create(); |
| 36 | + |
| 37 | + $ruleConditionArray = [ |
| 38 | + 'conditions' => [ |
| 39 | + '1' => [ |
| 40 | + 'type' => \Magento\CatalogWidget\Model\Rule\Condition\Combine::class, |
| 41 | + 'aggregator' => 'all', |
| 42 | + 'value' => '1', |
| 43 | + 'new_child' => '' |
| 44 | + ], |
| 45 | + '1--1' => [ |
| 46 | + 'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class, |
| 47 | + 'attribute' => 'category_ids', |
| 48 | + 'operator' => '==', |
| 49 | + 'value' => '3' |
| 50 | + ], |
| 51 | + '1--2' => [ |
| 52 | + 'type' => \Magento\CatalogWidget\Model\Rule\Condition\Product::class, |
| 53 | + 'attribute' => 'special_to_date', |
| 54 | + 'operator' => '==', |
| 55 | + 'value' => '2017-09-15' |
| 56 | + ], |
| 57 | + ] |
| 58 | + ]; |
| 59 | + |
| 60 | + |
| 61 | + $rule->loadPost($ruleConditionArray); |
| 62 | + $this->model->attachConditionToCollection($collection, $rule->getConditions()); |
| 63 | + |
| 64 | + $whereString = 'WHERE (category_id IN (\'3\')))) AND(IFNULL(`e`.`entity_id`, 0) = \'2017-09-15\') ))'; |
| 65 | + $this->assertNotFalse(strpos($collection->getSelectSql(true), $whereString)); |
| 66 | + } |
| 67 | +} |
0 commit comments