/**
  * Test a search using 'like' condition
  */
 public function testLike()
 {
     $attributeCode = 'description';
     $attributeCodeId = 42;
     $attribute = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $attribute->expects($this->once())->method('getAttributeCode')->willReturn($attributeCode);
     $this->eavConfig->expects($this->once())->method('getAttribute')->with(Product::ENTITY, $attributeCodeId)->willReturn($attribute);
     $filtersData = ['catalog_product_entity_text' => [$attributeCodeId => ['like' => 'search text']]];
     $this->filterBuilder->expects($this->once())->method('setField')->with($attributeCode)->willReturn($this->filterBuilder);
     $this->filterBuilder->expects($this->once())->method('setValue')->with('search text')->willReturn($this->filterBuilder);
     $filter = $this->getMock('Magento\\Framework\\Api\\Filter');
     $this->filterBuilder->expects($this->once())->method('create')->willReturn($filter);
     $criteria = $this->getMock('Magento\\Framework\\Api\\Search\\SearchCriteria', [], [], '', false);
     $this->criteriaBuilder->expects($this->once())->method('create')->willReturn($criteria);
     $criteria->expects($this->once())->method('setRequestName')->with('advanced_search_container');
     $tempTable = $this->getMock('Magento\\Framework\\DB\\Ddl\\Table', [], [], '', false);
     $temporaryStorage = $this->getMock('Magento\\Framework\\Search\\Adapter\\Mysql\\TemporaryStorage', [], [], '', false);
     $temporaryStorage->expects($this->once())->method('storeApiDocuments')->willReturn($tempTable);
     $this->temporaryStorageFactory->expects($this->once())->method('create')->willReturn($temporaryStorage);
     $searchResult = $this->getMock('Magento\\Framework\\Api\\Search\\SearchResultInterface', [], [], '', false);
     $this->search->expects($this->once())->method('search')->willReturn($searchResult);
     // addFieldsToFilter will load filters,
     //   then loadWithFilter will trigger _renderFiltersBefore code in Advanced/Collection
     $this->assertSame($this->advancedCollection, $this->advancedCollection->addFieldsToFilter($filtersData)->loadWithFilter());
 }
 public function testAfterSave()
 {
     $value = true;
     $attributeMock = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['save', 'setData'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->eavConfigMock->expects($this->once())->method('getAttribute')->with('customer', 'disable_auto_group_change')->willReturn($attributeMock);
     $attributeMock->expects($this->once())->method('setData')->with('default_value', $value);
     $attributeMock->expects($this->once())->method('save');
     $this->model->setValue($value);
     $this->assertEquals($this->model, $this->model->afterSave());
 }
 protected function setUp()
 {
     $this->searchBuilderMock = $this->getMock('Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
     $this->filterBuilderMock = $this->getMock('Magento\\Framework\\Api\\FilterBuilder', [], [], '', false);
     $this->attributeRepositoryMock = $this->getMock('Magento\\Eav\\Api\\AttributeRepositoryInterface', [], [], '', false);
     $this->searchResultMock = $this->getMock('Magento\\Framework\\Api\\SearchResultsInterface', ['getItems', 'getSearchCriteria', 'getTotalCount', 'setItems', 'setSearchCriteria', 'setTotalCount', '__wakeup'], [], '', false);
     $this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn(new \Magento\Framework\DataObject(['default_attribute_set_id' => 3]));
     $this->model = (new ObjectManager($this))->getObject('Magento\\Catalog\\Model\\Category\\AttributeRepository', ['searchCriteriaBuilder' => $this->searchBuilderMock, 'filterBuilder' => $this->filterBuilderMock, 'eavAttributeRepository' => $this->attributeRepositoryMock, 'eavConfig' => $this->eavConfigMock]);
 }
Beispiel #4
0
 public function testGetAttributeMetadata()
 {
     $attribute = new \Magento\Framework\Object(['entity_type_id' => '1', 'attribute_id' => '2', 'backend' => new \Magento\Framework\Object(['table' => 'customer_entity_varchar']), 'backend_type' => 'varchar']);
     $this->_eavConfig->expects($this->once())->method('getAttribute')->will($this->returnValue($attribute));
     $result = $this->_helper->getAttributeMetadata('customer', 'lastname');
     $expected = ['entity_type_id' => '1', 'attribute_id' => '2', 'attribute_table' => 'customer_entity_varchar', 'backend_type' => 'varchar'];
     foreach ($result as $key => $value) {
         $this->assertArrayHasKey($key, $expected, 'Attribute metadata with key "' . $key . '" not found.');
         $this->assertEquals($expected[$key], $value, 'Attribute metadata with key "' . $key . '" has invalid value.');
     }
 }
 public function testAfterGetUsedProductCollection()
 {
     $subject = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $result = $this->getMock('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\Collection', ['getEntity', 'addAttributeToSelect'], [], '', false);
     $collectionEntity = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', ['getType'], [], '', false);
     $collectionEntity->expects($this->once())->method('getType')->willReturn('catalog');
     $result->expects($this->once())->method('getEntity')->willReturn($collectionEntity);
     $attribute = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $this->eavConfig->expects($this->once())->method('getEntityAttributeCodes')->with('catalog')->willReturn(['size', 'color', 'swatch1']);
     $this->eavConfig->expects($this->exactly(3))->method('getAttribute')->willReturn($attribute);
     $this->swatchHelper->expects($this->exactly(3))->method('isVisualSwatch')->with($attribute)->willReturn(true);
     $result->expects($this->once())->method('addAttributeToSelect')->with($this->identicalTo(['image', 'size', 'color', 'swatch1']))->willReturn($result);
     $result = $this->pluginModel->afterGetUsedProductCollection($subject, $result);
     $this->assertInstanceOf('\\Magento\\ConfigurableProduct\\Model\\ResourceModel\\Product\\Type\\Configurable\\Product\\Collection', $result);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testAddDynamicDataWithStaticAndFilterable()
 {
     $existentName = 'field';
     $existentField = ['name' => $existentName, 'handler' => 'handler', 'origin' => $existentName, 'type' => 'type', 'filters' => ['filter'], 'dataType' => 'data_type'];
     $data = ['fields' => [$existentName => $existentField], 'references' => ['customer' => ['to' => 'to_field']]];
     $attrName = $existentName;
     $attrBackendType = 'varchar';
     $attrFrontendInput = 'text';
     /** @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject $collectionMock $entityType */
     $entityType = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock();
     /** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
     $collectionMock = $this->getMockBuilder('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Collection')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Customer\Model\ResourceModel\Customer|\PHPUnit_Framework_MockObject_MockObject $entity */
     $entity = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer')->disableOriginalConstructor()->getMock();
     /** @var \Magento\Customer\Model\Attribute|\PHPUnit_Framework_MockObject_MockObject $attribute */
     $attribute = $this->getMockBuilder('Magento\\Customer\\Model\\Attribute')->disableOriginalConstructor()->setMethods(['setEntity', 'getName', 'getFrontendInput', 'getBackendType', 'canBeSearchableInGrid', 'canBeFilterableInGrid', 'getData'])->getMock();
     $this->eavConfig->expects($this->once())->method('getEntityType')->with(Customer::ENTITY)->willReturn($entityType);
     $entityType->expects($this->once())->method('getAttributeCollection')->willReturn($collectionMock);
     $collectionMock->expects($this->once())->method('getItems')->willReturn([$attribute]);
     $entityType->expects($this->once())->method('getEntity')->willReturn($entity);
     $attribute->expects($this->once())->method('setEntity')->with($entity)->willReturnSelf();
     $attribute->expects($this->exactly(3))->method('getName')->willReturn($attrName);
     $attribute->expects($this->any())->method('getFrontendInput')->willReturn($attrFrontendInput);
     $attribute->expects($this->any())->method('getBackendType')->willReturn($attrBackendType);
     $attribute->expects($this->any())->method('canBeSearchableInGrid')->willReturn(false);
     $attribute->expects($this->any())->method('canBeFilterableInGrid')->willReturn(true);
     $attribute->expects($this->any())->method('getData')->willReturnMap([['is_used_in_grid', null, true]]);
     $this->assertEquals(['fields' => [$attrName => ['name' => $attrName, 'handler' => 'Magento\\Framework\\Indexer\\Handler\\AttributeHandler', 'origin' => $attrName, 'type' => 'filterable', 'filters' => [], 'dataType' => 'varchar', 'entity' => Customer::ENTITY, 'bind' => 'to_field']], 'references' => ['customer' => ['to' => 'to_field']]], $this->object->addDynamicData($data));
 }
 protected function setUp()
 {
     parent::setUp();
     $this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $this->eavValidationRulesMock = $this->getMockBuilder(EavValidationRules::class)->disableOriginalConstructor()->getMock();
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->groupCollectionFactoryMock = $this->getMockBuilder(GroupCollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->groupCollectionMock = $this->getMockBuilder(GroupCollection::class)->disableOriginalConstructor()->getMock();
     $this->attributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock();
     $this->groupMock = $this->getMockBuilder(Group::class)->disableOriginalConstructor()->setMethods(['getAttributeGroupCode'])->getMock();
     $this->entityTypeMock = $this->getMockBuilder(EntityType::class)->disableOriginalConstructor()->getMock();
     $this->attributeCollectionMock = $this->getMockBuilder(AttributeCollection::class)->disableOriginalConstructor()->getMock();
     $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass();
     $this->formElementMapperMock = $this->getMockBuilder(FormElementMapper::class)->disableOriginalConstructor()->getMock();
     $this->metaPropertiesMapperMock = $this->getMockBuilder(MetaPropertiesMapper::class)->disableOriginalConstructor()->getMock();
     $this->groupCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->groupCollectionMock);
     $this->groupCollectionMock->expects($this->any())->method('setAttributeSetFilter')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('setSortOrder')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('load')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupMock]));
     $this->attributeCollectionMock->expects($this->any())->method('addFieldToSelect')->willReturnSelf();
     $this->attributeCollectionMock->expects($this->any())->method('load')->willReturnSelf();
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityTypeMock);
     $this->entityTypeMock->expects($this->any())->method('getAttributeCollection')->willReturn($this->attributeCollectionMock);
     $this->productMock->expects($this->any())->method('getAttributes')->willReturn([$this->attributeMock]);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->productFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->productMock = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->initializedProductMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['setProductOptions', 'load', 'getOptions', 'getSku', 'getGalleryAttributeBackend', 'getMediaConfig', 'getMediaAttributes', 'getProductLinks', 'setProductLinks'], [], '', false);
     $this->filterBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\FilterBuilder', [], [], '', false);
     $this->initializationHelperMock = $this->getMock('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false);
     $this->collectionFactoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->searchCriteriaBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
     $this->metadataServiceMock = $this->getMock('\\Magento\\Catalog\\Api\\ProductAttributeRepositoryInterface', [], [], '', false);
     $this->searchResultsFactoryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductSearchResultsInterfaceFactory', ['create'], [], '', false);
     $this->resourceModelMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product', [], [], '', false);
     $this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn(new \Magento\Framework\Object(['default_attribute_set_id' => 4]));
     $this->objectManager = new ObjectManager($this);
     $this->extensibleDataObjectConverterMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\ExtensibleDataObjectConverter')->setMethods(['toNestedArray'])->disableOriginalConstructor()->getMock();
     $this->fileSystemMock = $this->getMockBuilder('\\Magento\\Framework\\Filesystem')->disableOriginalConstructor()->getMock();
     $this->mimeTypeExtensionMapMock = $this->getMockBuilder('Magento\\Catalog\\Model\\Product\\Gallery\\MimeTypeExtensionMap')->getMock();
     $this->contentFactoryMock = $this->getMock('Magento\\Framework\\Api\\Data\\ImageContentInterfaceFactory', ['create'], [], '', false);
     $this->contentValidatorMock = $this->getMockBuilder('Magento\\Framework\\Api\\ImageContentValidatorInterface')->disableOriginalConstructor()->getMock();
     $optionConverter = $this->objectManager->getObject('Magento\\Catalog\\Model\\Product\\Option\\Converter');
     $this->linkTypeProviderMock = $this->getMock('Magento\\Catalog\\Model\\Product\\LinkTypeProvider', ['getLinkTypes'], [], '', false);
     $this->imageProcessorMock = $this->getMock('Magento\\Framework\\Api\\ImageProcessorInterface', [], [], '', false);
     $this->model = $this->objectManager->getObject('Magento\\Catalog\\Model\\ProductRepository', ['productFactory' => $this->productFactoryMock, 'initializationHelper' => $this->initializationHelperMock, 'resourceModel' => $this->resourceModelMock, 'filterBuilder' => $this->filterBuilderMock, 'collectionFactory' => $this->collectionFactoryMock, 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, 'metadataServiceInterface' => $this->metadataServiceMock, 'searchResultsFactory' => $this->searchResultsFactoryMock, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock, 'optionConverter' => $optionConverter, 'eavConfig' => $this->eavConfigMock, 'contentValidator' => $this->contentValidatorMock, 'fileSystem' => $this->fileSystemMock, 'contentFactory' => $this->contentFactoryMock, 'mimeTypeExtensionMap' => $this->mimeTypeExtensionMapMock, 'linkTypeProvider' => $this->linkTypeProviderMock, 'imageProcessor' => $this->imageProcessorMock]);
 }
 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();
 }
Beispiel #10
0
 /**
  * Set Up
  */
 protected function setUp()
 {
     $this->localeDate = $this->getMock('Magento\\Framework\\Stdlib\\DateTime\\Timezone', [], [], '', false);
     $this->config = $this->getMock('Magento\\Eav\\Model\\Config', ['getEntityType'], [], '', false);
     $type = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Type', [], [], '', false);
     $this->config->expects($this->once())->method('getEntityType')->willReturn($type);
     $this->resource = $this->getMock('Magento\\Framework\\App\\Resource', [], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $this->logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $this->collection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', [], [], '', false);
     $this->abstractCollection = $this->getMockForAbstractClass('\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', [], '', false, true, true, ['count', 'setOrder', 'setStoreId', 'getCurPage', 'getLastPageNumber']);
     $this->exportConfig = $this->getMock('Magento\\ImportExport\\Model\\Export\\Config', [], [], '', false);
     $this->productFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\ProductFactory', ['create', 'getTypeId'], [], '', false);
     $this->attrSetColFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create', 'setEntityTypeFilter'], [], '', false);
     $this->categoryColFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', ['create', 'addNameToResult'], [], '', false);
     $this->itemFactory = $this->getMock('Magento\\CatalogInventory\\Model\\Resource\\Stock\\ItemFactory', [], [], '', false);
     $this->optionColFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Option\\CollectionFactory', [], [], '', false);
     $this->attributeColFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', [], [], '', false);
     $this->typeFactory = $this->getMock('Magento\\CatalogImportExport\\Model\\Export\\Product\\Type\\Factory', [], [], '', false);
     $this->linkTypeProvider = $this->getMock('Magento\\Catalog\\Model\\Product\\LinkTypeProvider', [], [], '', false);
     $this->rowCustomizer = $this->getMock('Magento\\CatalogImportExport\\Model\\Export\\RowCustomizer\\Composite', [], [], '', false);
     $this->storeResolver = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\StoreResolver', [], [], '', false);
     $this->groupRepository = $this->getMock('\\Magento\\Customer\\Api\\GroupRepositoryInterface', [], [], '', false);
     $this->writer = $this->getMock('Magento\\ImportExport\\Model\\Export\\Adapter\\AbstractAdapter', ['setHeaderCols', 'writeRow', 'getContents'], [], '', false);
     $constructorMethods = ['initTypeModels', 'initAttributes', '_initStores', 'initAttributeSets', 'initWebsites', 'initCategories'];
     $mockMethods = array_merge($constructorMethods, ['_customHeadersMapping', '_prepareEntityCollection', '_getEntityCollection', 'getWriter', 'getExportData', '_headerColumns', '_customFieldsMapping', 'getItemsPerPage', 'paginateCollection', '_getHeaderColumns']);
     $this->advancedPricing = $this->getMock('Magento\\AdvancedPricingImportExport\\Model\\Export\\AdvancedPricing', $mockMethods, [], '', false);
     foreach ($constructorMethods as $method) {
         $this->advancedPricing->expects($this->once())->method($method)->will($this->returnSelf());
     }
     $this->advancedPricing->__construct($this->localeDate, $this->config, $this->resource, $this->storeManager, $this->logger, $this->collection, $this->exportConfig, $this->productFactory, $this->attrSetColFactory, $this->categoryColFactory, $this->itemFactory, $this->optionColFactory, $this->attributeColFactory, $this->typeFactory, $this->linkTypeProvider, $this->rowCustomizer, $this->storeResolver, $this->groupRepository);
 }
Beispiel #11
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', array('getEntityType', 'getEntityTypeId'), array(), '', false);
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityType')->with($this->equalTo('catalog_product'))->will($this->returnSelf());
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityTypeId')->will($this->returnValue('1'));
     $this->_optionModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Option', array(), array(), '', false);
     $this->_optionFactory = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\OptionFactory', array('create'), array(), '', false);
     $this->_optionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_optionModel));
     $this->_storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManager', array('getWebsites', 'getStores'), array(), '', false);
     $this->_storeManager->expects($this->atLeastOnce())->method('getWebsites')->will($this->returnValue(array()));
     $this->_storeManager->expects($this->atLeastOnce())->method('getStores')->will($this->returnValue(array()));
     $this->_setCol = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', array('setEntityTypeFilter'), array(), '', false);
     $this->_setCol->expects($this->atLeastOnce())->method('setEntityTypeFilter')->with($this->equalTo('1'))->will($this->returnValue(array()));
     $this->_setColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', array('create'), array(), '', false);
     $this->_setColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_setCol));
     $this->_importConfig = $this->getMock('\\Magento\\ImportExport\\Model\\Import\\Config', array('getEntityTypes'), array(), '', false);
     $this->_importConfig->expects($this->atLeastOnce())->method('getEntityTypes')->with('catalog_product')->will($this->returnValue(array()));
     $this->_categoryCol = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\Collection', array('addNameToResult'), array(), '', false);
     $this->_categoryCol->expects($this->atLeastOnce())->method('addNameToResult')->will($this->returnValue(array()));
     $this->_categoryColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', array('create'), array(), '', false);
     $this->_categoryColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_categoryCol));
     $this->_product = $this->getMock('\\Magento\\Catalog\\Model\\Product', array('getProductEntitiesInfo', '__wakeup'), array(), '', false);
     $this->_product->expects($this->atLeastOnce())->method('getProductEntitiesInfo')->with($this->equalTo(array('entity_id', 'type_id', 'attribute_set_id', 'sku')))->will($this->returnValue(array()));
     $this->_productFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', array('create'), array(), '', false);
     $this->_productFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_product));
     $this->_customerGroupService = $this->getMock('Magento\\Customer\\Service\\V1\\CustomerGroupService', array('getGroups'), array(), '', false);
     $this->_customerGroupService->expects($this->atLeastOnce())->method('getGroups')->will($this->returnValue(array()));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_model = $objectManager->getObject('\\Magento\\CatalogImportExport\\Model\\Import\\Product', array('config' => $this->_eavConfig, 'optionFactory' => $this->_optionFactory, 'storeManager' => $this->_storeManager, 'setColFactory' => $this->_setColFactory, 'importConfig' => $this->_importConfig, 'categoryColFactory' => $this->_categoryColFactory, 'productFactory' => $this->_productFactory, 'customerGroupService' => $this->_customerGroupService));
 }
Beispiel #12
0
 public function testGetPrefixes()
 {
     $entityTypeId = 3;
     /** @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject $entityType */
     $entityType = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock();
     $entityType->expects($this->once())->method('getId')->will($this->returnValue($entityTypeId));
     /** @var AbstractFrontend|\PHPUnit_Framework_MockObject_MockObject $frontend */
     $frontend = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Attribute\\Frontend\\AbstractFrontend')->setMethods(['getLabel'])->disableOriginalConstructor()->getMockForAbstractClass();
     $frontend->expects($this->once())->method('getLabel')->will($this->returnValue('testLabel'));
     $this->attributeCollection->expects($this->once())->method('setEntityTypeFilter')->with($this->equalTo($entityTypeId));
     $this->attributeCollection->expects($this->once())->method('setFrontendInputTypeFilter')->with($this->equalTo('media_image'));
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue('attributeCode'));
     $this->attribute->expects($this->once())->method('getFrontend')->will($this->returnValue($frontend));
     $this->attributeCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->attribute])));
     $this->eavConfig->expects($this->any())->method('getEntityType')->with($this->equalTo(Product::ENTITY))->will($this->returnValue($entityType));
     $this->assertEquals([['field' => 'attributeCode_', 'label' => 'testLabel']], $this->model->getPrefixes());
 }
Beispiel #13
0
 /**
  * Test NoSuchEntityException getAttributeMetadata
  * @expectedException \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage No such entity with attributeCode = attr_code
  */
 public function testGetAttributeMetadataNoSuchEntityException()
 {
     $data = ['attribute_id' => 1, 'attribute_code' => 'description', 'frontend_label' => 'English', 'store_labels' => array(1 => 'France'), 'frontend_input' => 'textarea'];
     $attributeMock = $this->getMock('Magento\\Framework\\Object', array('getId'), array('data' => $data));
     $this->eavConfigMock->expects($this->once())->method('getAttribute')->will($this->returnValue($attributeMock));
     $attributeMock->expects($this->once())->method('getId')->will($this->returnValue(null));
     $this->service->getAttributeMetadata('entity_type', 'attr_code');
 }
Beispiel #14
0
 public function testUpdateAttributes()
 {
     $productIds = [1, 2, 2, 4];
     $productIdsUnique = [0 => 1, 1 => 2, 3 => 4];
     $attrData = [1];
     $storeId = 1;
     $this->resource->expects($this->any())->method('updateAttributes')->with($productIds, $attrData, $storeId)->will($this->returnSelf());
     $this->categoryIndexer->expects($this->any())->method('isScheduled')->will($this->returnValue(false));
     $this->categoryIndexer->expects($this->any())->method('reindexList')->will($this->returnValue($productIds));
     $this->prepareIndexer();
     $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttribute));
     $this->eavAttribute->expects($this->any())->method('isIndexable')->will($this->returnValue(false));
     $this->assertEquals($this->model, $this->model->updateAttributes($productIds, $attrData, $storeId));
     $this->assertEquals($this->model->getDataByKey('product_ids'), $productIdsUnique);
     $this->assertEquals($this->model->getDataByKey('attributes_data'), $attrData);
     $this->assertEquals($this->model->getDataByKey('store_id'), $storeId);
 }
 protected function setUp()
 {
     $this->productFactoryMock = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->productMock = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $this->filterBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\FilterBuilder', [], [], '', false);
     $this->initializationHelperMock = $this->getMock('\\Magento\\Catalog\\Controller\\Adminhtml\\Product\\Initialization\\Helper', [], [], '', false);
     $this->collectionFactoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->searchCriteriaBuilderMock = $this->getMock('\\Magento\\Framework\\Api\\SearchCriteriaBuilder', [], [], '', false);
     $this->metadataServiceMock = $this->getMock('\\Magento\\Catalog\\Api\\ProductAttributeRepositoryInterface', [], [], '', false);
     $this->searchResultsFactoryMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductSearchResultsInterfaceFactory', ['create'], [], '', false);
     $this->resourceModelMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product', [], [], '', false);
     $this->eavConfigMock = $this->getMock('Magento\\Eav\\Model\\Config', [], [], '', false);
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn(new \Magento\Framework\Object(['default_attribute_set_id' => 4]));
     $this->objectManager = new ObjectManager($this);
     $this->extensibleDataObjectConverterMock = $this->getMockBuilder('\\Magento\\Framework\\Api\\ExtensibleDataObjectConverter')->setMethods(['toNestedArray'])->disableOriginalConstructor()->getMock();
     $this->model = $this->objectManager->getObject('Magento\\Catalog\\Model\\ProductRepository', ['productFactory' => $this->productFactoryMock, 'initializationHelper' => $this->initializationHelperMock, 'resourceModel' => $this->resourceModelMock, 'filterBuilder' => $this->filterBuilderMock, 'collectionFactory' => $this->collectionFactoryMock, 'searchCriteriaBuilder' => $this->searchCriteriaBuilderMock, 'metadataServiceInterface' => $this->metadataServiceMock, 'searchResultsFactory' => $this->searchResultsFactoryMock, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock, 'eavConfig' => $this->eavConfigMock]);
 }
 /**
  * @dataProvider validateDataProvider
  *
  * @param string $attributeValue
  * @param string|array $parsedValue
  * @param string $newValue
  * @param string $operator
  * @param array $input
  */
 public function testValidateWithDatetimeValue($attributeValue, $parsedValue, $newValue, $operator, $input)
 {
     $this->product->setData('attribute', 'attribute_key');
     $this->product->setData('value_parsed', $parsedValue);
     $this->product->setData('operator', $operator);
     $this->config->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->eavAttributeResource->expects($this->any())->method('isScopeGlobal')->will($this->returnValue(false));
     $this->eavAttributeResource->expects($this->any())->method($input['method'])->will($this->returnValue($input['type']));
     $this->productModel->expects($this->any())->method('hasData')->will($this->returnValue(true));
     $this->productModel->expects($this->at(0))->method('getData')->will($this->returnValue(['1' => ['1' => $attributeValue]]));
     $this->productModel->expects($this->any())->method('getData')->will($this->returnValue($newValue));
     $this->productModel->expects($this->any())->method('getId')->will($this->returnValue('1'));
     $this->productModel->expects($this->once())->method('getStoreId')->will($this->returnValue('1'));
     $this->productModel->expects($this->any())->method('getResource')->will($this->returnValue($this->productResource));
     $this->productResource->expects($this->any())->method('getAttribute')->will($this->returnValue($this->eavAttributeResource));
     $this->product->collectValidatedAttributes($this->productModel);
     $this->assertTrue($this->product->validate($this->productModel));
 }
Beispiel #17
0
 /**
  * @return $this
  */
 protected function _parentObjectConstructor()
 {
     $type = $this->getMockBuilder('Magento\\Eav\\Model\\Entity\\Type')->disableOriginalConstructor()->getMock();
     $type->expects($this->any())->method('getEntityTypeId')->will($this->returnValue(self::ENTITY_TYPE_ID));
     $this->config->expects($this->any())->method('getEntityType')->with(self::ENTITY_TYPE_CODE)->willReturn($type);
     $this->_connection = $this->getMock('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface');
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->_connection);
     return $this;
 }
Beispiel #18
0
 public function testSendNewAccountEmailWithoutStoreId()
 {
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $website = $this->getMock('Magento\\Store\\Model\\Website', [], [], '', false);
     $website->expects($this->once())->method('getStoreIds')->will($this->returnValue([1, 2, 3, 4]));
     $this->_storeManager->expects($this->once())->method('getWebsite')->with(1)->will($this->returnValue($website));
     $this->_storeManager->expects($this->once())->method('getStore')->with(1)->will($this->returnValue($store));
     $this->_config->expects($this->exactly(3))->method('getAttribute')->will($this->returnValue($this->_attribute));
     $this->_attribute->expects($this->exactly(3))->method('getIsVisible')->will($this->returnValue(true));
     $methods = ['setTemplateIdentifier', 'setTemplateOptions', 'setTemplateVars', 'setFrom', 'addTo'];
     foreach ($methods as $method) {
         $this->_transportBuilderMock->expects($this->once())->method($method)->will($this->returnSelf());
     }
     $transportMock = $this->getMock('Magento\\Framework\\Mail\\TransportInterface', [], [], '', false);
     $transportMock->expects($this->once())->method('sendMessage')->will($this->returnSelf());
     $this->_transportBuilderMock->expects($this->once())->method('getTransport')->will($this->returnValue($transportMock));
     $this->_model->setData(['website_id' => 1, 'store_id' => 1, 'email' => '*****@*****.**', 'firstname' => 'FirstName', 'lastname' => 'LastName', 'middlename' => 'MiddleName', 'prefix' => 'Prefix']);
     $this->_model->sendNewAccountEmail('registered');
 }
 /**
  * Test UpdateCatalogRuleGroupWebsiteData
  *
  * @covers \Magento\CatalogRule\Model\Indexer\IndexBuilder::updateCatalogRuleGroupWebsiteData
  * @return void
  */
 public function testUpdateCatalogRuleGroupWebsiteData()
 {
     $priceAttrMock = $this->getMock('Magento\\Catalog\\Model\\Entity\\Attribute', ['getBackend'], [], '', false);
     $backendModelMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Attribute\\Backend\\Tierprice', ['getResource'], [], '', false);
     $resourceMock = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Backend\\Tierprice', ['getMainTable'], [], '', false);
     $resourceMock->expects($this->any())->method('getMainTable')->will($this->returnValue('catalog_product_entity_tear_price'));
     $backendModelMock->expects($this->any())->method('getResource')->will($this->returnValue($resourceMock));
     $priceAttrMock->expects($this->any())->method('getBackend')->will($this->returnValue($backendModelMock));
     $this->eavConfig->expects($this->at(0))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'price')->will($this->returnValue($this->attribute));
     $this->select->expects($this->once())->method('insertFromSelect')->with('catalogrule_group_website');
     $this->indexBuilder->reindexByIds([1]);
 }
Beispiel #20
0
 public function testGetAllAttributeCodesWithoutStoreId()
 {
     $entityType = 'entityType';
     $attributeSetId = 'attributeSetId';
     $storeId = 'storeId';
     $value = 'value';
     $store = $this->getMockBuilder('Magento\\Model\\Store')->disableOriginalConstructor()->setMethods(['getId'])->getMock();
     $store->expects($this->once())->method('getId')->will($this->returnValue($storeId));
     $this->storeManager->expects($this->once())->method('getStore')->will($this->returnValue($store));
     $objectCodes = new \Magento\Framework\Object(['store_id' => $storeId, 'attribute_set_id' => $attributeSetId]);
     $this->configEav->expects($this->once())->method('getEntityAttributeCodes')->with($entityType, $objectCodes)->will($this->returnValue($value));
     $actualValue = $this->attributeMetadataProvider->getAllAttributeCodes($entityType, $attributeSetId, null);
     $this->assertEquals($value, $actualValue);
 }
 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\\Store\\Model\\StoreManagerInterface');
     $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnSelf());
     $this->connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'describeTable', 'quoteIdentifier', '_connect', '_quote'], [], '', false);
     $this->select = new \Magento\Framework\DB\Select($this->connectionMock);
     $this->resourceMock = $this->getMockForAbstractClass('Magento\\Framework\\Model\\ModelResource\\Db\\AbstractDb', [], '', false, true, true, ['__wakeup', 'getConnection', 'getMainTable', 'getTable']);
     $this->connectionMock->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $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('getConnection')->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'));
 }
 /**
  * Set up test
  *
  * @return void
  */
 protected function setUp()
 {
     $this->resource = $this->getMock('Magento\\Framework\\App\\Resource', ['getConnection', 'getTableName'], [], '', false);
     $this->ruleCollectionFactory = $this->getMock('Magento\\CatalogRule\\Model\\Resource\\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->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', [], [], '', 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('getConditions')->will($this->returnValue($this->combine));
     $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->combine->expects($this->any())->method('validate')->will($this->returnValue(true));
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->backend));
     $this->eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($this->attribute));
     $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);
 }
Beispiel #23
0
 protected function setUp()
 {
     parent::setUp();
     $this->objectManager = new ObjectManager($this);
     $this->eavConfigMock = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
     $this->eavValidationRulesMock = $this->getMockBuilder(EavValidationRules::class)->disableOriginalConstructor()->getMock();
     $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass();
     $this->groupCollectionFactoryMock = $this->getMockBuilder(GroupCollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->groupCollectionMock = $this->getMockBuilder(GroupCollection::class)->disableOriginalConstructor()->getMock();
     $this->attributeMock = $this->getMockBuilder(EavAttribute::class)->disableOriginalConstructor()->getMock();
     $this->groupMock = $this->getMockBuilder(Group::class)->disableOriginalConstructor()->setMethods(['getAttributeGroupCode'])->getMock();
     $this->entityTypeMock = $this->getMockBuilder(EntityType::class)->disableOriginalConstructor()->getMock();
     $this->attributeCollectionMock = $this->getMockBuilder(AttributeCollection::class)->disableOriginalConstructor()->getMock();
     $this->storeManagerMock = $this->getMockBuilder(StoreManagerInterface::class)->getMockForAbstractClass();
     $this->formElementMapperMock = $this->getMockBuilder(FormElementMapper::class)->disableOriginalConstructor()->getMock();
     $this->metaPropertiesMapperMock = $this->getMockBuilder(MetaPropertiesMapper::class)->disableOriginalConstructor()->getMock();
     $this->searchCriteriaBuilderMock = $this->getMockBuilder(SearchCriteriaBuilder::class)->disableOriginalConstructor()->getMock();
     $this->attributeGroupRepositoryMock = $this->getMockBuilder(ProductAttributeGroupRepositoryInterface::class)->getMockForAbstractClass();
     $this->attributeGroupMock = $this->getMockBuilder(AttributeGroupInterface::class)->setMethods(['getAttributeGroupCode', 'getApplyTo'])->getMockForAbstractClass();
     $this->attributeRepositoryMock = $this->getMockBuilder(ProductAttributeRepositoryInterface::class)->getMockForAbstractClass();
     $this->searchCriteriaMock = $this->getMockBuilder(SearchCriteria::class)->disableOriginalConstructor()->setMethods(['getItems'])->getMock();
     $this->sortOrderBuilderMock = $this->getMockBuilder(SortOrderBuilder::class)->disableOriginalConstructor()->getMock();
     $this->searchResultsMock = $this->getMockBuilder(SearchResultsInterface::class)->getMockForAbstractClass();
     $this->eavAttributeMock = $this->getMockBuilder(Attribute::class)->setMethods(['getAttributeGroupCode', 'getApplyTo', 'getFrontendInput', 'getAttributeCode'])->disableOriginalConstructor()->getMock();
     $this->groupCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->groupCollectionMock);
     $this->groupCollectionMock->expects($this->any())->method('setAttributeSetFilter')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('setSortOrder')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('load')->willReturnSelf();
     $this->groupCollectionMock->expects($this->any())->method('getIterator')->willReturn(new \ArrayIterator([$this->groupMock]));
     $this->attributeCollectionMock->expects($this->any())->method('addFieldToSelect')->willReturnSelf();
     $this->attributeCollectionMock->expects($this->any())->method('load')->willReturnSelf();
     $this->eavConfigMock->expects($this->any())->method('getEntityType')->willReturn($this->entityTypeMock);
     $this->entityTypeMock->expects($this->any())->method('getAttributeCollection')->willReturn($this->attributeCollectionMock);
     $this->productMock->expects($this->any())->method('getAttributes')->willReturn([$this->attributeMock]);
     $this->storeMock = $this->getMockBuilder(StoreInterface::class)->setMethods(['load', 'getId', 'getConfig', 'getBaseCurrencyCode'])->getMockForAbstractClass();
     $this->currencyMock = $this->getMockBuilder(Currency::class)->disableOriginalConstructor()->setMethods(['toCurrency'])->getMock();
     $this->currencyLocaleMock = $this->getMockBuilder(CurrencyLocale::class)->disableOriginalConstructor()->setMethods(['getCurrency'])->getMock();
     $this->eav = $this->getModel();
     $this->objectManager->setBackwardCompatibleProperty($this->eav, 'localeCurrency', $this->currencyLocaleMock);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.TooManyFields)
  * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function setUp()
 {
     $this->importProduct = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getProductCategories', 'getProductWebsites', 'getStoreIdByCode', 'getCategoryProcessor'], [], '', false);
     $this->catalogProductFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false);
     $this->storeManager = $this->getMockBuilder('\\Magento\\Store\\Model\\StoreManagerInterface')->disableOriginalConstructor()->setMethods(['getWebsite'])->getMockForAbstractClass();
     $this->event = $this->getMock('\\Magento\\Framework\\Event', ['getAdapter', 'getBunch'], [], '', false);
     $this->event->expects($this->any())->method('getAdapter')->willReturn($this->importProduct);
     $this->event->expects($this->any())->method('getBunch')->willReturn($this->products);
     $this->observer = $this->getMock('\\Magento\\Framework\\Event\\Observer', ['getEvent'], [], '', false);
     $this->observer->expects($this->any())->method('getEvent')->willReturn($this->event);
     $this->urlPersist = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlPersistInterface')->disableOriginalConstructor()->getMock();
     $this->productUrlRewriteGenerator = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlRewriteGenerator')->disableOriginalConstructor()->setMethods(['generate'])->getMock();
     $this->productRepository = $this->getMockBuilder('\\Magento\\Catalog\\Api\\ProductRepositoryInterface')->disableOriginalConstructor()->getMock();
     $this->eavConfig = $this->getMock('\\Magento\\Eav\\Model\\Config', ['getAttribute'], [], '', false);
     $attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute')->setMethods(['getBackendTable'])->disableOriginalConstructor()->getMockForAbstractClass();
     $beTable = 'backend table';
     $attribute->expects($this->any())->method('getBackendTable')->willReturn($beTable);
     $this->eavConfig->expects($this->any())->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, \Magento\CatalogUrlRewrite\Observer\AfterImportDataObserver::URL_KEY_ATTRIBUTE_CODE)->willReturn($attribute);
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', [], [], '', false);
     $this->connection = $this->getMockBuilder('\\Magento\\Framework\\DB\\Adapter\\AdapterInterface')->disableOriginalConstructor()->setMethods(['quoteInto', 'select', 'fetchAll'])->getMockForAbstractClass();
     $this->resource->expects($this->any())->method('getConnection')->willReturn($this->connection);
     $this->select = $this->getMock('\\Magento\\Framework\\DB\\Select', ['from', 'where'], [], '', false);
     $this->connection->expects($this->any())->method('select')->willReturn($this->select);
     $this->objectRegistryFactory = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistryFactory', [], [], '', false);
     $this->productUrlPathGenerator = $this->getMock('\\Magento\\CatalogUrlRewrite\\Model\\ProductUrlPathGenerator', [], [], '', false);
     $this->storeViewService = $this->getMock('\\Magento\\CatalogUrlRewrite\\Service\\V1\\StoreViewService', [], [], '', false);
     $this->urlRewriteFactory = $this->getMock('\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewriteFactory', ['create'], [], '', false);
     $this->urlFinder = $this->getMockBuilder('\\Magento\\UrlRewrite\\Model\\UrlFinderInterface')->setMethods(['findAllByData'])->disableOriginalConstructor()->getMockForAbstractClass();
     $this->urlRewrite = $this->getMockBuilder('Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->disableOriginalConstructor()->getMock();
     $this->product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $this->objectRegistry = $this->getMockBuilder('\\Magento\\CatalogUrlRewrite\\Model\\ObjectRegistry')->disableOriginalConstructor()->getMock();
     $categoryProcessor = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\CategoryProcessor', ['getCategoryById'], [], '', false);
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getId'], [], '', false);
     $category->expects($this->any())->method('getId')->willReturn($this->categoryId);
     $categoryProcessor->expects($this->any())->method('getCategoryById')->with($this->categoryId)->willReturn($category);
     $this->importProduct->expects($this->any())->method('getCategoryProcessor')->willReturn($categoryProcessor);
     $this->objectManager = new ObjectManager($this);
     $this->import = $this->objectManager->getObject('\\Magento\\CatalogUrlRewrite\\Observer\\AfterImportDataObserver', ['catalogProductFactory' => $this->catalogProductFactory, 'eavConfig' => $this->eavConfig, 'objectRegistryFactory' => $this->objectRegistryFactory, 'productUrlPathGenerator' => $this->productUrlPathGenerator, 'resource' => $this->resource, 'storeViewService' => $this->storeViewService, 'storeManager' => $this->storeManager, 'urlPersist' => $this->urlPersist, 'urlRewriteFactory' => $this->urlRewriteFactory, 'urlFinder' => $this->urlFinder]);
 }
 public function testProcessNotStaticAttribute()
 {
     $expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)';
     $scopeId = 0;
     $isNegation = false;
     $query = 'SELECT field FROM table';
     $attributeId = 1234567;
     $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
     $this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute'));
     $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute));
     $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false));
     $this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table'));
     $this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId));
     $this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL'));
     $this->select->expects($this->once())->method('from')->with(['main_table' => 'backend_table'], 'entity_id')->will($this->returnSelf());
     $this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf());
     $this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf());
     $this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf());
     $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART'));
     $actualResult = $this->target->process($this->filter, $isNegation, $query);
     $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
 }
 public function testRefreshSpecialPrices()
 {
     $idsToProcess = array(1, 2, 3);
     $selectMock = $this->getMock('Magento\\Framework\\DB\\Select', array(), array(), '', false);
     $selectMock->expects($this->any())->method('from')->will($this->returnSelf());
     $selectMock->expects($this->any())->method('where')->will($this->returnSelf());
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\AdapterInterface', array(), array(), '', false);
     $connectionMock->expects($this->any())->method('select')->will($this->returnValue($selectMock));
     $connectionMock->expects($this->any())->method('fetchCol')->with($selectMock, array('entity_id'))->will($this->returnValue($idsToProcess));
     $this->_resourceMock->expects($this->once())->method('getConnection')->with('write')->will($this->returnValue($connectionMock));
     $storeMock = $this->getMock('\\Magento\\Store\\Model\\Store', array(), array(), '', false);
     $storeMock->expects($this->any())->method('getId')->will($this->returnValue(1));
     $this->_storeManagerMock->expects($this->once())->method('getStores')->with(true)->will($this->returnValue(array($storeMock)));
     $this->_localeDateMock->expects($this->once())->method('scopeTimeStamp')->with($storeMock)->will($this->returnValue(32000));
     $indexerMock = $this->getMock('Magento\\Indexer\\Model\\Indexer', array(), array(), '', 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', array(), '', false, true, true, array('__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->refreshSpecialPrices();
 }
 public function testAfterDeleteEavCache()
 {
     $this->eavConfigMock->expects($this->once())->method('clear');
     $this->_model->afterDelete();
 }
Beispiel #28
0
 /**
  * Test method
  */
 public function testAfterDeleteEavCache()
 {
     $this->configMock->expects($this->once())->method('clear');
     $this->attribute->afterDelete();
 }
 /**
  * @return Config|\PHPUnit_Framework_MockObject_MockObject
  */
 protected function getEavConfigMock()
 {
     $this->eavConfigMock->expects($this->at(0))->method('getEntityType')->with('customer')->willReturn($this->getTypeCustomerMock());
     $this->eavConfigMock->expects($this->at(1))->method('getEntityType')->with('customer_address')->willReturn($this->getTypeAddressMock());
     return $this->eavConfigMock;
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Cannot retrieve attribute for entity type "invalid_type"
  */
 public function testInvalidAttributeRetrieve()
 {
     $invalidEntityType = 'invalid_type';
     $this->config->expects($this->once())->method('getAttribute')->will($this->returnValue(false));
     $this->storeViewService->doesEntityHaveOverriddenUrlKeyForStore(1, 1, $invalidEntityType);
 }