![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/dev/tests/integration/testsuite/Magento/Rule/Model/Condition/Sql/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Rule\Model\Condition\Sql; use Magento\TestFramework\Helper\Bootstrap; use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory; use Magento\CatalogWidget\Model\RuleFactory; use Magento\CatalogWidget\Model\Rule\Condition\Combine as CombineCondition; use Magento\CatalogWidget\Model\Rule\Condition\Product as ProductCondition; /** * Test for Magento\Rule\Model\Condition\Sql\Builder */ class BuilderTest extends \PHPUnit\Framework\TestCase { /** * @var Builder */ private $model; protected function setUp(): void { $this->model = Bootstrap::getObjectManager()->create(Builder::class); } /** * @return void */ public function testAttachConditionToCollection(): void { /** @var ProductCollectionFactory $collectionFactory */ $collectionFactory = Bootstrap::getObjectManager()->create(ProductCollectionFactory::class); $collection = $collectionFactory->create(); /** @var RuleFactory $ruleFactory */ $ruleFactory = Bootstrap::getObjectManager()->create(RuleFactory::class); $rule = $ruleFactory->create(); $ruleConditionArray = [ 'conditions' => [ '1' => [ 'type' => CombineCondition::class, 'aggregator' => 'all', 'value' => '1', 'new_child' => '', ], '1--1' => [ 'type' => ProductCondition::class, 'attribute' => 'category_ids', 'operator' => '==', 'value' => '3', ], '1--2' => [ 'type' => ProductCondition::class, 'attribute' => 'special_to_date', 'operator' => '==', 'value' => '2017-09-15', ], '1--3' => [ 'type' => ProductCondition::class, 'attribute' => 'sku', 'operator' => '()', 'value' => ' :( , :) ', ] ], ]; $rule->loadPost($ruleConditionArray); $this->model->attachConditionToCollection($collection, $rule->getConditions()); $whereString = "/\(category_id IN \('3'\).+\(IFNULL\(`e`\.`entity_id`,.+\) = '2017-09-15 00:00:00'\)" . ".+ORDER BY \(FIELD\(`e`.`sku`, ':\(', ':\)'\)\)/"; $this->assertEquals(1, preg_match($whereString, $collection->getSelectSql(true))); } }