/**
  * Render WHERE section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::FROM) && $select->getPart(Select::WHERE)) {
         $sql .= ' ' . Select::SQL_WHERE . ' ' . implode(' ', $select->getPart(Select::WHERE));
     }
     return $sql;
 }
Пример #2
0
 /**
  * Render FROM & JOIN's section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  * @throws \Zend_Db_Select_Exception
  */
 public function render(Select $select, $sql = '')
 {
     /*
      * If no table specified, use RDBMS-dependent solution
      * for table-less query.  e.g. DUAL in Oracle.
      */
     $source = $select->getPart(Select::FROM);
     if (empty($source)) {
         $source = [];
     }
     $from = [];
     foreach ($source as $correlationName => $table) {
         $tmp = '';
         $joinType = $table['joinType'] == Select::FROM ? Select::INNER_JOIN : $table['joinType'];
         // Add join clause (if applicable)
         if (!empty($from)) {
             $tmp .= ' ' . strtoupper($joinType) . ' ';
         }
         $tmp .= $this->getQuotedSchema($table['schema']);
         $tmp .= $this->getQuotedTable($table['tableName'], $correlationName);
         // Add join conditions (if applicable)
         if (!empty($from) && !empty($table['joinCondition'])) {
             $tmp .= ' ' . Select::SQL_ON . ' ' . $table['joinCondition'];
         }
         // Add the table name and condition add to the list
         $from[] = $tmp;
     }
     // Add the list of all joins
     if (!empty($from)) {
         $sql .= ' ' . Select::SQL_FROM . ' ' . implode("\n", $from);
     }
     return $sql;
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function build(ScoreBuilder $scoreBuilder, Select $select, RequestQueryInterface $query, $conditionType)
 {
     /** @var $query \Magento\Framework\Search\Request\Query\Match */
     $queryValue = $this->prepareQuery($query->getValue(), $conditionType);
     $fieldList = [];
     foreach ($query->getMatches() as $match) {
         $fieldList[] = $match['field'];
     }
     $resolvedFieldList = $this->resolver->resolve($fieldList);
     $fieldIds = [];
     $columns = [];
     foreach ($resolvedFieldList as $field) {
         if ($field->getType() === FieldInterface::TYPE_FULLTEXT && $field->getAttributeId()) {
             $fieldIds[] = $field->getAttributeId();
         }
         $column = $field->getColumn();
         $columns[$column] = $column;
     }
     $matchQuery = $this->fulltextHelper->getMatchQuery($columns, $queryValue, $this->fulltextSearchMode);
     $scoreBuilder->addCondition($matchQuery, true);
     if ($fieldIds) {
         $matchQuery = sprintf('(%s AND search_index.attribute_id IN (%s))', $matchQuery, implode(',', $fieldIds));
     }
     $select->where($matchQuery);
     return $select;
 }
Пример #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
     $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
     $this->attrCollectionFactory->expects($this->any())->method('addFieldToFilter')->willReturn([]);
     $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getErrorAggregator', 'getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope'], [], '', false);
     $this->entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
     $this->params = [0 => $this->entityModel, 1 => 'grouped'];
     $this->links = $this->getMock('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped\\Links', [], [], '', false);
     $entityAttributes = [['attribute_set_name' => 'attribute_id', 'attribute_id' => 'attributeSetName']];
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock);
     $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->connection->expects($this->any())->method('fetchAll')->will($this->returnValue($entityAttributes));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->grouped = $this->objectManagerHelper->getObject('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'resource' => $this->resource, 'params' => $this->params, 'links' => $this->links]);
 }
 public function testAddUnsecureUrlsFilter()
 {
     $this->collection->expects($this->at(0))->method('_translateCondition')->with('endpoint', ['like' => 'http:%'])->will($this->returnValue('endpoint like \'http:%\''));
     $this->collection->expects($this->at(1))->method('_translateCondition')->with('identity_link_url', ['like' => 'http:%'])->will($this->returnValue('identity_link_url like \'http:%\''));
     $this->select->expects($this->once())->method('where')->with($this->equalTo('(endpoint like \'http:%\') OR (identity_link_url like \'http:%\')'), $this->equalTo(null), $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION));
     $this->collection->addUnsecureUrlsFilter();
 }
 /**
  * Render DISTINCT section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::DISTINCT)) {
         $sql .= ' ' . Select::SQL_DISTINCT . ' ';
     }
     return $sql;
 }
 public function testRender()
 {
     $sql = 'SELECT';
     $expectedResult = $sql . ' ' . Select::SQL_DISTINCT . ' ';
     $this->selectMock->expects($this->once())->method('getPart')->with(Select::DISTINCT)->willReturn(true);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Пример #8
0
 /**
  * Add JOINs to original select.
  *
  * @param \Magento\Framework\DB\Select $select
  * @return \Magento\Framework\DB\Select
  */
 public function modifySelect(\Magento\Framework\DB\Select $select)
 {
     /* aliases for tables ... */
     $tblEntity = 'e';
     // this is alias for 'catalog_product_entity' table
     $tblStockItem = $this->_resource->getTableName(self::TBL_STOCK_ITEM);
     $tblWrhsQty = $this->_resource->getTableName(self::TBL_WRHS_QTY);
     /* ... and fields */
     $fldStockItemProdId = StockItem::PRODUCT_ID;
     $fldStockItemId = StockItem::ITEM_ID;
     $fldEntityId = \Magento\Eav\Model\Entity::DEFAULT_ENTITY_ID_FIELD;
     $fldQty = self::FLD_QTY;
     $fldStockItemRef = Quantity::ATTR_STOCK_ITEM_REF;
     /* LEFT JOIN `cataloginventory_stock_item` */
     $on = "`{$tblStockItem}`.`{$fldStockItemProdId}`=`{$tblEntity}`.`{$fldEntityId}`";
     $fields = [];
     $select->joinLeft($tblStockItem, $on, $fields);
     /* LEFT JOIN `prxgt_wrhs_qty` */
     $on = "`{$tblWrhsQty}`.`{$fldStockItemRef}`=`{$tblStockItem}`.`{$fldStockItemId}`";
     $fields = [$fldQty => $this->getEquationQty()];
     $select->joinLeft($tblWrhsQty, $on, $fields);
     /* GROUP BY */
     $select->group("{$tblEntity}.{$fldEntityId}");
     return $select;
 }
Пример #9
0
 /**
  * @param array $columns
  * @param string $sql
  * @param string $expectedResult
  * @dataProvider renderDataProvider
  */
 public function testRender($columns, $sql, $expectedResult)
 {
     $mapValues = [['column', null, '`column`'], [['table', 'column'], null, '`table`.`column`'], [['table', 'column'], 'alias', '`table`.`column` AS `alias`']];
     $this->quoteMock->expects($this->any())->method('quoteColumnAs')->willReturnMap($mapValues);
     $this->selectMock->expects($this->exactly(2))->method('getPart')->with(Select::COLUMNS)->willReturn($columns);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Пример #10
0
 /**
  * Render FOR UPDATE section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  * @throws \Zend_Db_Select_Exception
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::FOR_UPDATE)) {
         $sql .= ' ' . Select::SQL_FOR_UPDATE;
     }
     return $sql;
 }
Пример #11
0
 /**
  * Apply price rule price to price index table
  *
  * @param \Magento\Framework\DB\Select $select
  * @param array|string $indexTable
  * @param string $entityId
  * @param string $customerGroupId
  * @param string $websiteId
  * @param array $updateFields       the array of fields for compare with rule price and update
  * @param string $websiteDate
  * @return \Magento\CatalogRule\Model\ResourceModel\Rule\Product\Price
  */
 public function applyPriceRuleToIndexTable(\Magento\Framework\DB\Select $select, $indexTable, $entityId, $customerGroupId, $websiteId, $updateFields, $websiteDate)
 {
     if (empty($updateFields)) {
         return $this;
     }
     if (is_array($indexTable)) {
         foreach ($indexTable as $k => $v) {
             if (is_string($k)) {
                 $indexAlias = $k;
             } else {
                 $indexAlias = $v;
             }
             break;
         }
     } else {
         $indexAlias = $indexTable;
     }
     $select->join(['rp' => $this->getMainTable()], "rp.rule_date = {$websiteDate}", [])->where("rp.product_id = {$entityId} AND rp.website_id = {$websiteId} AND rp.customer_group_id = {$customerGroupId}");
     foreach ($updateFields as $priceField) {
         $priceCond = $this->getConnection()->quoteIdentifier([$indexAlias, $priceField]);
         $priceExpr = $this->getConnection()->getCheckSql("rp.rule_price < {$priceCond}", 'rp.rule_price', $priceCond);
         $select->columns([$priceField => $priceExpr]);
     }
     $query = $select->crossUpdateFromSelect($indexTable);
     $this->getConnection()->query($query);
     return $this;
 }
Пример #12
0
 protected function setUp()
 {
     parent::setUp();
     $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getErrorAggregator', 'getBehavior', 'getNewSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope', 'getConnection'], [], '', false);
     $this->entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto', 'fetchAssoc'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->select->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->initFetchAllCalls();
     $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->attrSetColFac = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->attrSetColFac->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
     $this->prodAttrColFac = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection', [], [], '', false);
     $attrCollection->expects($this->any())->method('addFieldToFilter')->willReturn([]);
     $this->prodAttrColFac->expects($this->any())->method('create')->will($this->returnValue($attrCollection));
     $this->params = [0 => $this->entityModel, 1 => 'bundle'];
     $this->bundle = $this->objectManagerHelper->getObject('Magento\\BundleImportExport\\Model\\Import\\Product\\Type\\Bundle', ['attrSetColFac' => $this->attrSetColFac, 'prodAttrColFac' => $this->prodAttrColFac, 'resource' => $this->resource, 'params' => $this->params]);
 }
Пример #13
0
 public function testRender()
 {
     $sql = 'SELECT';
     $expectedResult = $sql . ' ' . Select::SQL_HAVING . ' having1 having2';
     $mapValues = [[Select::FROM, true], [Select::HAVING, ['having1', 'having2']]];
     $this->selectMock->expects($this->any())->method('getPart')->willReturnMap($mapValues);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Пример #14
0
 protected function setUp()
 {
     $this->entityModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], [], '', false);
     $attrSetColFactory = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $attrSetCollection = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', [], [], '', false);
     $attrColFactory = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $attributeSet = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], [], '', false);
     $attrCollection = $this->getMock('\\Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Collection', ['addFieldToFilter'], [], '', false);
     $attribute = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute', ['getAttributeCode', 'getId', 'getIsVisible', 'getIsGlobal', 'getIsRequired', 'getIsUnique', 'getFrontendLabel', 'isStatic', 'getApplyTo', 'getDefaultValue', 'usesSource', 'getFrontendInput'], [], '', false);
     $attribute->expects($this->any())->method('getIsVisible')->willReturn(true);
     $attribute->expects($this->any())->method('getIsGlobal')->willReturn(true);
     $attribute->expects($this->any())->method('getIsRequired')->willReturn(true);
     $attribute->expects($this->any())->method('getIsUnique')->willReturn(true);
     $attribute->expects($this->any())->method('getFrontendLabel')->willReturn('frontend_label');
     $attribute->expects($this->any())->method('getApplyTo')->willReturn(['simple']);
     $attribute->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
     $attribute->expects($this->any())->method('usesSource')->willReturn(true);
     $entityAttributes = [['attribute_id' => 'attribute_id', 'attribute_set_name' => 'attributeSetName'], ['attribute_id' => 'boolean_attribute', 'attribute_set_name' => 'attributeSetName']];
     $attribute1 = clone $attribute;
     $attribute2 = clone $attribute;
     $attribute1->expects($this->any())->method('getId')->willReturn('1');
     $attribute1->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
     $attribute1->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
     $attribute1->expects($this->any())->method('isStatic')->willReturn(true);
     $attribute2->expects($this->any())->method('getId')->willReturn('2');
     $attribute2->expects($this->any())->method('getAttributeCode')->willReturn('boolean_attribute');
     $attribute2->expects($this->any())->method('getFrontendInput')->willReturn('boolean');
     $attribute2->expects($this->any())->method('isStatic')->willReturn(false);
     $this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
     $this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturnOnConsecutiveCalls(['option1', 'option2'], ['yes' => 1, 'no' => 0]);
     $attrSetColFactory->expects($this->any())->method('create')->willReturn($attrSetCollection);
     $attrSetCollection->expects($this->any())->method('setEntityTypeFilter')->willReturn([$attributeSet]);
     $attrColFactory->expects($this->any())->method('create')->willReturn($attrCollection);
     $attrCollection->expects($this->any())->method('setAttributeSetFilter')->willReturn([$attribute1, $attribute2]);
     $attributeSet->expects($this->any())->method('getId')->willReturn(1);
     $attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
     $attrCollection->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', ['in' => ['attribute_id', 'boolean_attribute']])->willReturn([$attribute1, $attribute2]);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $connection->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getConnection')->willReturn($connection);
     $this->connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->connection->expects($this->any())->method('fetchAll')->will($this->returnValue($entityAttributes));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->simpleType = $this->objectManagerHelper->getObject('Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\Simple', ['attrSetColFac' => $attrSetColFactory, 'prodAttrColFac' => $attrColFactory, 'params' => [$this->entityModel, 'simple'], 'resource' => $this->resource]);
     $this->abstractType = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMockForAbstractClass();
 }
Пример #15
0
 public function testRender()
 {
     $sql = 'SELECT';
     $expectedResult = $sql . ' ' . Select::SQL_GROUP_BY . ' group1' . ",\n\t" . 'group2';
     $mapValues = [[Select::FROM, true], [Select::GROUP, ['group1', 'group2']]];
     $this->selectMock->expects($this->exactly(3))->method('getPart')->willReturnMap($mapValues);
     $this->quoteMock->expects($this->exactly(2))->method('quoteIdentifier')->willReturnArgument(0);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Пример #16
0
 /**
  * @param array $from
  * @param string $sql
  * @param string $expectedResult
  * @dataProvider renderDataProvider
  */
 public function testRender($from, $sql, $expectedResult)
 {
     $this->quoteMock->expects($this->any())->method('quoteIdentifier')->willReturnArgument(0);
     $this->quoteMock->expects($this->any())->method('quoteTableAs')->willReturnCallback(function ($tableName, $correlationName) {
         return $tableName . ' AS ' . $correlationName;
     });
     $this->selectMock->expects($this->once())->method('getPart')->with(Select::FROM)->willReturn($from);
     $this->assertEquals($expectedResult, $this->model->render($this->selectMock, $sql));
 }
Пример #17
0
 /**
  * Render SELECT statement
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     $sql = Select::SQL_SELECT;
     foreach ($this->renderers as $renderer) {
         if (in_array($renderer['part'], [Select::COLUMNS, Select::FROM]) || $select->getPart($renderer['part'])) {
             $sql = $renderer['renderer']->render($select, $sql);
         }
     }
     return $sql;
 }
Пример #18
0
 /**
  * Run test mapFields method
  *
  * @return void
  */
 public function testMapFields()
 {
     $fields = [['test-correlation-name', 'test-field', 'test-alias'], ['test-correlation-name', 'test-field', null], ['test-correlation-name', 'test-field', 'test-alias-unique']];
     /** @var \Magento\Framework\DB\GenericMapper|\PHPUnit_Framework_MockObject_MockObject $geneticMapper */
     $geneticMapper = $this->getMock('Magento\\Framework\\DB\\GenericMapper', ['getSelect'], [], '', false);
     $geneticMapper->expects($this->any())->method('getSelect')->will($this->returnValue($this->selectMock));
     $this->selectMock->expects($this->once())->method('getPart')->with(\Magento\Framework\DB\Select::COLUMNS)->willReturn([]);
     $this->selectMock->expects($this->once())->method('setPart')->with(\Magento\Framework\DB\Select::COLUMNS, $this->equalTo($fields));
     $geneticMapper->mapFields($fields);
 }
 /**
  * @test
  */
 public function testAddFieldToFilter()
 {
     $field = 'name';
     $value = 'test_filter';
     $searchSql = 'sql query';
     $this->connection->expects($this->any())->method('quoteIdentifier')->willReturn($searchSql);
     $this->connection->expects($this->any())->method('prepareSqlCondition')->willReturn($searchSql);
     $this->select->expects($this->once())->method('where')->with($searchSql, null, \Magento\Framework\DB\Select::TYPE_CONDITION);
     $this->assertSame($this->collection, $this->collection->addFieldToFilter($field, $value));
 }
Пример #20
0
 /**
  * Method for FULLTEXT search in Mysql, will added generated
  * MATCH ($columns) AGAINST ('$expression' $mode) to where clause
  *
  * @param \Magento\Framework\DB\Select $select
  * @param string|string[] $columns Columns which add to MATCH ()
  * @param string $expression Expression which add to AGAINST ()
  * @param bool $isCondition true=AND, false=OR
  * @param string $mode
  * @return \Magento\Framework\DB\Select
  */
 public function match($select, $columns, $expression, $isCondition = true, $mode = self::FULLTEXT_MODE_NATURAL)
 {
     $fullCondition = $this->getMatchQuery($columns, $expression, $mode);
     if ($isCondition) {
         $select->where($fullCondition);
     } else {
         $select->orWhere($fullCondition);
     }
     return $select;
 }
Пример #21
0
 public function testAddOrdersFilter()
 {
     $this->resourceConnectionMock->expects($this->exactly(2))->method('getConnection')->willReturn($this->connectionMock);
     $this->resourceConnectionMock->expects($this->once())->method('getTableName')->with('paypal_billing_agreement_order')->willReturn('pref_paypal_billing_agreement_order');
     $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
     $this->selectMock->expects($this->once())->method('from')->with(['pbao' => 'pref_paypal_billing_agreement_order'], ['order_id'], null)->willReturnSelf();
     $this->selectMock->expects($this->exactly(2))->method('where')->withConsecutive(['pbao.agreement_id IN(?)', [100]], ['main_table.entity_id IN (?)', [500]])->willReturnSelf();
     $this->connectionMock->expects($this->once())->method('fetchCol')->with($this->selectMock, [])->willReturn([500]);
     $this->collectionMock->expects($this->once())->method('getSelect')->willReturn($this->selectMock);
     $this->assertEquals($this->agreementResource, $this->agreementResource->addOrdersFilter($this->collectionMock, 100));
 }
Пример #22
0
 protected function mockBuild($index, $tableSuffix)
 {
     $this->request->expects($this->once())->method('getIndex')->will($this->returnValue($index));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnCallback(function ($index) {
         return is_array($index) ? $index[0] . $index[1] : $index;
     }));
     $this->select->expects($this->once())->method('from')->with(['search_index' => $index . $tableSuffix], ['entity_id' => 'product_id'])->will($this->returnSelf());
     $this->select->expects($this->at(1))->method('joinLeft')->with(['category_index' => 'catalog_category_product_index'], 'search_index.product_id = category_index.product_id' . ' AND search_index.store_id = category_index.store_id', [])->will($this->returnSelf());
     $this->select->expects($this->at(2))->method('joinLeft')->with(['cea' => 'catalog_eav_attribute'], 'search_index.attribute_id = cea.attribute_id', ['search_weight'])->will($this->returnSelf());
     $this->select->expects($this->at(3))->method('joinLeft')->with(['cpie' => $this->resource->getTableName('catalog_product_index_eav')], 'search_index.product_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id', [])->willReturnSelf();
 }
Пример #23
0
 /**
  * Render GROUP BY section
  *
  * @param Select $select
  * @param string $sql
  * @return string
  */
 public function render(Select $select, $sql = '')
 {
     if ($select->getPart(Select::FROM) && $select->getPart(Select::GROUP)) {
         $group = [];
         foreach ($select->getPart(Select::GROUP) as $term) {
             $group[] = $this->quote->quoteIdentifier($term);
         }
         $sql .= ' ' . Select::SQL_GROUP_BY . ' ' . implode(",\n\t", $group);
     }
     return $sql;
 }
Пример #24
0
 protected function setUp()
 {
     $this->selectMock = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
     $this->selectMock->expects($this->any())->method('where');
     $this->adapterMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock = $this->getMock('\\Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->configMock = $this->getMock('\\Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->model = new \Magento\Quote\Model\Resource\Quote($this->resourceMock, $this->configMock);
 }
Пример #25
0
 protected function setUp()
 {
     $this->_selectMock = $this->getMock('\\Magento\\Framework\\DB\\Select', array(), array(), '', false);
     $this->_selectMock->expects($this->any())->method('from')->will($this->returnSelf());
     $this->_selectMock->expects($this->any())->method('where');
     $this->_adapterMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', array(), array(), '', false);
     $this->_adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->_selectMock));
     $this->_resourceMock = $this->getMock('\\Magento\\Framework\\App\\Resource', array(), array(), '', false);
     $this->_resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->_adapterMock));
     $this->_configMock = $this->getMock('\\Magento\\Eav\\Model\\Config', array(), array(), '', false);
     $this->_model = new \Magento\Sales\Model\Resource\Quote($this->_resourceMock, new \Magento\Framework\Stdlib\DateTime(), $this->_configMock);
 }
Пример #26
0
 /**
  * Check structure of sql query
  *
  * @param \Magento\Framework\DB\Select $select
  * @return array
  */
 public function fetchAllCallback(\Magento\Framework\DB\Select $select)
 {
     $whereParts = $select->getPart(\Magento\Framework\DB\Select::WHERE);
     $this->assertCount(2, $whereParts);
     $this->assertContains("rule_name IS NOT NULL", $whereParts[0]);
     $this->assertContains("rule_name <> ''", $whereParts[1]);
     $orderParts = $select->getPart(\Magento\Framework\DB\Select::ORDER);
     $this->assertCount(1, $orderParts);
     $expectedOrderParts = ['rule_name', 'ASC'];
     $this->assertEquals($expectedOrderParts, $orderParts[0]);
     return $this->_rules;
 }
 public function testExecute()
 {
     $identifier = '100000001';
     $context = ['store_id' => 1];
     $expectedData = ['entity_id' => 1];
     $this->select->expects($this->once())->method('from')->with(['t' => 'entity_table'])->willReturnSelf();
     $this->select->expects($this->at(1))->method('where')->with('identifier = ?', $identifier)->willReturnSelf();
     $this->select->expects($this->at(2))->method('where')->with('store_id = ?', 1)->willReturnSelf();
     $this->connection->expects($this->once())->method('fetchRow')->willReturn($expectedData);
     $actualData = $this->subject->execute('Test\\Entity\\Type', $identifier, $context);
     $this->assertEquals($expectedData, $actualData);
 }
Пример #28
0
 /**
  * Retrieve all necessary objects mocks which used inside customer storage
  *
  * @param int $tableRowsCount
  * @param array $tableData
  * @param array $aliasesMap
  *
  * @return array
  */
 protected function _getModelDependencies($tableRowsCount = 0, $tableData = [], $aliasesMap = [])
 {
     $this->_selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->_selectMock->expects($this->any())->method('from')->will($this->returnSelf());
     $this->_selectMock->expects($this->any())->method('where')->will($this->returnCallback([$this, 'whereCallback']));
     $adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'update', 'fetchAll', 'fetchOne'], [], '', false);
     $adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->_selectMock));
     $adapterMock->expects($this->any())->method('update')->will($this->returnCallback([$this, 'updateCallback']));
     $adapterMock->expects($this->any())->method('fetchAll')->will($this->returnValue($tableData));
     $adapterMock->expects($this->any())->method('fetchOne')->will($this->returnValue($tableRowsCount));
     return ['resource_config' => 'not_used', 'connection_config' => 'not_used', 'module_config' => 'not_used', 'base_dir' => 'not_used', 'path_to_map_file' => 'not_used', 'connection' => $adapterMock, 'core_helper' => $this->getMock('Magento\\Core\\Helper\\Data', [], [], '', false, false), 'aliases_map' => $aliasesMap];
 }
 /**
  * @param \Magento\Framework\DB\Select $select
  * @throws \Exception
  */
 public function filterResults(Select $select)
 {
     $page = $this->request->getQuery('page', 1);
     if (!is_numeric($page)) {
         throw new \Exception("Page {$page} is not a valid integer");
     }
     $limit = $this->request->getQuery('limit', 100);
     if (!is_numeric($limit)) {
         throw new \Exception("Limit {$limit} is not a valid integer");
     }
     $select->limitPage((int) $page, (int) $limit);
 }
Пример #30
-1
 public function testAddFieldToFilter()
 {
     $field = 'title';
     $value = 'test_filter';
     $searchSql = 'sql query';
     $this->collection->expects($this->once())->method('_translateCondition')->with($field, $value)->will($this->returnValue($searchSql));
     $this->select->expects($this->once())->method('where')->with($this->equalTo($searchSql), $this->equalTo(null), $this->equalTo(\Magento\Framework\DB\Select::TYPE_CONDITION));
     $this->collection->addFieldToFilter($field, $value);
 }