protected function setUp()
 {
     $this->_adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->_resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->_resourceMock->expects($this->any())->method('getConnection')->with('prefix')->will($this->returnValue($this->_adapterMock));
     $this->_model = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Helper\\AbstractHelper', [$this->_resourceMock, 'prefix'], '', true, true, true, ['addLikeEscape']);
 }
 protected function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('quoteInto')->willReturnCallback(function ($query, $expression) {
         return str_replace('?', $expression, $query);
     });
     $this->resource = $this->getMockBuilder('\\Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->resource->method('getTableName')->willReturnCallback(function ($table) {
         return 'prefix_' . $table;
     });
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->website = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\WebsiteInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->website->expects($this->any())->method('getId')->willReturn(self::WEBSITE_ID);
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->store->expects($this->any())->method('getId')->willReturn(self::STORE_ID);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->any())->method('getWebsite')->willReturn($this->website);
     $this->storeManager->expects($this->any())->method('getStore')->willReturn($this->store);
     $this->attributeCollection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $attributeCollectionFactory->expects($this->once())->method('create')->willReturn($this->attributeCollection);
     $this->target = $objectManager->getObject('\\Magento\\CatalogSearch\\Model\\Search\\TableMapper', ['resource' => $this->resource, 'storeManager' => $this->storeManager, 'attributeCollectionFactory' => $attributeCollectionFactory]);
     $this->select = $this->getMockBuilder('\\Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\Search\\RequestInterface')->disableOriginalConstructor()->getMock();
 }
 public function getLotsByProductId($prodId, $stockId)
 {
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $conn */
     $conn = $this->_repoGeneric->getConnection();
     /* aliases and tables */
     $asStockItem = 'csi';
     $asQty = 'pwq';
     $asLot = 'pwl';
     $tblStockItem = [$asStockItem => $this->_resource->getTableName(Cfg::ENTITY_MAGE_CATALOGINVENTORY_STOCK_ITEM)];
     $tblQty = [$asQty => $this->_resource->getTableName(Quantity::ENTITY_NAME)];
     $tblLot = [$asLot => $this->_resource->getTableName(Lot::ENTITY_NAME)];
     /* SELECT FROM cataloginventory_stock_item */
     $query = $conn->select();
     $cols = [Alias::AS_STOCK_ITEM_ID => Cfg::E_CATINV_STOCK_ITEM_A_ITEM_ID];
     $query->from($tblStockItem, $cols);
     /* LEFT JOIN prxgt_wrhs_qty pwq */
     $on = $asQty . '.' . Quantity::ATTR_STOCK_ITEM_REF . '=' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_ITEM_ID;
     $cols = [Alias::AS_QTY => Quantity::ATTR_TOTAL];
     $query->joinLeft($tblQty, $on, $cols);
     // LEFT JOIN prxgt_wrhs_lot pwl
     $on = $asLot . '.' . Lot::ATTR_ID . '=' . $asQty . '.' . Quantity::ATTR_LOT_REF;
     $cols = [Alias::AS_LOT_ID => Lot::ATTR_ID, Alias::AS_LOT_CODE => Lot::ATTR_CODE, Alias::AS_LOT_EXP_DATE => Lot::ATTR_EXP_DATE];
     $query->joinLeft($tblLot, $on, $cols);
     /* where */
     $where = $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_PROD_ID . '=' . (int) $prodId;
     $where .= ' AND ' . $asStockItem . '.' . Cfg::E_CATINV_STOCK_ITEM_A_STOCK_ID . '=' . (int) $stockId;
     $query->where($where);
     /* order by */
     $order = $asLot . '.' . Lot::ATTR_EXP_DATE . ' ASC';
     $query->order($order);
     /* fetch data */
     $result = $conn->fetchAll($query);
     return $result;
 }
Esempio n. 4
0
 /**
  * @magentoDataFixture Magento/Bundle/_files/product.php
  * @covers \Magento\Indexer\Model\Indexer::reindexAll
  * @covers \Magento\Bundle\Model\Product\Type::getSearchableData
  */
 public function testPrepareProductIndexForBundleProduct()
 {
     $this->indexer->reindexAll();
     $select = $this->connectionMock->select()->from($this->resource->getTableName('catalogsearch_fulltext_scope1'))->where('`data_index` LIKE ?', '%' . 'Bundle Product Items' . '%');
     $result = $this->connectionMock->fetchAll($select);
     $this->assertCount(1, $result);
 }
Esempio n. 5
0
 /**
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 protected function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection('sales');
     }
     return $this->connection;
 }
 /**
  * Returns Adapter interface
  *
  * @return array \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->resource->getConnection(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION);
     }
     return $this->connection;
 }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function install(array $fixtures)
 {
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface $adapter */
     $adapter = $this->resource->getConnection('core_write');
     $regions = $this->loadDirectoryRegions();
     foreach ($fixtures as $fileName) {
         $fileName = $this->fixtureManager->getFixture($fileName);
         if (!file_exists($fileName)) {
             continue;
         }
         $rows = $this->csvReader->getData($fileName);
         $header = array_shift($rows);
         foreach ($rows as $row) {
             $data = [];
             foreach ($row as $key => $value) {
                 $data[$header[$key]] = $value;
             }
             $regionId = $data['region'] != '*' ? $regions[$data['country']][$data['region']] : 0;
             try {
                 $adapter->insert($this->tablerate->getMainTable(), ['website_id' => $this->storeManager->getWebsite()->getId(), 'dest_country_id' => $data['country'], 'dest_region_id' => $regionId, 'dest_zip' => $data['zip'], 'condition_name' => 'package_value', 'condition_value' => $data['order_subtotal'], 'price' => $data['price'], 'cost' => 0]);
             } catch (\Zend_Db_Statement_Exception $e) {
                 if ($e->getCode() == self::ERROR_CODE_DUPLICATE_ENTRY) {
                     // In case if Sample data was already installed we just skip duplicated records installation
                     continue;
                 } else {
                     throw $e;
                 }
             }
         }
     }
     $this->configWriter->save('carriers/tablerate/active', 1);
     $this->configWriter->save('carriers/tablerate/condition_name', 'package_value');
     $this->cacheTypeList->cleanType('config');
 }
 public function testCreate()
 {
     $triggerName = 'trigger_name';
     $this->resourceMock->expects($this->atLeastOnce())->method('getTriggerName')->willReturn($triggerName);
     $triggerMock = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Trigger')->disableOriginalConstructor()->getMock();
     $triggerMock->expects($this->exactly(3))->method('setName')->with($triggerName)->will($this->returnSelf());
     $triggerMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('triggerName'));
     $triggerMock->expects($this->exactly(3))->method('setTime')->with(\Magento\Framework\DB\Ddl\Trigger::TIME_AFTER)->will($this->returnSelf());
     $triggerMock->expects($this->exactly(3))->method('setEvent')->will($this->returnSelf());
     $triggerMock->expects($this->exactly(3))->method('setTable')->with($this->tableName)->will($this->returnSelf());
     $triggerMock->expects($this->exactly(6))->method('addStatement')->will($this->returnSelf());
     $changelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []);
     $changelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('test_view_cl'));
     $changelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id'));
     $this->viewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($changelogMock));
     $this->triggerFactoryMock->expects($this->exactly(3))->method('create')->will($this->returnValue($triggerMock));
     $otherChangelogMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\View\\ChangelogInterface', [], '', false, false, true, []);
     $otherChangelogMock->expects($this->exactly(3))->method('getName')->will($this->returnValue('other_test_view_cl'));
     $otherChangelogMock->expects($this->exactly(3))->method('getColumnName')->will($this->returnValue('entity_id'));
     $otherViewMock = $this->getMockForAbstractClass('Magento\\Framework\\Mview\\ViewInterface', [], '', false, false, true, []);
     $otherViewMock->expects($this->exactly(1))->method('getId')->will($this->returnValue('other_id'));
     $otherViewMock->expects($this->exactly(1))->method('getSubscriptions')->will($this->returnValue([['name' => $this->tableName], ['name' => 'otherTableName']]));
     $otherViewMock->expects($this->exactly(3))->method('getChangelog')->will($this->returnValue($otherChangelogMock));
     $this->viewMock->expects($this->exactly(3))->method('getId')->will($this->returnValue('this_id'));
     $this->viewMock->expects($this->never())->method('getSubscriptions');
     $this->viewCollectionMock->expects($this->exactly(1))->method('getViewsByStateMode')->with(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED)->will($this->returnValue([$this->viewMock, $otherViewMock]));
     $this->connectionMock->expects($this->exactly(3))->method('dropTrigger')->with('triggerName')->will($this->returnValue(true));
     $this->connectionMock->expects($this->exactly(3))->method('createTrigger')->with($triggerMock);
     $this->model->create();
 }
 public function testSave()
 {
     $connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock = $this->getMock('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', ['_construct', 'getConnection', '__wakeup', 'getIdFieldName'], [], '', false);
     $connectionInterfaceMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionInterfaceMock));
     $data = 'tableName';
     $this->resourcesMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->resourcesMock->expects($this->any())->method('getTableName')->with($data)->will($this->returnValue('tableName'));
     $mainTableReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_mainTable');
     $mainTableReflection->setAccessible(true);
     $mainTableReflection->setValue($this->model, 'tableName');
     $idFieldNameReflection = new \ReflectionProperty('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', '_idFieldName');
     $idFieldNameReflection->setAccessible(true);
     $idFieldNameReflection->setValue($this->model, 'idFieldName');
     $connectionMock->expects($this->any())->method('save')->with('tableName', 'idFieldName');
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName'));
     $abstractModelMock = $this->setupAbstractModel($resourceMock);
     $abstractModelMock->setIdFieldName('id');
     $abstractModelMock->setData(['id' => 12345, 'name' => 'Test Name', 'value' => 'Test Value']);
     $abstractModelMock->afterLoad();
     $this->assertEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $newData = ['value' => 'Test Value New'];
     $abstractModelMock->addData($newData);
     $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $abstractModelMock->isObjectNew(false);
     $connectionMock->expects($this->any())->method('update')->with('tableName', $newData, 'idFieldName');
     $this->relationProcessorMock->expects($this->once())->method('validateDataIntegrity');
     $this->entityManager->expects($this->once())->method('save');
     $this->model->save($abstractModelMock);
 }
Esempio n. 10
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]);
 }
 /**
  * @return void
  */
 public function testDeleteRecordsOlderThen()
 {
     $timestamp = 12345;
     $this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->dbAdapterMock);
     $this->dbAdapterMock->expects($this->once())->method('delete')->with($this->model->getMainTable(), ['created_at < ?' => $this->dateTimeMock->formatDate($timestamp)])->willReturnSelf();
     $this->assertEquals($this->model, $this->model->deleteRecordsOlderThen($timestamp));
 }
Esempio n. 12
0
 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $connection->update($metadata->getEntityTable(), $this->prepareData($metadata, $connection, $data), [$metadata->getLinkField() . ' = ?' => $data[$metadata->getLinkField()]]);
     return $data;
 }
Esempio n. 13
0
 /**
  * {@inheritDoc}
  */
 protected function setUp()
 {
     $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $this->helper = new Helper($this->resourceMock);
 }
Esempio n. 14
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;
 }
Esempio n. 15
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]);
 }
 protected function setUp()
 {
     $this->coreEntityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface', [], [], '', false);
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->configMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->coreResourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resourceHelperMock = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Helper', [], [], '', false);
     $this->validatorFactoryMock = $this->getMock('Magento\\Framework\\Validator\\UniversalFactory', [], [], '', false);
     $this->entityFactoryMock = $this->getMock('Magento\\Eav\\Model\\EntityFactory', [], [], '', false);
     /** @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject */
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->statementMock = $this->getMock('Magento\\Framework\\DB\\Statement\\Pdo\\Mysql', ['fetch'], [], '', false);
     /** @var $selectMock \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject */
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->coreEntityFactoryMock->expects($this->any())->method('create')->will($this->returnCallback([$this, 'getMagentoObject']));
     $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
     $connectionMock->expects($this->any())->method('query')->willReturn($this->statementMock);
     $this->coreResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $entityMock = $this->getMock('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], [], '', false);
     $entityMock->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $entityMock->expects($this->any())->method('getDefaultAttributes')->will($this->returnValue([]));
     $this->validatorFactoryMock->expects($this->any())->method('create')->with('test_entity_model')->will($this->returnValue($entityMock));
     $this->model = new AbstractCollectionStub($this->coreEntityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->configMock, $this->coreResourceMock, $this->entityFactoryMock, $this->resourceHelperMock, $this->validatorFactoryMock, null);
 }
Esempio n. 17
0
 /**
  * @param ResourceConnection $resource
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
  */
 public function __construct(ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->storeManager = $storeManager;
     $this->resourceHelper = $resourceHelper;
     $this->columns = array_merge($this->getStaticColumns(), $this->getEavColumns());
 }
Esempio n. 18
0
 public function getConnection($name = null)
 {
     if (is_null($name)) {
         $name = \Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION;
     }
     $result = $this->_resource->getConnection($name);
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function build($productId)
 {
     $timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
     $currentDate = $this->dateTime->formatDate($timestamp, false);
     $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
     $productTable = $this->resource->getTableName('catalog_product_entity');
     return [$this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalogrule_product_price')], 't.product_id = child.entity_id', [])->where('parent.entity_id = ? ', $productId)->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.rule_date = ?', $currentDate)->order('t.rule_price ' . Select::SQL_ASC)->limit(1)];
 }
Esempio n. 20
0
 /**
  * Get table name (validated by db adapter) by table placeholder
  *
  * @param string|array $tableName
  * @return string
  */
 public function getTable($tableName)
 {
     $cacheKey = $this->_getTableCacheName($tableName);
     if (!isset($this->tables[$cacheKey])) {
         $this->tables[$cacheKey] = $this->resourceModel->getTableName($tableName);
     }
     return $this->tables[$cacheKey];
 }
Esempio n. 21
0
 public function doInsert()
 {
     $tbl = $this->_resource->getTableName(Account::ENTITY_NAME);
     $bind = [Account::ATTR_CUST_ID => 1, Account::ATTR_ASSET_TYPE_ID => 2, Account::ATTR_BALANCE => 123.45];
     $this->_conn->insert($tbl, $bind);
     $result = $this->_conn->lastInsertId($tbl);
     return $result;
 }
Esempio n. 22
0
 /**
  * @param Config $eavConfig
  * @param ResourceConnection $resource
  * @param ScopeResolverInterface $scopeResolver
  * @param Session $customerSession
  */
 public function __construct(Config $eavConfig, ResourceConnection $resource, ScopeResolverInterface $scopeResolver, Session $customerSession)
 {
     $this->eavConfig = $eavConfig;
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->scopeResolver = $scopeResolver;
     $this->customerSession = $customerSession;
 }
Esempio n. 23
0
 /**
  * @param \Magento\Framework\Model\Context $context
  * @param \Magento\Framework\Registry $registry
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  * @param \Magento\UrlRewrite\Helper\UrlRewrite $urlRewriteHelper
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param ResourceConnection $appResource
  * @param \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder
  * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
  * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\UrlRewrite\Helper\UrlRewrite $urlRewriteHelper, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\ResourceConnection $appResource, \Magento\UrlRewrite\Model\UrlFinderInterface $urlFinder, \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, array $data = [])
 {
     parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
     $this->urlRewriteHelper = $urlRewriteHelper;
     $this->connection = $appResource->getConnection();
     $this->urlFinder = $urlFinder;
     $this->storeManager = $storeManager;
 }
 /**
  * @param \Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param TableDataInterface $tableData
  */
 public function __construct(\Magento\Catalog\Helper\Product\Flat\Indexer $productIndexerHelper, \Magento\Framework\App\ResourceConnection $resource, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Indexer\Product\Flat\TableDataInterface $tableData)
 {
     $this->_productIndexerHelper = $productIndexerHelper;
     $this->_connection = $resource->getConnection();
     $this->_config = $config;
     $this->_storeManager = $storeManager;
     $this->_tableData = $tableData;
 }
Esempio n. 25
0
 protected function setUp()
 {
     $connectionMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->relation = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Relation', [], [], '', false);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable', ['resource' => $this->resource, 'catalogProductRelation' => $this->relation]);
 }
Esempio n. 26
0
 public function setUp()
 {
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->resourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock);
     $contextMock = $this->getMock('\\Magento\\Framework\\Model\\ModelResource\\Db\\Context', [], [], '', false);
     $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock);
     $this->tokenResource = new \Magento\Integration\Model\ResourceModel\Oauth\Token($contextMock, new \Magento\Framework\Stdlib\DateTime());
 }
Esempio n. 27
0
 /**
  * Initialization
  */
 protected function setUp()
 {
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->appResourceMock->expects($this->any())->method('getTableName')->willReturnArgument(0);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->taxItem = $objectManager->getObject('Magento\\Sales\\Model\\ResourceModel\\Order\\Tax\\Item', ['resource' => $this->appResourceMock]);
 }
Esempio n. 28
0
 public function testGetTable()
 {
     $tableName = 'table';
     $expectedTableName = 'expected_table';
     $this->resourceModel->expects($this->once())->method('getTableName')->with($tableName)->will($this->returnValue($expectedTableName));
     $this->assertSame($expectedTableName, $this->object->getTable($tableName));
     // Check that table name is cached
     $this->assertSame($expectedTableName, $this->object->getTable($tableName));
 }
Esempio n. 29
0
 /**
  * @param ResourceConnection $resource
  * @param Range $range
  * @param Session $customerSession
  * @param MysqlDataProviderInterface $dataProvider
  * @param IntervalFactory $intervalFactory
  */
 public function __construct(ResourceConnection $resource, Range $range, Session $customerSession, MysqlDataProviderInterface $dataProvider, IntervalFactory $intervalFactory)
 {
     $this->resource = $resource;
     $this->connection = $resource->getConnection();
     $this->range = $range;
     $this->customerSession = $customerSession;
     $this->dataProvider = $dataProvider;
     $this->intervalFactory = $intervalFactory;
 }
Esempio n. 30
0
 protected function setUp()
 {
     $this->config = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['select', 'from', 'where', 'join'])->disableOriginalConstructor()->getMock();
     $this->connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->storeViewService = (new ObjectManager($this))->getObject('Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', ['eavConfig' => $this->config, 'resource' => $this->resource]);
 }