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\\Model\\Entity\\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('Magento\\Cms\\Model\\Page')->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('Magento\\Cms\\Model\\Page', $page);
     $this->assertInstanceOf('Magento\\Cms\\Model\\Page', $result);
 }
 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('Magento\\ConfigurableProduct\\Model\\Attribute\\LockValidator', ['resource' => $this->resource, 'metadataPool' => $this->metadataPoolMock]);
 }
 protected function setUp()
 {
     $this->connection = $this->getMockForAbstractClass('Magento\\Framework\\DB\\Adapter\\AdapterInterface', [], '', false, false, true, []);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\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\\Model\\Entity\\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);
 }
 protected function setUp()
 {
     $connectionMock = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->getMock();
     $this->resource = $this->getMock('Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($connectionMock));
     $this->relation = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Relation', [], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($metadata);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable', ['resource' => $this->resource, 'catalogProductRelation' => $this->relation, 'metadataPool' => $this->metadataPool]);
 }
 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\\Model\\Entity\\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);
 }
 protected function setUp()
 {
     $this->metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $this->metadata->expects($this->any())->method('getIdentifierField')->willReturn('identifier');
     $this->hydrator = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityHydrator', [], [], '', false);
     $this->metadataPool = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->metadataPool->expects($this->any())->method('getHydrator')->with('Test\\Entity\\Type')->willReturn($this->hydrator);
     $this->metadataPool->expects($this->any())->method('getMetadata')->with('Test\\Entity\\Type')->willReturn($this->metadata);
     $this->abstractEntity = $this->getMockForAbstractClass('Magento\\Eav\\Model\\Entity\\AbstractEntity', [], '', false, false, true, []);
     $this->writeOperation = $this->getMockForAbstractClass('Magento\\Framework\\Model\\Operation\\WriteInterface', [], '', false, false, true, []);
     $this->orchestratorPool = $this->getMock('Magento\\Framework\\Model\\OrchestratorPool', [], [], '', false);
     $this->subject = new \Magento\Framework\Model\EntityManager($this->orchestratorPool, $this->metadataPool);
 }
 /**
  * test Execute
  */
 public function testExecute()
 {
     $entityData = ['row_id' => 2, 'rule_id' => 1];
     $customers = [1, 2];
     $websites = [3, 4, 5];
     $className = '\\Magento\\Framework\\Model\\Entity\\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);
 }
 /**
  * @param string $entityType
  * @param array $entity
  * @param string $identifier
  * @param string $linkField
  * @dataProvider executeParameters
  */
 public function testExecute($entityType, $entity, $identifier, $linkField)
 {
     $this->metadataPoolMock->expects($this->once())->method('getMetadata')->with($entityType)->willReturn($this->metadataMock);
     $entityWithMainRead = array_merge($entity, ['main_read' => 'some info']);
     $this->readMainMock->expects($this->once())->method('execute')->with($entityType, $entity, $identifier)->willReturn($entityWithMainRead);
     $this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
     $entityWithExtensionAndRelation = $entityWithMainRead;
     if (isset($entity[$linkField])) {
         $entityWithExtension = array_merge($entityWithMainRead, ['ext' => 'extParameter']);
         $this->readExtensionMock->expects($this->once())->method('execute')->with($entityType, $entityWithMainRead)->willReturn($entityWithExtension);
         $entityWithExtensionAndRelation = array_merge($entityWithExtension, ['relation' => 'some_relation']);
         $this->readRelationMock->expects($this->once())->method('execute')->with($entityType, $entityWithExtension)->willReturn($entityWithExtensionAndRelation);
     }
     $this->assertEquals($entityWithExtensionAndRelation, $this->read->execute($entityType, $entity, $identifier));
 }
 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\Model\Entity\EntityMetadata::class, [], [], '', false);
     $this->metadataPoolMock = $this->getMock(\Magento\Framework\Model\Entity\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);
 }
Beispiel #10
0
 protected function setUp()
 {
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\MetadataPool', [], [], '', false);
     $this->repositoryMock = $this->getMock('\\Magento\\Catalog\\Api\\ProductRepositoryInterface', [], [], '', false);
     $this->productTypeMock = $this->getMock('\\Magento\\Downloadable\\Model\\Product\\Type', [], [], '', false);
     $this->linkResourceMock = $this->getMock('Magento\\Downloadable\\Model\\ResourceModel\\Link', [], [], '', false);
     $this->contentValidatorMock = $this->getMock('\\Magento\\Downloadable\\Model\\Link\\ContentValidator', [], [], '', false);
     $this->contentUploaderMock = $this->getMock('Magento\\Downloadable\\Helper\\File', [], [], '', false);
     $this->jsonEncoderMock = $this->getMock('Magento\\Framework\\Json\\Helper\\Data', [], [], '', false);
     $this->linkFactoryMock = $this->getMockBuilder('Magento\\Downloadable\\Api\\Data\\LinkInterfaceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['__wakeup', 'getTypeId', 'setDownloadableData', 'save', 'getId', 'getStoreId', 'getStore', 'getWebsiteIds', 'getData'], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadata->expects($this->any())->method('getLinkField')->willReturn('id');
     $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata);
     $this->service = new \Magento\Downloadable\Model\LinkRepository($this->metadataPoolMock, $this->repositoryMock, $this->productTypeMock, $this->linkResourceMock, $this->linkFactoryMock, $this->contentValidatorMock, $this->jsonEncoderMock, $this->contentUploaderMock);
 }
 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\\Model\\Entity\\EntityMetadata', [], [], '', false);
     $metadataMock->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $this->metadataPoolMock = $this->getMock('Magento\\Framework\\Model\\Entity\\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->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);
 }
 /**
  * @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->_model = $this->_objectHelper->getObject('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', ['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, 'cache' => $this->cache, 'metadataPool' => $this->metadataPool]);
 }
Beispiel #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\\Model\\Entity\\MetadataPool', [], [], '', false);
     $metadata = $this->getMock('Magento\\Framework\\Model\\Entity\\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->collection = new Collection($this->entityFactoryMock, $this->loggerMock, $this->fetchStrategyMock, $this->eventManagerMock, $this->optionsFactoryMock, $this->storeManagerMock, $this->metadataPoolMock, $this->joinProcessor, null, $this->resourceMock);
 }
 /**
  * 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\\Model\\Entity\\MetadataPool', [], [], '', false);
     $metadata = $this->getMockBuilder('Magento\\Framework\\Model\\Entity\\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->metadataPool);
 }
 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));
 }
 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\\Model\\Entity\\MetadataPool')->disableOriginalConstructor()->getMock();
     $this->metadataMock = $this->getMockBuilder('\\Magento\\Framework\\Model\\Entity\\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('\\Magento\\Bundle\\Model\\LinkManagement', ['productRepository' => $this->productRepository, 'linkFactory' => $this->linkFactory, 'bundleFactory' => $this->bundleFactoryMock, 'bundleSelection' => $this->bundleSelectionMock, 'optionCollection' => $this->optionCollectionFactoryMock, 'storeManager' => $this->storeManagerMock, 'dataObjectHelper' => $this->dataObjectHelperMock, 'metadataPool' => $this->metadataPoolMock]);
 }
 public function testSaveProductAttributes()
 {
     $testTable = 'test_table';
     $attributeId = 'test_attribute_id';
     $storeId = 'test_store_id';
     $testSku = 'test_sku';
     $attributesData = [$testTable => [$testSku => [$attributeId => [$storeId => ['foo' => 'bar']]]]];
     $metadataMock = $this->getMockBuilder('\\Magento\\Framework\\Model\\Entity\\EntityMetadata')->disableOriginalConstructor()->getMock();
     $this->metadataPool->expects($this->any())->method('getMetadata')->with(\Magento\Catalog\Api\Data\ProductInterface::class)->willReturn($metadataMock);
     $metadataMock->expects($this->any())->method('getLinkField')->willReturn('entity_id');
     $entityTable = 'catalog_product_entity';
     $resource = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Proxy\\Product\\ResourceModel')->disableOriginalConstructor()->setMethods(['getTable'])->getMock();
     $resource->expects($this->once())->method('getTable')->with($entityTable)->willReturnArgument(0);
     $this->_resourceFactory->expects($this->once())->method('create')->willReturn($resource);
     $selectMock = $this->getMockBuilder('Magento\\Framework\\DB\\Select')->disableOriginalConstructor()->getMock();
     $selectMock->expects($this->once())->method('from')->with($entityTable, '*', null)->willReturnSelf();
     $selectMock->expects($this->once())->method('where')->with('sku = ?', $testSku)->willReturnSelf();
     $selectMock->expects($this->once())->method('columns')->with('entity_id')->willReturnSelf();
     $this->_connection->expects($this->any())->method('fetchOne')->willReturn(self::ENTITY_ID);
     $this->_connection->expects($this->any())->method('select')->willReturn($selectMock);
     $this->_connection->expects($this->any())->method('quoteInto')->willReturnCallback([$this, 'returnQuoteCallback']);
     $tableData[] = ['entity_id' => self::ENTITY_ID, 'attribute_id' => $attributeId, 'store_id' => $storeId, 'value' => $attributesData[$testTable][$testSku][$attributeId][$storeId]];
     $this->_connection->expects($this->once())->method('insertOnDuplicate')->with($testTable, $tableData, ['value']);
     $object = $this->invokeMethod($this->importProduct, '_saveProductAttributes', [$attributesData]);
     $this->assertEquals($this->importProduct, $object);
 }
 /**
  * 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\Model\Entity\MetadataPool::class, [], [], '', false);
     $entityMetadataMock = $this->getMock(\Magento\Framework\Model\Entity\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);
 }