init
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\Rule\Model\Condition\AbstractCondition
|
||||
*/
|
||||
namespace Magento\Rule\Model\Condition;
|
||||
|
||||
class AbstractTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testGetValueElement()
|
||||
{
|
||||
$layoutMock = $this->createMock(\Magento\Framework\View\Layout::class);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$context = $objectManager->create(\Magento\Rule\Model\Condition\Context::class, ['layout' => $layoutMock]);
|
||||
|
||||
/** @var \Magento\Rule\Model\Condition\AbstractCondition $model */
|
||||
$model = $this->getMockForAbstractClass(
|
||||
\Magento\Rule\Model\Condition\AbstractCondition::class,
|
||||
[$context],
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
['getValueElementRenderer']
|
||||
);
|
||||
$editableBlock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Rule\Block\Editable::class
|
||||
);
|
||||
$model->expects($this->any())->method('getValueElementRenderer')->willReturn($editableBlock);
|
||||
|
||||
$rule = $this->getMockBuilder(\Magento\Rule\Model\AbstractModel::class)
|
||||
->setMethods(['getForm'])
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
$rule->expects($this->any())
|
||||
->method('getForm')
|
||||
->willReturn(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Framework\Data\Form::class)
|
||||
);
|
||||
$model->setRule($rule);
|
||||
|
||||
$property = new \ReflectionProperty(\Magento\Rule\Model\Condition\AbstractCondition::class, '_inputType');
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($model, 'date');
|
||||
|
||||
$element = $model->getValueElement();
|
||||
$this->assertNotNull($element);
|
||||
$this->assertNotEmpty($element->getDateFormat());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?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)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user