Beispiel #1
0
 /**
  * Run test getAllIds method
  *
  * @return void
  */
 public function testGetAllIds()
 {
     $adapterMock = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false, true, true, ['fetchCol']);
     $this->resourceMock->expects($this->once())->method('getIdFieldName')->will($this->returnValue('return-value'));
     $this->selectMock->expects($this->once())->method('getAdapter')->will($this->returnValue($adapterMock));
     $adapterMock->expects($this->once())->method('fetchCol')->will($this->returnValue('fetch-result'));
     $this->assertEquals('fetch-result', $this->query->getAllIds());
 }
Beispiel #2
0
 /**
  * @expectedException \Exception
  */
 public function testDeleteRaiseException()
 {
     $this->actionValidatorMock->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $this->adapterMock->expects($this->once())->method('beginTransaction');
     $this->resourceMock->expects($this->once())->method('delete')->will($this->throwException(new \Exception()));
     $this->resourceMock->expects($this->never())->method('commit');
     $this->resourceMock->expects($this->once())->method('rollBack');
     $this->model->delete();
 }
Beispiel #3
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]);
 }
 protected function setUp()
 {
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->select = $this->getMock('Zend_Db_Select', ['from', 'where'], [], '', false);
     $this->adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'prepareSqlCondition', 'quoteIdentifier'], [], '', false);
     $this->resource = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getReadConnection', '__wakeup', 'getMainTable', 'getTable']);
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->adapter->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->adapter->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->resource->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->adapter));
     $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\\Resource\\UrlRewriteCollection', ['storeManager' => $this->storeManager, 'resource' => $this->resource]);
 }
Beispiel #5
0
 /**
  * @param mixed $ignoreData
  * @param 'string' $ignoreSql
  * @dataProvider ignoresDataProvider
  * @return void
  */
 public function testAddStoreFilter($ignoreData, $ignoreSql)
 {
     $typeId = 1;
     $subjectId = 2;
     $subtype = 3;
     $limit = 0;
     $stores = [1, 2];
     $this->resourceMock->expects($this->once())->method('getCurrentStoreIds')->willReturn($stores);
     $this->selectMock->expects($this->at(0))->method('where')->with('event_type_id = ?', $typeId);
     $this->selectMock->expects($this->at(1))->method('where')->with('subject_id = ?', $subjectId);
     $this->selectMock->expects($this->at(2))->method('where')->with('subtype = ?', $subtype);
     $this->selectMock->expects($this->at(3))->method('where')->with('store_id IN(?)', $stores);
     $this->selectMock->expects($this->at(4))->method('where')->with($ignoreSql, $ignoreData);
     $this->collection->addRecentlyFiler($typeId, $subjectId, $subtype, $ignoreData, $limit);
 }
Beispiel #6
0
 protected function setUp()
 {
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false);
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->resourceMock = $this->getMockBuilder('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb')->setMethods(['getReadConnection', 'getMainTable', 'getTable'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->adapterMock = $this->getMock('Zend_Db_Adapter_Pdo_Mysql', ['select', 'query'], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from'], ['adapter' => $this->adapterMock]);
     $this->adapterMock->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock->expects($this->once())->method('getReadConnection')->will($this->returnValue($this->adapterMock));
     $this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('main_table_name');
     $this->resourceMock->expects($this->once())->method('getTable')->will($this->returnArgument(0));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->collection = $objectManager->getObject('Magento\\Review\\Model\\Resource\\Review\\Summary\\Collection', ['entityFactory' => $this->entityFactoryMock, 'logger' => $this->loggerMock, 'fetchStrategy' => $this->fetchStrategyMock, 'resource' => $this->resourceMock]);
 }
Beispiel #7
0
 public function testGetFields()
 {
     $entityTable = 'entity_table';
     $expectedDescribedTable = ['field1' => null, 'field2' => null];
     $expectedAttributes = ['attribute1' => 'value1', 'attribute2' => 'value2'];
     $expectedResults = array_merge($expectedDescribedTable, $expectedAttributes);
     $this->resource->expects($this->any())->method('getEntityTable')->willReturn($entityTable);
     $this->connection->expects($this->once())->method('describeTable')->with($entityTable)->willReturn($expectedDescribedTable);
     $this->model->expects($this->any())->method('getAttributes')->willReturn($expectedAttributes);
     //check that fields load with null initial value
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
     // Testing loading data from cache.
     $this->connection->expects($this->never())->method('describeTable');
     $this->assertEquals(array_fill_keys(array_keys($expectedResults), null), $this->metadata->getFields($this->model));
 }
Beispiel #8
0
 public function testPrepareDataForUpdate()
 {
     $adapterInterfaceMock = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $context = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject('Magento\\Framework\\Model\\Context');
     $registryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false);
     $resourceMock = $this->getMock('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', ['_construct', '_getReadAdapter', '_getWriteAdapter', '__wakeup', 'getIdFieldName'], [], '', false);
     $adapterMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $resourceMock->expects($this->any())->method('_getWriteAdapter')->will($this->returnValue($adapterMock));
     $resourceCollectionMock = $this->getMockBuilder('Magento\\Framework\\Data\\Collection\\AbstractDb')->disableOriginalConstructor()->getMockForAbstractClass();
     $abstractModelMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\AbstractModel', [$context, $registryMock, $resourceMock, $resourceCollectionMock]);
     $data = 'tableName';
     $this->_resourcesMock->expects($this->any())->method('getConnection')->will($this->returnValue($adapterInterfaceMock));
     $this->_resourcesMock->expects($this->any())->method('getTableName')->with($data)->will($this->returnValue('tableName'));
     $this->_resourcesMock->expects($this->any())->method('_getWriteAdapter')->will($this->returnValue($adapterInterfaceMock));
     $mainTableReflection = new \ReflectionProperty('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', '_mainTable');
     $mainTableReflection->setAccessible(true);
     $mainTableReflection->setValue($this->_model, 'tableName');
     $idFieldNameReflection = new \ReflectionProperty('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', '_idFieldName');
     $idFieldNameReflection->setAccessible(true);
     $idFieldNameReflection->setValue($this->_model, 'idFieldName');
     $adapterInterfaceMock->expects($this->any())->method('save')->with('tableName', 'idFieldName');
     $adapterInterfaceMock->expects($this->any())->method('quoteInto')->will($this->returnValue('idFieldName'));
     $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'];
     $this->_model->expects($this->once())->method('_prepareDataForTable')->will($this->returnValue($newData));
     $abstractModelMock->addData($newData);
     $this->assertNotEquals($abstractModelMock->getData(), $abstractModelMock->getStoredData());
     $abstractModelMock->isObjectNew(false);
     $adapterInterfaceMock->expects($this->once())->method('update')->with('tableName', $newData, 'idFieldName');
     $this->_model->save($abstractModelMock);
 }
Beispiel #9
0
 /**
  * @param int $isFilter
  * @param string $useAggregatedData
  * @param string $mainTable
  * @dataProvider salesDataProvider
  * @return void
  */
 public function testCalculateSales($isFilter, $useAggregatedData, $mainTable)
 {
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with('sales/dashboard/use_aggregated_data', \Magento\Store\Model\ScopeInterface::SCOPE_STORE)->willReturn($useAggregatedData);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeMock);
     $this->resourceMock->expects($this->at(0))->method('getTable')->with($mainTable);
     $this->collection->calculateSales($isFilter);
 }
 protected function _prepareAddFilterStubs()
 {
     $entityInfo = [];
     $entityInfo['entity_id_field'] = 'entity_id';
     $entityInfo['rule_id_field'] = 'rule_id';
     $entityInfo['associations_table'] = 'assoc_table';
     $connection = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $select = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false);
     $collectionSelect = $this->getMock('\\Magento\\Framework\\DB\\Select', [], [], '', false);
     $connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $collectionSelect->expects($this->once())->method('exists');
     $this->abstractCollection->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $this->_db->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->abstractCollection->expects($this->any())->method('getSelect')->will($this->returnValue($collectionSelect));
     $this->abstractCollection->expects($this->any())->method('_getAssociatedEntityInfo')->will($this->returnValue($entityInfo));
 }
Beispiel #11
0
 public function setUp()
 {
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->historyItemMock = $this->getMock('Magento\\Sales\\Model\\Order\\Status\\History', ['__wakeup', 'addData'], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['getReadConnection', 'getMainTable', 'getTable', '__wakeup']);
     $this->fetchStrategyMock = $this->getMockForAbstractClass('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategyInterface');
     $this->entityFactoryMock = $this->getMock('Magento\\Core\\Model\\EntityFactory', [], [], '', false);
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->atLeastOnce())->method('select')->will($this->returnValue($this->selectMock));
     $data = [['data']];
     $this->historyItemMock->expects($this->once())->method('addData')->with($this->equalTo($data[0]))->will($this->returnValue($this->historyItemMock));
     $this->fetchStrategyMock->expects($this->once())->method('fetchAll')->will($this->returnValue($data));
     $this->entityFactoryMock->expects($this->once())->method('create')->will($this->returnValue($this->historyItemMock));
     $logger = $this->getMock('Magento\\Framework\\Logger', [], [], '', false);
     $this->collection = new \Magento\Sales\Model\Resource\Order\Status\History\Collection($this->entityFactoryMock, $logger, $this->fetchStrategyMock, $this->eventManagerMock, $this->connectionMock, $this->resourceMock);
 }
 protected function setUp()
 {
     $this->entityFactoryMock = $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->coreResourceMock = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['__wakeup', 'getReadConnection', 'getMainTable', 'getTable']);
     $this->selectMock = $this->getMock('Zend_Db_Select', [], [], '', false);
     $this->coreResourceMock->expects($this->any())->method('getConnection')->will($this->returnValue($this->connectionMock));
     $this->coreResourceMock->expects($this->any())->method('getTableName')->with('eav_attribute_option_value')->will($this->returnValue(null));
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getMainTable')->will($this->returnValue('eav_attribute_option'));
     $this->resourceMock->expects($this->any())->method('getTable')->with('eav_attribute_option')->will($this->returnValue('eav_attribute_option'));
     $this->model = new \Magento\Eav\Model\Resource\Entity\Attribute\Option\Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->coreResourceMock, $this->storeManagerMock, null, $this->resourceMock);
 }
Beispiel #13
0
 protected function setUp()
 {
     $this->entityFactoryMock = $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');
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->entityTypeMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', ['__wakeup'], [], '', false);
     $this->entityTypeMock->setAdditionalAttributeTable('some_extra_table');
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->will($this->returnValue($this->entityTypeMock));
     $this->storeManagerMock = $this->getMock('Magento\\Framework\\Store\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnSelf());
     $adapter = $this->getMockForAbstractClass('Zend_Db_Adapter_Abstract', [], '', false);
     $this->selectMock = $this->getMock('Zend_Db_Select', null, [$adapter]);
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'describeTable', 'quoteIdentifier', '_connect', '_quote'], [], '', false);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Resource\\Db\\AbstractDb', [], '', false, true, true, ['__wakeup', 'getReadConnection', 'getMainTable', 'getTable']);
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
     $this->connectionMock->expects($this->any())->method('quoteIdentifier')->will($this->returnArgument(0));
     $this->connectionMock->expects($this->any())->method('describeTable')->will($this->returnvalueMap([['some_main_table', null, ['col1' => [], 'col2' => []]], ['some_extra_table', null, ['col2' => [], 'col3' => []]], [null, null, ['col2' => [], 'col3' => [], 'col4' => []]]]));
     $this->connectionMock->expects($this->any())->method('_quote')->will($this->returnArgument(0));
     $this->resourceMock->expects($this->any())->method('getReadConnection')->will($this->returnValue($this->connectionMock));
     $this->resourceMock->expects($this->any())->method('getMainTable')->will($this->returnValue('some_main_table'));
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnValue('some_extra_table'));
 }
Beispiel #14
0
 public function testDelete()
 {
     $this->resourceMock->expects($this->once())->method('delete')->with($this->model);
     $this->model->delete();
 }
 public function testGetTable()
 {
     $this->resourceMock->expects($this->any())->method('getTable')->will($this->returnValue(self::TABLE_NAME));
     $this->assertEquals(self::TABLE_NAME, $this->uut->getTable(''));
 }