public function testRefreshSpecialPrices()
 {
     $idsToProcess = [1, 2, 3];
     $this->metadataPool->expects($this->atLeastOnce())->method('getMetadata')->willReturn($this->metadataMock);
     $this->metadataMock->expects($this->atLeastOnce())->method('getLinkField')->willReturn('row_id');
     $this->metadataMock->expects($this->atLeastOnce())->method('getIdentifierField')->willReturn('entity_id');
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $selectMock->expects($this->any())->method('from')->will($this->returnSelf());
     $selectMock->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $selectMock->expects($this->any())->method('where')->will($this->returnSelf());
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], [], '', false);
     $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
     $connectionMock->expects($this->any())->method('fetchCol')->will($this->returnValue($idsToProcess));
     $this->_resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->_resourceMock->expects($this->any())->method('getTableName')->will($this->returnValue('category'));
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', [], [], '', false);
     $storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->_storeManagerMock->expects($this->once())->method('getStores')->with(true)->will($this->returnValue([$storeMock]));
     $this->_localeDateMock->expects($this->once())->method('scopeTimeStamp')->with($storeMock)->will($this->returnValue(32000));
     $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', [], [], '', false);
     $indexerMock->expects($this->exactly(2))->method('reindexList');
     $this->_priceProcessorMock->expects($this->exactly(2))->method('getIndexer')->will($this->returnValue($indexerMock));
     $attributeMock = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], '', false, true, true, ['__wakeup', 'getAttributeId']);
     $attributeMock->expects($this->any())->method('getAttributeId')->will($this->returnValue(1));
     $this->_eavConfigMock->expects($this->any())->method('getAttribute')->will($this->returnValue($attributeMock));
     $this->_model->execute();
 }
Ejemplo n.º 2
0
 public function testExecute()
 {
     $entityId = 1;
     $linkId = 2;
     $oldStore = 1;
     $newStore = 2;
     $linkField = 'link_id';
     $adapter = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMockForAbstractClass();
     $whereForDelete = [$linkField . ' = ?' => $linkId, 'store_id IN (?)' => [$oldStore]];
     $adapter->expects($this->once())->method('delete')->with('cms_page_store', $whereForDelete)->willReturnSelf();
     $whereForInsert = [$linkField => $linkId, 'store_id' => $newStore];
     $adapter->expects($this->once())->method('insertMultiple')->with('cms_page_store', [$whereForInsert])->willReturnSelf();
     $entityMetadata = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->once())->method('getEntityConnection')->willReturn($adapter);
     $entityMetadata->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $this->metadataPool->expects($this->once())->method('getMetadata')->with(PageInterface::class)->willReturn($entityMetadata);
     $this->resourcePage->expects($this->once())->method('lookupStoreIds')->willReturn([$oldStore]);
     $this->resourcePage->expects($this->once())->method('getTable')->with('cms_page_store')->willReturn('cms_page_store');
     $page = $this->getMockBuilder('Magento\\Cms\\Model\\Page')->disableOriginalConstructor()->setMethods(['getStores', 'getStoreId', 'getId', 'getData'])->getMock();
     $page->expects($this->once())->method('getStores')->willReturn(null);
     $page->expects($this->once())->method('getStoreId')->willReturn($newStore);
     $page->expects($this->once())->method('getId')->willReturn($entityId);
     $page->expects($this->exactly(2))->method('getData')->with($linkField)->willReturn($linkId);
     $result = $this->model->execute($page);
     $this->assertInstanceOf(PageInterface::class, $result);
 }
Ejemplo n.º 3
0
 public function testAddProductNameFilter()
 {
     $entityMetadata = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadata->expects($this->once())->method('getLinkField')->willReturn('entity_id');
     $this->metadataPool->expects($this->once())->method('getMetadata')->with(ProductInterface::class)->willReturn($entityMetadata);
     $collection = $this->collection->addProductNameFilter('TestProductName');
     $sql = $collection->getSelect()->__toString();
     $sql = trim(preg_replace('/\\s+/', ' ', $sql));
     $this->assertEquals(trim(preg_replace('/\\s+/', ' ', $this->sql)), $sql);
 }
Ejemplo n.º 4
0
 protected function setUp()
 {
     $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false, false, true, []);
     $metadata = $this->getMock('Magento\\Framework\\EntityManager\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $metadata->expects($this->any())->method('getEntityTable')->willReturn('entity_table');
     $metadata->expects($this->any())->method('getEntityConnection')->willReturn($this->connection);
     $this->metadataPool = $this->getMock('Magento\\Framework\\EntityManager\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($metadata);
     $this->subject = new \Magento\Framework\Model\ResourceModel\Db\DeleteEntityRow($this->metadataPool);
 }
Ejemplo n.º 5
0
 public function testExecuteWithString()
 {
     $customers = '1,2';
     $websites = '3,4,5';
     $entityData = ['row_id' => 1, 'rule_id' => 1, 'website_ids' => $websites, 'customer_group_ids' => $customers];
     $className = '\\Magento\\Framework\\EntityManager\\EntityMetadata';
     $metadata = $this->getMock($className, [], [], '', false);
     $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id');
     $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata);
     $this->ruleResource->expects($this->any())->method('bindRuleToEntity')->withConsecutive([1, [3, 4, 5]], [1, [1, 2]]);
     $result = $this->model->execute(RuleInterface::class, $entityData);
     $this->assertEquals($entityData, $result);
 }
Ejemplo n.º 6
0
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->resource = $this->getMockBuilder('Magento\\Framework\\App\\ResourceConnection')->disableOriginalConstructor()->getMock();
     $this->connectionMock = $this->getMockBuilder('Magento\\Framework\\DB\\Adapter\\AdapterInterface')->setMethods(['select', 'fetchOne'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->select = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->setMethods(['reset', 'from', 'join', 'where', 'group', 'limit'])->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock->expects(self::once())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->getMetaDataMock());
     $this->model = $helper->getObject(LockValidator::class, ['resource' => $this->resource]);
     $refClass = new \ReflectionClass(LockValidator::class);
     $refProperty = $refClass->getProperty('metadataPool');
     $refProperty->setAccessible(true);
     $refProperty->setValue($this->model, $this->metadataPoolMock);
 }
Ejemplo n.º 7
0
 /**
  * test Execute
  */
 public function testExecute()
 {
     $entityData = ['row_id' => 2, 'rule_id' => 1];
     $customers = [1, 2];
     $websites = [3, 4, 5];
     $className = '\\Magento\\Framework\\EntityManager\\EntityMetadata';
     $metadata = $this->getMock($className, [], [], '', false);
     $metadata->expects($this->once())->method('getLinkField')->willReturn('rule_id');
     $this->metadataPool->expects($this->once())->method('getMetadata')->willReturn($metadata);
     $this->ruleResource->expects($this->once())->method('getCustomerGroupIds')->willReturn($customers);
     $this->ruleResource->expects($this->once())->method('getWebsiteIds')->willReturn($websites);
     $result = $this->model->execute(RuleInterface::class, $entityData);
     $expected = ['row_id' => 2, 'rule_id' => 1, 'customer_group_ids' => [1, 2], 'website_ids' => [3, 4, 5]];
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 8
0
 public function testExecute()
 {
     $data = ['test_link_field' => 1, 'identified_field' => 'test_identified_field', 'test_simple' => 'test_value'];
     $columns = ['test_nullable' => ['NULLABLE' => true, 'DEFAULT' => false, 'IDENTITY' => false, 'COLUMN_NAME' => 'test_nullable'], 'test_simple' => ['NULLABLE' => true, 'DEFAULT' => false, 'IDENTITY' => false, 'COLUMN_NAME' => 'test_simple']];
     $preparedColumns = ['test_identified_field' => null, 'test_nullable' => null, 'test_simple' => 'test_value'];
     $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with('test')->willReturn($this->metadataMock);
     $this->resourceConnectionMock->expects($this->once())->method('getConnectionByName')->willReturn($this->connectionMock);
     $this->metadataMock->expects($this->once())->method('getEntityConnectionName')->willReturn('test_connection_name');
     $this->metadataMock->expects($this->exactly(2))->method('getEntityTable')->willReturn('test_entity_table');
     $this->connectionMock->expects($this->once())->method('update')->with('test_entity_table', $preparedColumns, ['test_link_field' . ' = ?' => $data['test_link_field']]);
     $this->metadataMock->expects($this->exactly(2))->method('getLinkField')->willReturn('test_link_field');
     $this->connectionMock->expects($this->once())->method('describeTable')->willReturn($columns);
     $this->metadataMock->expects($this->exactly(2))->method('getIdentifierField')->willReturn('test_identified_field');
     $this->assertSame($data, $this->model->execute('test', $data));
 }
Ejemplo n.º 9
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $fileStorageDbMock = $this->getMock('Magento\\MediaStorage\\Helper\\File\\Storage\\Database', [], [], '', false);
     $filesystem = $this->getMockBuilder('Magento\\Framework\\Filesystem')->disableOriginalConstructor()->getMock();
     $coreRegistry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false);
     $logger = $this->getMockBuilder('\\Psr\\Log\\LoggerInterface')->disableOriginalConstructor()->setMethods([])->getMockForAbstractClass();
     $this->_typeConfigurableFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\ConfigurableFactory', ['create', 'saveProducts'], [], '', false);
     $this->_configurableAttributeFactoryMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable\\AttributeFactory', ['create'], [], '', false);
     $this->_productCollectionFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->_attributeCollectionFactory = $this->getMock('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->productRepository = $this->getMock('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $this->extensionAttributesJoinProcessorMock = $this->getMock('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface', [], [], '', false);
     $this->entityMetadata = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
     $this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->entityMetadata);
     $this->cache = $this->getMockBuilder(\Magento\Framework\Cache\FrontendInterface::class)->getMockForAbstractClass();
     $this->catalogConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $this->_model = $this->_objectHelper->getObject(Configurable::class, ['typeConfigurableFactory' => $this->_typeConfigurableFactory, 'configurableAttributeFactory' => $this->_configurableAttributeFactoryMock, 'productCollectionFactory' => $this->_productCollectionFactory, 'attributeCollectionFactory' => $this->_attributeCollectionFactory, 'eventManager' => $eventManager, 'fileStorageDb' => $fileStorageDbMock, 'filesystem' => $filesystem, 'coreRegistry' => $coreRegistry, 'logger' => $logger, 'productRepository' => $this->productRepository, 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock, 'customerSession' => $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(), 'cache' => $this->cache, 'catalogConfig' => $this->catalogConfig]);
     $refClass = new \ReflectionClass(Configurable::class);
     $refProperty = $refClass->getProperty('metadataPool');
     $refProperty->setAccessible(true);
     $refProperty->setValue($this->_model, $this->metadataPool);
 }
Ejemplo n.º 10
0
 protected function setUp()
 {
     $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)->getMock();
     $this->resource = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->relation = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product\Relation::class, [], [], '', false);
     $this->metadataMock = $this->getMock(\Magento\Framework\EntityManager\EntityMetadata::class, [], [], '', false);
     $this->metadataPoolMock = $this->getMock(\Magento\Framework\EntityManager\MetadataPool::class, [], [], '', false);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(ProductInterface::class)->willReturn($this->metadataMock);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->configurable = $this->objectManagerHelper->getObject(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class, ['resource' => $this->resource, 'catalogProductRelation' => $this->relation]);
     $reflection = new \ReflectionClass(\Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable::class);
     $reflectionProperty = $reflection->getProperty('metadataPool');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->configurable, $this->metadataPoolMock);
 }
Ejemplo n.º 11
0
 protected function setUp()
 {
     $this->categoryFactoryMock = $this->getMock('\\Magento\\Catalog\\Model\\CategoryFactory', ['create'], [], '', false);
     $this->categoryResourceMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category', [], [], '', false);
     $this->storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods(['getId'])->getMockForAbstractClass();
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->extensibleDataObjectConverterMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\ExtensibleDataObjectConverter')->setMethods(['toNestedArray'])->disableOriginalConstructor()->getMock();
     $metadataMock = $this->getMock('Magento\\Framework\\EntityManager\\EntityMetadata', [], [], '', false);
     $metadataMock->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\EntityManager\\MetadataPool', [], [], '', false);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\CategoryInterface::class)->willReturn($metadataMock);
     $this->model = new \Magento\Catalog\Model\CategoryRepository($this->categoryFactoryMock, $this->categoryResourceMock, $this->storeManagerMock);
     $this->setProperties($this->model, ['metadataPool' => $this->metadataPoolMock]);
     // Todo: \Magento\Framework\TestFramework\Unit\Helper\ObjectManager to do this automatically (MAGETWO-49793)
     $reflection = new \ReflectionClass(get_class($this->model));
     $reflectionProperty = $reflection->getProperty('extensibleDataObjectConverter');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->model, $this->extensibleDataObjectConverterMock);
 }
Ejemplo n.º 12
0
 /**
  * @param \Magento\Framework\DataObject $item
  * @param array $storesData
  * @dataProvider getItemsDataProvider
  * @throws \Exception
  */
 public function testAfterLoad($item, $storesData)
 {
     $linkField = 'row_id';
     $expectedResult = [];
     foreach ($storesData as $storeData) {
         $expectedResult[$storeData[$linkField]][] = $storeData['store_id'];
     }
     $entityMetadataMock = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $entityMetadataMock->expects($this->any())->method('getLinkField')->willReturn($linkField);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($entityMetadataMock);
     $this->select->expects($this->any())->method('from')->willReturnSelf();
     $this->connection->expects($this->any())->method('fetchAll')->willReturn($storesData);
     $storeDataMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->getMockForAbstractClass();
     $storeDataMock->expects($this->any())->method('getId')->willReturn(current($expectedResult[$item->getId()]));
     $storeDataMock->expects($this->any())->method('getCode')->willReturn('some_code');
     $this->storeManagerMock->expects($this->any())->method('getStores')->willReturn([$storeDataMock]);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($storeDataMock);
     $this->collection->addItem($item);
     $this->assertEmpty($item->getStoreId());
     $this->collection->load();
     $this->assertEquals($expectedResult[$item->getId()], $item->getStoreId());
 }
Ejemplo n.º 13
0
 protected function setUp()
 {
     $this->entityFactoryMock = $this->getMock('Magento\\Framework\\Data\\Collection\\EntityFactory', ['create'], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->fetchStrategyMock = $this->getMock('Magento\\Framework\\Data\\Collection\\Db\\FetchStrategy\\Query', ['fetchAll'], [], '', false);
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\Manager', [], [], '', false);
     $this->optionsFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option\\Value\\CollectionFactory', ['create'], [], '', false);
     $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $this->joinProcessor = $this->getMockBuilder('Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface')->disableOriginalConstructor()->getMockForAbstractClass();
     $this->resourceMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Option', ['getConnection', '__wakeup', 'getMainTable', 'getTable'], [], '', false);
     $this->selectMock = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'reset', 'join'], [], '', false);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select'], [], '', false);
     $this->connection->expects($this->once())->method('select')->will($this->returnValue($this->selectMock));
     $this->resourceMock->expects($this->once())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resourceMock->expects($this->once())->method('getMainTable')->will($this->returnValue('test_main_table'));
     $this->resourceMock->expects($this->exactly(3))->method('getTable')->withConsecutive(['test_main_table'], ['catalog_product_entity'], ['catalog_product_entity'])->willReturnOnConsecutiveCalls($this->returnValue('test_main_table'), 'catalog_product_entity', 'catalog_product_entity');
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\EntityManager\\MetadataPool', [], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\EntityManager\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->selectMock->expects($this->exactly(2))->method('join');
     $this->prepareObjectManager([['Magento\\Framework\\EntityManager\\MetadataPool', $this->metadataPoolMock], ['Magento\\Framework\\Api\\ExtensionAttribute\\JoinProcessorInterface', $this->joinProcessor]]);
     $this->collection = new Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->optionsFactoryMock, $this->storeManagerMock, null, $this->resourceMock);
 }
Ejemplo n.º 14
0
 /**
  * Set up test
  *
  * @return void
  */
 protected function setUp()
 {
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\ResourceModel\\Rule\\CollectionFactory', ['create', 'addFieldToFilter'], [], '', false);
     $this->backend = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\Backend\\AbstractBackend', [], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\EntityManager\\MetadataPool', [], [], '', false);
     $metadata = $this->getMockBuilder('Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->db = $this->getMock('Zend_Db_Statement_Interface', [], [], '', false);
     $this->website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->combine = $this->getMock('Magento\\Rule\\Model\\Condition\\Combine', [], [], '', false);
     $this->rules = $this->getMock('Magento\\CatalogRule\\Model\\Rule', [], [], '', false);
     $this->logger = $this->getMock('Psr\\Log\\LoggerInterface', [], [], '', false);
     $this->attribute = $this->getMock('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', [], [], '', false);
     $this->priceCurrency = $this->getMock('Magento\\Framework\\Pricing\\PriceCurrencyInterface');
     $this->dateFormat = $this->getMock('Magento\\Framework\\Stdlib\\DateTime', [], [], '', false);
     $this->dateTime = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\DateTime', [], [], '', false);
     $this->eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', ['getAttribute'], [], '', false);
     $this->product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $this->connection->expects($this->any())->method('query')->will($this->returnValue($this->db));
     $this->select->expects($this->any())->method('distinct')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('order')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $this->storeManager->expects($this->any())->method('getWebsites')->will($this->returnValue([$this->website]));
     $this->storeManager->expects($this->any())->method('getWebsite')->will($this->returnValue($this->website));
     $this->rules->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->rules->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('getCustomerGroupIds')->will($this->returnValue([1]));
     $this->ruleCollectionFactory->expects($this->any())->method('create')->will($this->returnSelf());
     $this->ruleCollectionFactory->expects($this->any())->method('addFieldToFilter')->will($this->returnValue([$this->rules]));
     $this->product->expects($this->any())->method('load')->will($this->returnSelf());
     $this->product->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->product->expects($this->any())->method('getWebsiteIds')->will($this->returnValue([1]));
     $this->rules->expects($this->any())->method('validate')->with($this->product)->willReturn(true);
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->productFactory->expects($this->any())->method('create')->will($this->returnValue($this->product));
     $this->indexBuilder = new \Magento\CatalogRule\Model\Indexer\IndexBuilder($this->ruleCollectionFactory, $this->priceCurrency, $this->resource, $this->storeManager, $this->logger, $this->eavConfig, $this->dateFormat, $this->dateTime, $this->productFactory);
     $this->setProperties($this->indexBuilder, ['metadataPool' => $this->metadataPool]);
 }
Ejemplo n.º 15
0
 public function testAddCollectionData()
 {
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('join')->will($this->returnSelf());
     $select->expects($this->any())->method('joinInner')->will($this->returnSelf());
     $select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $connection->expects($this->any())->method('fetchCol')->will($this->returnValue([]));
     $resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $resource->expects($this->any())->method('getConnection')->will($this->returnValue($connection));
     $resource->expects($this->any())->method('getTableName')->will($this->returnArgument(0));
     $eventManager = $this->getMock('Magento\\Framework\\Event\\ManagerInterface', [], [], '', false);
     $attributeConfig = $this->getMock('Magento\\Catalog\\Model\\Attribute\\Config', [], [], '', false);
     $attributes = ['attribute_one', 'attribute_two'];
     $attributeConfig->expects($this->once())->method('getAttributeNames')->with('catalog_category')->will($this->returnValue($attributes));
     $collection = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false);
     $collection->expects($this->never())->method('getAllIds')->will($this->returnValue([]));
     $collection->expects($this->once())->method('getAllIdsSql')->will($this->returnValue($select));
     $collectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection\\Factory', [], [], '', false);
     $collectionFactory->expects($this->once())->method('create')->will($this->returnValue($collection));
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->any())->method('getId')->will($this->returnValue(1));
     $storeManager = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface');
     $storeManager->expects($this->any())->method('getStore')->will($this->returnValue($store));
     $categoryMetadataMock = $this->getMockBuilder(EntityMetadata::class)->disableOriginalConstructor()->getMock();
     $categoryMetadataMock->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(CategoryInterface::class)->willReturn($categoryMetadataMock);
     $model = $objectHelper->getObject('Magento\\Catalog\\Model\\ResourceModel\\Category\\Tree', ['storeManager' => $storeManager, 'resource' => $resource, 'eventManager' => $eventManager, 'attributeConfig' => $attributeConfig, 'collectionFactory' => $collectionFactory, 'metadataPool' => $this->metadataPoolMock]);
     $nodeMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', ['getId', 'getPath'], [], '', false);
     $nodeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $nodeMock->expects($this->once())->method('getPath')->will($this->returnValue([]));
     $model->addNode($nodeMock);
     $this->assertSame($model, $model->addCollectionData(null, false, [], false, true));
 }
Ejemplo n.º 16
0
 /**
  * @param object $dataObject
  * @param string $interfaceNames
  * @dataProvider resolveDataProvider
  */
 public function testResolve($dataObject, $interfaceName)
 {
     $customerDataObject = $this->objectManager->getObject($dataObject);
     $this->metadataPoolMock->expects($this->any())->method('hasConfiguration')->willReturnMap([[$interfaceName, true]]);
     $this->assertEquals($interfaceName, $this->resolver->resolve($customerDataObject));
 }
Ejemplo n.º 17
0
 /**
  * Init entity adapter model
  */
 protected function setUp()
 {
     parent::setUp();
     $addExpectations = false;
     $deleteBehavior = false;
     $testName = $this->getName(true);
     if ($testName == 'testImportDataAppendBehavior' || $testName == 'testImportDataDeleteBehavior') {
         $addExpectations = true;
         $deleteBehavior = $this->getName() == 'testImportDataDeleteBehavior' ? true : false;
     }
     $doubleOptions = false;
     if ($testName == 'testValidateAmbiguousData with data set "ambiguity_several_db_rows"') {
         $doubleOptions = true;
     }
     $catalogDataMock = $this->getMock(\Magento\Catalog\Helper\Data::class, ['__construct'], [], '', false);
     $scopeConfig = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
     $timezoneInterface = $this->getMock(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
     $date = new \DateTime();
     $timezoneInterface->expects($this->any())->method('date')->willReturn($date);
     $this->metadataPoolMock = $this->getMock(\Magento\Framework\EntityManager\MetadataPool::class, [], [], '', false);
     $entityMetadataMock = $this->getMock(\Magento\Framework\EntityManager\EntityMetadata::class, [], [], '', false);
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($entityMetadataMock);
     $entityMetadataMock->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $modelClassArgs = [$this->getMock(\Magento\ImportExport\Model\ResourceModel\Import\Data::class, [], [], '', false), $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false), $this->getMock(\Magento\ImportExport\Model\ResourceModel\Helper::class, [], [], '', false), $this->getMock(\Magento\Store\Model\StoreManagerInterface::class, [], [], '', false), $this->getMock(\Magento\Catalog\Model\ProductFactory::class, [], [], '', false), $this->getMock(\Magento\Catalog\Model\ResourceModel\Product\Option\CollectionFactory::class, [], [], '', false), $this->getMock(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class, [], [], '', false), $catalogDataMock, $scopeConfig, $timezoneInterface, $this->getMock(\Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface::class, [], [], '', false), $this->_getModelDependencies($addExpectations, $deleteBehavior, $doubleOptions)];
     $modelClassName = \Magento\CatalogImportExport\Model\Import\Product\Option::class;
     $class = new \ReflectionClass($modelClassName);
     $this->model = $class->newInstanceArgs($modelClassArgs);
     // Create model mock with rewritten _getMultiRowFormat method to support test data with the old format.
     $this->modelMock = $this->getMockBuilder($modelClassName)->setConstructorArgs($modelClassArgs)->setMethods(['_getMultiRowFormat'])->getMock();
     $reflection = new \ReflectionClass(\Magento\CatalogImportExport\Model\Import\Product\Option::class);
     $reflectionProperty = $reflection->getProperty('metadataPool');
     $reflectionProperty->setAccessible(true);
     $reflectionProperty->setValue($this->modelMock, $this->metadataPoolMock);
 }
Ejemplo n.º 18
0
 protected function setUp()
 {
     $helper = new ObjectManager($this);
     $this->productRepository = $this->getMockBuilder('Magento\\Catalog\\Model\\ProductRepository')->setMethods(['get'])->disableOriginalConstructor()->getMock();
     $this->productType = $this->getMockBuilder('Magento\\Bundle\\Model\\Product\\Type\\Interceptor')->setMethods(['getOptionsCollection', 'setStoreFilter', 'getSelectionsCollection', 'getOptionsIds'])->disableOriginalConstructor()->getMock();
     $this->option = $this->getMockBuilder('Magento\\Bundle\\Model\\Option')->setMethods(['getSelections', 'getOptionId', '__wakeup'])->disableOriginalConstructor()->getMock();
     $this->optionCollection = $this->getMockBuilder('Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection')->setMethods(['appendSelections'])->disableOriginalConstructor()->getMock();
     $this->selectionCollection = $this->getMockBuilder('Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection')->disableOriginalConstructor()->getMock();
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getTypeInstance', 'getStoreId', 'getTypeId', '__wakeup', 'getId', 'getData'])->disableOriginalConstructor()->getMock();
     $this->link = $this->getMockBuilder('\\Magento\\Bundle\\Api\\Data\\LinkInterface')->disableOriginalConstructor()->getMock();
     $this->linkFactory = $this->getMockBuilder('\\Magento\\Bundle\\Api\\Data\\LinkInterfaceFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $this->bundleSelectionMock = $this->getMock('\\Magento\\Bundle\\Model\\SelectionFactory', ['create'], [], '', false);
     $this->bundleFactoryMock = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\BundleFactory', ['create'], [], '', false);
     $this->optionCollectionFactoryMock = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\CollectionFactory', ['create'], [], '', false);
     $this->storeManagerMock = $this->getMock('\\Magento\\Store\\Model\\StoreManagerInterface', [], [], '', false);
     $this->metadataPoolMock = $this->getMockBuilder('\\Magento\\Framework\\EntityManager\\MetadataPool')->disableOriginalConstructor()->getMock();
     $this->metadataMock = $this->getMockBuilder('\\Magento\\Framework\\EntityManager\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($this->metadataMock);
     $this->dataObjectHelperMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\DataObjectHelper')->disableOriginalConstructor()->getMock();
     $this->model = $helper->getObject(LinkManagement::class, ['productRepository' => $this->productRepository, 'linkFactory' => $this->linkFactory, 'bundleFactory' => $this->bundleFactoryMock, 'bundleSelection' => $this->bundleSelectionMock, 'optionCollection' => $this->optionCollectionFactoryMock, 'storeManager' => $this->storeManagerMock, 'dataObjectHelper' => $this->dataObjectHelperMock]);
     $refClass = new \ReflectionClass(LinkManagement::class);
     $refProperty = $refClass->getProperty('metadataPool');
     $refProperty->setAccessible(true);
     $refProperty->setValue($this->model, $this->metadataPoolMock);
 }