Пример #1
0
 /**
  * Test purge method
  */
 public function testPurge()
 {
     $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->appResourceMock->expects($this->once())->method('getTableName')->will($this->returnValue('sales_flat_invoice_grid'));
     $this->adapterMock->expects($this->once())->method('delete')->with('sales_flat_invoice_grid', ['fi.field = ?' => 1])->will($this->returnValue(1));
     $this->assertEquals(1, $this->grid->purge(1, 'fi.field'));
 }
Пример #2
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;
 }
 /**
  * @param int $storeId
  * @param bool $withAdmin
  * @param array $condition
  * @dataProvider dataProviderForTestAddStoreFilterIfStoreIsInt
  * @covers \Magento\UrlRewrite\Model\Resource\UrlRewriteCollection
  */
 public function testAddStoreFilterIfStoreIsInt($storeId, $withAdmin, $condition)
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $this->adapter->expects($this->once())->method('prepareSqlCondition')->with('store_id', ['in' => $condition]);
     $this->collection->addStoreFilter($storeId, $withAdmin);
 }
Пример #4
0
 public function testSelectByCompositeKey()
 {
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $selectMock->expects($this->once())->method('from')->will($this->returnValue($selectMock));
     $selectMock->expects($this->exactly(2))->method('where')->will($this->returnValue($selectMock));
     $this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
     $this->adapterMock->expects($this->once())->method('fetchRow');
     $this->nonceResource->selectByCompositeKey('nonce', 5);
 }
Пример #5
0
 protected function processAttributeGetter($dbAttributes)
 {
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->connection->expects($this->once())->method('select')->will($this->returnValue($select));
     $select->expects($this->once())->method('from')->will($this->returnSelf());
     $select->expects($this->once())->method('where')->will($this->returnSelf());
     $this->connection->expects($this->once())->method('fetchAll')->with($select)->will($this->returnValue($dbAttributes));
     $this->link->expects($this->any())->method('getAttributeTypeTable')->will($this->returnValue('table_name'));
 }
Пример #6
0
 public function testSelectTokenByCustomerId()
 {
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $selectMock->expects($this->once())->method('from')->will($this->returnValue($selectMock));
     $selectMock->expects($this->exactly(2))->method('where')->will($this->returnValue($selectMock));
     $this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock);
     $this->adapterMock->expects($this->once())->method('fetchRow');
     $this->tokenResource->selectTokenByCustomerId(5);
 }
 /**
  * @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));
 }
 protected function setUp()
 {
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $this->connection = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('select')->willReturn($this->select);
     $this->resource = $this->getMockBuilder('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb')->disableOriginalConstructor()->setMethods(['getConnection', 'getMainTable', 'getTable'])->getMockForAbstractClass();
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->resource->expects($this->any())->method('getMainTable')->willReturn('table_test');
     $this->resource->expects($this->any())->method('getTable')->willReturn('test');
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
 }
Пример #9
0
 public function testAssignState()
 {
     $state = 'processing';
     $status = 'processing';
     $isDefault = 1;
     $visibleOnFront = 1;
     $tableName = 'sales_order_status_state';
     $this->connectionMock->expects($this->once())->method('update')->with($this->equalTo($tableName), $this->equalTo(['is_default' => 0]), $this->equalTo(['state = ?' => $state]));
     $this->connectionMock->expects($this->once())->method('insertOnDuplicate')->with($this->equalTo($tableName), $this->equalTo(['status' => $status, 'state' => $state, 'is_default' => $isDefault, 'visible_on_front' => $visibleOnFront]));
     $this->model->assignState($status, $state, $isDefault, $visibleOnFront);
 }
Пример #10
0
 public function testGetTimeInSecondsSinceCreation()
 {
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $selectMock->expects($this->any())->method('from')->will($this->returnValue($selectMock));
     $selectMock->expects($this->any())->method('reset')->will($this->returnValue($selectMock));
     $selectMock->expects($this->any())->method('columns')->will($this->returnValue($selectMock));
     $selectMock->expects($this->any())->method('where')->will($this->returnValue($selectMock));
     $this->adapterMock->expects($this->any())->method('select')->willReturn($selectMock);
     $this->adapterMock->expects($this->once())->method('fetchOne');
     $this->consumerResource->getTimeInSecondsSinceCreation(1);
 }
Пример #11
0
 public function testGetTaxItemsByOrderId()
 {
     $orderId = 1;
     $taxItems = [['tax_id' => 1, 'tax_percent' => 5, 'item_id' => 1, 'taxable_item_type' => 4, 'associated_item_id' => 1, 'real_amount' => 12, 'real_base_amount' => 12]];
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->adapterMock->expects($this->once())->method('select')->willReturn($select);
     $select->expects($this->once())->method('from')->with(['item' => 'sales_order_tax_item'], ['tax_id', 'tax_percent', 'item_id', 'taxable_item_type', 'associated_item_id', 'real_amount', 'real_base_amount'])->willReturnSelf();
     $select->expects($this->once())->method('join')->with(['tax' => 'sales_order_tax'], 'item.tax_id = tax.tax_id', ['code', 'title', 'order_id'])->willReturnSelf();
     $select->expects($this->once())->method('where')->with('tax.order_id = ?', $orderId)->willReturnSelf();
     $this->adapterMock->expects($this->once())->method('fetchAll')->with($select)->willReturn($taxItems);
     $this->assertEquals($taxItems, $this->taxItem->getTaxItemsByOrderId($orderId));
 }
Пример #12
0
 /**
  * @expectedException \Exception
  * @expectedExceptionMessage Expected Exception
  * @throws \Exception
  */
 public function testSaveFailed()
 {
     $this->modelMock->expects($this->any())->method('getEventPrefix')->will($this->returnValue('event_prefix'));
     $this->modelMock->expects($this->any())->method('getEventObject')->will($this->returnValue('event_object'));
     $this->appResourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $exception = new \Exception('Expected Exception');
     $this->modelMock->expects($this->any())->method('getId')->will($this->throwException($exception));
     $this->adapterMock->expects($this->once())->method('beginTransaction');
     $this->adapterMock->expects($this->once())->method('rollback');
     $this->eventManagerMock->expects($this->once())->method('dispatch')->with('event_prefix_save_attribute_before', ['event_object' => $this->attribute, 'object' => $this->modelMock, 'attribute' => ['attribute']]);
     $this->attribute->saveAttribute($this->modelMock, 'attribute');
 }
Пример #13
0
 public function testGetUnnotifiedForInstance()
 {
     $orderId = 100000512;
     $entityType = 'order';
     $order = $this->getMock('Magento\\Sales\\Model\\Order', ['__wakeup', 'getEntityType', 'getId'], [], '', false);
     $order->expects($this->once())->method('getEntityType')->will($this->returnValue($entityType));
     $order->expects($this->once())->method('getId')->will($this->returnValue($orderId));
     $this->connectionMock = $this->collection->getResource()->getReadConnection();
     $this->connectionMock->expects($this->exactly(3))->method('prepareSqlCondition')->will($this->returnValueMap([['entity_name', $entityType, 'sql-string'], ['is_customer_notified', 0, 'sql-string'], ['parent_id', $orderId, 'sql-string']]));
     $result = $this->collection->getUnnotifiedForInstance($order);
     $this->assertEquals($this->historyItemMock, $result);
 }
Пример #14
0
 public function setUp()
 {
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History\\Validator', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->historyResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Status\\History', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock]);
 }
Пример #15
0
 /**
  * Mock class dependencies
  */
 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', [], [], '', false);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $objectManager = new ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Quote\\Model\\Resource\\Quote\\Item\\Collection', ['entityFactory' => $this->entityFactoryMock, 'fetchStrategy' => $this->fetchStrategyMock, 'eventManager' => $this->eventManagerMock, 'resource' => $this->resourceMock]);
 }
Пример #16
0
 protected function setUp()
 {
     $this->entityModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', [], [], '', false);
     $attrSetColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $attrSetCollection = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', [], [], '', false);
     $attrColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $attributeSet = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\Set', [], [], '', false);
     $attrCollection = $this->getMock('\\Magento\\Eav\\Model\\Resource\\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);
     $entityAttributes = ['attribute_id' => 'attributeSetName'];
     $this->entityModel->expects($this->any())->method('getEntityTypeId')->willReturn(3);
     $this->entityModel->expects($this->any())->method('getAttributeOptions')->willReturn(['option1', 'option2']);
     $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([$attribute]);
     $attributeSet->expects($this->any())->method('getId')->willReturn(1);
     $attributeSet->expects($this->any())->method('getAttributeSetName')->willReturn('attribute_set_name');
     $attribute->expects($this->any())->method('getAttributeCode')->willReturn('attr_code');
     $attribute->expects($this->any())->method('getId')->willReturn('1');
     $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('isStatic')->willReturn(true);
     $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);
     $attribute->expects($this->any())->method('getFrontendInput')->willReturn('multiselect');
     $attrCollection->expects($this->any())->method('addFieldToFilter')->with('main_table.attribute_id', ['in' => [key($entityAttributes)]])->willReturn([$attribute]);
     $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', 'getAdapter'], [], '', 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));
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $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('fetchPairs')->will($this->returnValue($entityAttributes));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['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();
 }
Пример #17
0
 /**
  * @param \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\DB\Adapter\Pdo\Mysql $adapter
  * @depends testSetAddOrder
  */
 public function testUnshiftOrder($adapter)
 {
     $renderer = $this->getSelectRenderer($this->objectManager);
     $select = new \Magento\Framework\DB\Select($adapter, $renderer);
     $adapter->expects($this->any())->method('select')->willReturn($select);
     $this->collection->setConnection($adapter);
     $this->collection->addOrder('some_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     $this->collection->unshiftOrder('other_field', \Magento\Framework\Data\Collection::SORT_ORDER_ASC);
     $this->collection->load();
     $selectOrders = $this->collection->getSelect()->getPart(\Magento\Framework\DB\Select::ORDER);
     $this->assertEquals('other_field ASC', (string) array_shift($selectOrders));
     $this->assertEquals('some_field ASC', (string) array_shift($selectOrders));
     $this->assertEmpty(array_shift($selectOrders));
 }
Пример #18
0
 public function setUp()
 {
     $this->addressMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address', ['__wakeup', 'getOrderId', 'hasDataChanges'], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['describeTable', 'insert', 'lastInsertId'], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Address\\Validator', [], [], '', false);
     $this->gridPoolMock = $this->getMock('Magento\\Sales\\Model\\Resource\\GridPool', ['refreshByOrderId'], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->addressResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Address', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock, 'gridPool' => $this->gridPoolMock]);
 }
Пример #19
0
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->commentModelMock = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Comment', [], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo\\Comment\\Validator', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->commentModelMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->commentModelMock->expects($this->any())->method('isSaveAllowed')->will($this->returnValue(true));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->commentResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Creditmemo\\Comment', ['resource' => $this->appResourceMock, 'validator' => $this->validatorMock]);
 }
Пример #20
0
 /**
  * Init
  */
 public function setUp()
 {
     $this->addressMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Address', ['__wakeup', 'getOrderId', 'hasDataChanges', 'beforeSave', 'afterSave', 'validateBeforeSave', 'getOrder'], [], '', false);
     $this->quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', ['__wakeup', 'getId'], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->entitySnapshotMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\VersionControl\\Snapshot', [], [], '', false);
     $this->relationCompositeMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\VersionControl\\RelationComposite', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->addressResource = $objectManager->getObject('Magento\\Quote\\Model\\Resource\\Quote\\Address', ['resource' => $this->appResourceMock, 'entitySnapshot' => $this->entitySnapshotMock, 'entityRelationComposite' => $this->relationCompositeMock]);
 }
Пример #21
0
 public function testSave()
 {
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
     $this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
     $this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
     $this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
     $this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
     $this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
     $this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
     $this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
     $this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
     $this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
     $this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
     $this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
     $this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
     $this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Пример #22
0
 public function testRemove()
 {
     $triggerMock = $this->getMock('Magento\\Framework\\DB\\Ddl\\Trigger', [], [], '', false, false);
     $triggerMock->expects($this->exactly(3))->method('setName')->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(3))->method('addStatement')->will($this->returnSelf());
     $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));
     $triggerMock->expects($this->exactly(3))->method('getStatements')->will($this->returnValue(true));
     $this->connectionMock->expects($this->exactly(3))->method('createTrigger')->with($triggerMock);
     $this->model->remove();
 }
Пример #23
0
 /**
  * Test for method prepareAttributesWithDefaultValueForSave
  */
 public function testPrepareAttributesWithDefaultValueForSave()
 {
     $rowData = ['_attribute_set' => 'Default', 'sku' => 'downloadablesku1', 'product_type' => 'downloadable', 'name' => 'Downloadable Product 1', 'downloadable_samples' => 'group_title=Group Title Samples, title=Title 1, file=media/file.mp4,sortorder=1' . '|group_title=Group Title, title=Title 2, url=media/file2.mp4,sortorder=0', 'downloadable_links' => 'group_title=Group Title Links, title=Title 1, price=10, downloads=unlimited,' . ' file=media/file_link.mp4,sortorder=1|group_title=Group Title, title=Title 2, price=10, downloads' . '=unlimited, url=media/file2.mp4,sortorder=0'];
     $this->connectionMock->expects($this->any())->method('fetchAll')->with($this->select)->willReturnOnConsecutiveCalls([['attribute_set_name' => '1', 'attribute_id' => '1'], ['attribute_set_name' => '2', 'attribute_id' => '2']]);
     $this->downloadableModelMock = $this->objectManagerHelper->getObject('\\Magento\\DownloadableImportExport\\Model\\Import\\Product\\Type\\Downloadable', ['attrSetColFac' => $this->attrSetColFacMock, 'prodAttrColFac' => $this->prodAttrColFacMock, 'resource' => $this->resourceMock, 'params' => $this->paramsArray, 'uploaderHelper' => $this->uploaderHelper, 'downloadableHelper' => $this->downloadableHelper]);
     $this->setPropertyValue($this->downloadableModelMock, '_attributes', ['Default' => ['name' => ['id' => '69', 'code' => 'name', 'is_global' => '0', 'is_required' => '1', 'is_unique' => '0', 'frontend_label' => 'Name', 'is_static' => false, 'apply_to' => [], 'type' => 'varchar', 'default_value' => null, 'options' => []], 'sku' => ['id' => '70', 'code' => 'sku', 'is_global' => '1', 'is_required' => '1', 'is_unique' => '1', 'frontend_label' => 'SKU', 'is_static' => true, 'apply_to' => [], 'type' => 'varchar', 'default_value' => null, 'options' => []]]]);
     $this->downloadableModelMock->prepareAttributesWithDefaultValueForSave($rowData);
 }
Пример #24
0
 public function setUp()
 {
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History\\Validator', [], [], '', false);
     $this->entitySnapshotMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\VersionControl\\Snapshot', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $relationProcessorMock = $this->getMock('\\Magento\\Framework\\Model\\Resource\\Db\\ObjectRelationProcessor', [], [], '', false);
     $contextMock = $this->getMock('\\Magento\\Framework\\Model\\Resource\\Db\\Context', [], [], '', false);
     $contextMock->expects($this->once())->method('getResources')->willReturn($this->appResourceMock);
     $contextMock->expects($this->once())->method('getObjectRelationProcessor')->willReturn($relationProcessorMock);
     $this->historyResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Status\\History', ['context' => $contextMock, 'validator' => $this->validatorMock, 'entitySnapshot' => $this->entitySnapshotMock]);
 }
Пример #25
0
 public function setUp()
 {
     $this->object = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['getOldSku', '_populateToUrlGeneration'], [], '', false);
     $this->adapter->expects($this->any())->method('_populateToUrlGeneration')->willReturn($this->object);
     $this->adapter->expects($this->any())->method('getOldSku')->willReturn(['sku' => ['sku' => 'sku', 'url_key' => 'value1', 'entity_id' => '1'], 'sku2' => ['sku' => 'sku2', 'url_key' => 'value2', 'entity_id' => '2']]);
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->adapter);
     $this->event->expects($this->any())->method('getBunch')->willReturn([['sku' => 'sku', 'url_key' => 'value1'], ['sku' => 'sku3', 'url_key' => 'value3']]);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->productUrlRewriteGenerator = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlRewriteGenerator')->disableOriginalConstructor()->setMethods(['generate'])->getMock();
     $this->productRepository = $this->getMockBuilder('\\Magento\\Catalog\\Api\\ProductRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->import = $this->objectManagerHelper->getObject('\\Magento\\CatalogUrlRewrite\\Model\\Product\\Plugin\\Import', ['urlPersist' => $this->urlPersist, 'productUrlRewriteGenerator' => $this->productUrlRewriteGenerator, 'productRepository' => $this->productRepository]);
 }
Пример #26
0
 /**
  * Test deleting changelog table
  */
 public function testDeleteCl()
 {
     $this->_changelogMock->expects($this->any())->method('getName')->will($this->returnValue('catalog_product_flat_cl'));
     $this->_connectionMock->expects($this->once())->method('getTables')->with('catalog_product_flat_%')->will($this->returnValue(['catalog_product_flat_cl']));
     $this->_connectionMock->expects($this->never())->method('dropTable');
     $this->_resourceMock->expects($this->once())->method('getConnection')->with('write')->will($this->returnValue($this->_connectionMock));
     $this->_setStoreManagerExpectedStores([1]);
     $this->_model->deleteAbandonedStoreFlatTables();
 }
Пример #27
0
 /**
  * Set up
  */
 protected function setUp()
 {
     $this->trackModelMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment\\Track', [], [], '', false);
     $this->appResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->validatorMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment\\Track\\Validator', [], [], '', false);
     $this->appResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->adapterMock));
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('insert');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->trackModelMock->expects($this->any())->method('hasDataChanges')->will($this->returnValue(true));
     $this->trackModelMock->expects($this->any())->method('isSaveAllowed')->will($this->returnValue(true));
     $relationProcessorMock = $this->getMock('\\Magento\\Framework\\Model\\Resource\\Db\\ObjectRelationProcessor', [], [], '', false);
     $contextMock = $this->getMock('\\Magento\\Framework\\Model\\Resource\\Db\\Context', [], [], '', false);
     $contextMock->expects($this->once())->method('getResources')->willReturn($this->appResourceMock);
     $contextMock->expects($this->once())->method('getObjectRelationProcessor')->willReturn($relationProcessorMock);
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->trackResource = $objectManager->getObject('Magento\\Sales\\Model\\Resource\\Order\\Shipment\\Track', ['context' => $contextMock, 'validator' => $this->validatorMock]);
 }
 public function testSetMainTableNoSelect()
 {
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue(null));
     $this->uut = $this->getUut();
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnValue(self::TABLE_NAME));
     $this->uut->setMainTable('');
     $this->selectMock->expects($this->never())->method('getPart');
     $this->assertTrue($this->uut->setMainTable('') instanceof Uut);
     $this->assertEquals(self::TABLE_NAME, $this->uut->getMainTable());
 }
Пример #29
0
 public function testSave()
 {
     $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
     $this->adapterMock->expects($this->any())->method('quoteInto');
     $this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
     $this->adapterMock->expects($this->any())->method('update');
     $this->adapterMock->expects($this->any())->method('lastInsertId');
     $this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->orderMock->expects($this->once())->method('hasDataChanges')->will($this->returnValue(true));
     $this->resource->save($this->orderMock);
 }
Пример #30
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]);
 }