예제 #1
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]);
 }
 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));
 }
예제 #3
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));
 }
 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();
 }
예제 #5
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]);
 }
예제 #6
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));
 }
예제 #7
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));
 }
예제 #8
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();
 }
예제 #9
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));
 }
 /**
  * @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));
 }
예제 #11
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);
 }
예제 #12
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();
 }
예제 #13
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));
 }
예제 #14
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);
 }
예제 #15
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);
 }
예제 #16
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];
 }
 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);
 }
예제 #18
0
 /**
  * Test for method "build"
  */
 public function testBuild()
 {
     $productIds = [1, 2, 3];
     $metrics = ['count' => 'count(*)'];
     $this->select->expects($this->once())->method('where')->withConsecutive(['main_table.entity_id IN (?)', $productIds]);
     $this->select->expects($this->once())->method('columns')->withConsecutive([$metrics]);
     $this->select->expects($this->once())->method('group')->withConsecutive(['value']);
     $this->metricsBuilder->expects($this->once())->method('build')->willReturn($metrics);
     $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select);
     $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select);
     $result = $this->term->build($this->dataProvider, [], $this->bucket, $productIds);
     $this->assertEquals($this->select, $result);
 }
예제 #19
0
 public function testApply()
 {
     $filter = new Filter();
     $filter->setValue('test');
     $this->collectionAbstractDbMock->expects($this->any())->method('getMainTable')->willReturn('testTable');
     $this->collectionAbstractDbMock->expects($this->once())->method('getConnection')->willReturn($this->connectionMock);
     $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock);
     $this->connectionMock->expects($this->once())->method('getIndexList')->willReturn([['INDEX_TYPE' => 'FULLTEXT', 'COLUMNS_LIST' => ['col1', 'col2']]]);
     $this->selectMock->expects($this->once())->method('getPart')->willReturn([]);
     $this->selectMock->expects($this->once())->method('where')->willReturn(null);
     $this->collectionAbstractDbMock->expects($this->exactly(2))->method('getSelect')->willReturn($this->selectMock);
     $this->fulltextFilter->apply($this->collectionAbstractDbMock, $filter);
 }
예제 #20
0
 /**
  * Test refresh method
  */
 public function testRefresh()
 {
     $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->appResourceMock->expects($this->any())->method('getTableName')->will($this->returnValue('sales_order_grid'));
     $this->adapterMock->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->selectMock->expects($this->once())->method('from')->will($this->returnSelf());
     $this->selectMock->expects($this->exactly(2))->method('joinLeft')->will($this->returnSelf());
     $this->selectMock->expects($this->once())->method('columns')->will($this->returnSelf());
     $this->selectMock->expects($this->once())->method('where')->with('fi.field = ?', 1, null)->will($this->returnSelf());
     $this->adapterMock->expects($this->once())->method('query')->with('sql-query')->will($this->returnValue($this->statementMock));
     $this->adapterMock->expects($this->once())->method('insertFromSelect')->with($this->selectMock, 'sales_order_grid', [], 1)->will($this->returnValue('sql-query'));
     $this->assertEquals($this->statementMock, $this->grid->refresh(1, 'fi.field'));
 }
예제 #21
0
 /**
  * Test for method "build"
  */
 public function testBuild()
 {
     $metrics = ['count' => 'count(*)'];
     $this->select->expects($this->once())->method('columns')->withConsecutive([$metrics]);
     $this->select->expects($this->once())->method('group')->withConsecutive(['value']);
     $this->metricsBuilder->expects($this->once())->method('build')->willReturn($metrics);
     $this->dataProvider->expects($this->once())->method('getDataSet')->willReturn($this->select);
     $this->dataProvider->expects($this->once())->method('execute')->willReturn($this->select);
     /** @var \Magento\Framework\DB\Ddl\Table|\PHPUnit_Framework_MockObject_MockObject $table */
     $table = $this->getMockBuilder('Magento\\Framework\\DB\\Ddl\\Table')->disableOriginalConstructor()->getMock();
     $result = $this->term->build($this->dataProvider, [], $this->bucket, $table);
     $this->assertEquals($this->select, $result);
 }
예제 #22
0
 protected function setUp()
 {
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'prepareSqlCondition', 'quoteIdentifier'], [], '', false);
     $this->resource = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ResourceModel\\Db\\AbstractDb', [], '', false, true, true, ['getConnection', '__wakeup', 'getMainTable', 'getTable']);
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->resource->expects($this->any())->method('getMainTable')->will($this->returnValue('test_main_table'));
     $this->resource->expects($this->any())->method('getTable')->with('test_main_table')->will($this->returnValue('test_main_table'));
     $this->collection = (new ObjectManager($this))->getObject('Magento\\UrlRewrite\\Model\\ResourceModel\\UrlRewriteCollection', ['storeManager' => $this->storeManager, 'resource' => $this->resource]);
 }
 /**
  * @param int $amount
  * @param array $collectionArray
  * @param array $result
  * @dataProvider getDataDataProvider
  */
 public function testGetData($amount, array $collectionArray, array $result)
 {
     $tableName = 'catalog_product_option_table';
     $this->collectionMock->expects($this->once())->method('isLoaded')->willReturn(false);
     $this->requestMock->expects($this->once())->method('getParam')->with('current_product_id', null)->willReturn(0);
     $this->collectionMock->expects($this->any())->method('getSelect')->willReturn($this->dbSelectMock);
     $this->dbSelectMock->expects($this->any())->method('distinct')->willReturnSelf();
     $this->collectionMock->expects($this->any())->method('getTable')->with('catalog_product_option')->willReturn($tableName);
     $this->dbSelectMock->expects($this->once())->method('join')->with(['opt' => $tableName], 'opt.product_id = e.entity_id', null)->willReturnSelf();
     $this->collectionMock->expects($this->once())->method('load')->willReturnSelf();
     $this->collectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([]));
     $this->setCommonExpectations(false, $amount, $collectionArray);
     $this->assertSame($result, $this->dataProvider->getData());
 }
예제 #24
0
 /**
  * @dataProvider overriddenUrlKeyForStoreDataProvider
  * @param int $storeId
  * @param array $fetchedStoreIds
  * @param bool $result
  */
 public function testDoesEntityHaveOverriddenUrlKeyForStore($storeId, $fetchedStoreIds, $result)
 {
     $entityType = 'entity_type';
     $productId = 'product_id';
     $attribute = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->disableOriginalConstructor()->setMethods(['__wakeup', 'getBackendTable', 'getId'])->getMockForAbstractClass();
     $this->config->expects($this->once())->method('getAttribute')->with($entityType, 'url_key')->will($this->returnValue($attribute));
     $attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table'));
     $attribute->expects($this->once())->method('getId')->will($this->returnValue('attribute-id'));
     $this->select->expects($this->once())->method('from')->with('backend_table', 'store_id')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
     $this->connection->expects($this->once())->method('fetchCol')->will($this->returnValue($fetchedStoreIds));
     $this->assertEquals($result, $this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore($storeId, $productId, $entityType));
 }
 /**
  * @return void
  */
 public function testPerform()
 {
     $this->data = new Data($this->destination, $this->progress);
     $this->progress->expects($this->once())->method('start')->with(1);
     $this->progress->expects($this->once())->method('advance');
     $this->progress->expects($this->once())->method('finish');
     $this->destination->expects($this->once())->method('getAdapter')->willReturn($this->adapter);
     $this->adapter->expects($this->once())->method('getSelect')->willReturn($this->select);
     $this->select->expects($this->once())->method('from')->with('rating_store', ['rating_id'])->will($this->returnSelf());
     $this->select->expects($this->once())->method('where')->with('store_id > 0')->will($this->returnSelf());
     $this->adapter->expects($this->once())->method('loadDataFromSelect')->with($this->select)->willReturn([['rating_id' => 1]]);
     $this->adapter->expects($this->once())->method('updateDocument')->with('rating', ['is_active' => 1], 'rating_id IN (1)');
     $this->data->perform();
 }
예제 #26
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->connectionMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['update', 'insertOnDuplicate'], [], '', false);
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $tableName = 'sales_order_status_state';
     $this->resourceMock->expects($this->at(1))->method('getTableName')->with($this->equalTo($tableName))->will($this->returnValue($tableName));
     $this->resourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->configMock = $this->getMock('\\Magento\\Eav\\Model\\Config', ['getConnectionName'], [], '', false);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->model = $objectManager->getObject('Magento\\Sales\\Model\\ResourceModel\\Order\\Status', ['resource' => $this->resourceMock]);
 }
예제 #27
0
    public function testBuildBoolQuery()
    {
        $query = $this->createBoolQuery();
        $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query));

        $matchQuery = $this->createMatchQuery();
        $filterMatchQuery = $this->createFilterQuery();
        $filterMatchQuery->expects($this->once())->method('getReferenceType')
            ->will($this->returnValue(Filter::REFERENCE_QUERY));
        $filterMatchQuery->expects($this->once())->method('getReference')->will($this->returnValue($matchQuery));

        $filterQuery = $this->createFilterQuery();
        $filterQuery->expects($this->once())->method('getReferenceType')
            ->will($this->returnValue(Filter::REFERENCE_FILTER));
        $filterQuery->expects($this->once())->method('getReference')->will($this->returnValue($this->filter));

        $this->request->expects($this->once())->method('getQuery')->will($this->returnValue($query));

        $this->filterBuilder->expects($this->once())->method('build')->will($this->returnValue('(1)'));

        $this->select->expects($this->once())->method('columns')->will($this->returnValue($this->select));

        $query->expects($this->once())
            ->method('getMust')
            ->will(
                $this->returnValue(
                    [
                        $this->createMatchQuery(),
                        $this->createFilterQuery(),
                    ]
                )
            );

        $query->expects($this->once())
            ->method('getShould')
            ->will(
                $this->returnValue(
                    [
                        $this->createMatchQuery(),
                        $filterMatchQuery,
                    ]
                )
            );

        $query->expects($this->once())
            ->method('getMustNot')
            ->will(
                $this->returnValue(
                    [
                        $this->createMatchQuery(),
                        $filterQuery,
                    ]
                )
            );

        $response = $this->mapper->buildQuery($this->request);

        $this->assertEquals($this->select, $response);
    }
예제 #28
0
 /**
  * Run test fetchItem method
  *
  * @return void
  */
 public function testFetchItem()
 {
     $adapterMock = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false, true, true, ['query']);
     $this->selectMock->expects($this->once())->method('getAdapter')->will($this->returnValue($adapterMock));
     $adapterMock->expects($this->once())->method('query')->will($this->returnValue($this->fetchStmtMock));
     $this->fetchStmtMock->expects($this->once())->method('fetch')->will($this->returnValue(null));
     $this->assertEquals([], $this->query->fetchItem());
 }
예제 #29
0
 /**
  * Run test fetchItem method
  *
  * @return void
  */
 public function testFetchItem()
 {
     $adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['query'], [], '', false);
     $this->selectMock->expects($this->once())->method('getConnection')->will($this->returnValue($adapterMock));
     $adapterMock->expects($this->once())->method('query')->will($this->returnValue($this->fetchStmtMock));
     $this->fetchStmtMock->expects($this->once())->method('fetch')->will($this->returnValue(null));
     $this->assertEquals([], $this->query->fetchItem());
 }
예제 #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);
 }