protected function setUp() { $this->productCollection = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $this->productCollectionFactory = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->productCollectionFactory->expects($this->once())->method('create')->willReturn($this->productCollection); $this->attributeSetFinder = (new ObjectManager($this))->getObject(AttributeSetFinder::class, ['productCollectionFactory' => $this->productCollectionFactory]); }
/** * @return void */ protected function setUp() { $this->objectManager = new ObjectManager($this); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->setMethods(['toArray', 'isLoaded', 'addAttributeToFilter', 'load', 'getSize', 'addFilterByRequiredOptions', 'addStoreFilter'])->getMock(); $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->collectionFactoryMock->expects($this->any())->method('create')->willReturn($this->collectionMock); $this->dataHelperMock = $this->getMockBuilder(Data::class)->disableOriginalConstructor()->setMethods(['getAllowedSelectionTypes'])->getMock(); }
public function testGetDisabledCount() { $statusDisabled = 2; $productsMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', [], [], '', false); $this->productsFactoryMock->expects($this->once())->method('create')->willReturn($productsMock); $productsMock->expects($this->once())->method('addAttributeToFilter')->with('status', $statusDisabled)->willReturnSelf(); $productsMock->expects($this->once())->method('getSize')->willReturn('expected'); $this->assertEquals('expected', $this->model->getCount($statusDisabled)); }
protected function setUp() { $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->collectionMock = $this->getMockBuilder(AbstractCollection::class)->disableOriginalConstructor()->setMethods(['load', 'getSelect', 'getTable', 'getIterator', 'isLoaded', 'toArray', 'getSize'])->getMockForAbstractClass(); $this->dbSelectMock = $this->getMockBuilder(DbSelect::class)->disableOriginalConstructor()->getMock(); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->dataProvider = $this->objectManagerHelper->getObject(ProductCustomOptionsDataProvider::class, ['collectionFactory' => $this->collectionFactoryMock, 'request' => $this->requestMock]); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); $this->poolMock = $this->getMockBuilder(Pool::class)->disableOriginalConstructor()->getMock(); $this->modifierMockOne = $this->getMockBuilder(ModifierInterface::class)->setMethods(['getData', 'getMeta'])->getMockForAbstractClass(); $this->model = $this->objectManager->getObject(ProductDataProvider::class, ['name' => 'testName', 'primaryFieldName' => 'testPrimaryFieldName', 'requestFieldName' => 'testRequestFieldName', 'collectionFactory' => $this->collectionFactoryMock, 'pool' => $this->poolMock]); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->productRepositoryMock = $this->getMockBuilder(ProductRepositoryInterface::class)->getMockForAbstractClass(); $this->productLinkRepositoryMock = $this->getMockBuilder(ProductLinkRepositoryInterface::class)->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass(); $this->collectionMock = $this->getMockBuilder(Collection::class)->disableOriginalConstructor()->getMock(); $this->collectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)->setMethods(['create'])->disableOriginalConstructor()->getMock(); $this->productRepositoryMock->expects($this->any())->method('getById')->willReturn($this->productMock); $this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); }
/** * Test public `createCollection` method and protected `getPageSize` method via `createCollection` * * @param bool $pagerEnable * @param int $productsCount * @param int $productsPerPage * @param int $expectedPageSize * @dataProvider createCollectionDataProvider */ public function testCreateCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize) { $this->visibility->expects($this->once())->method('getVisibleInCatalogIds')->willReturn([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH]); $collection = $this->getMockBuilder('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->setMethods(['setVisibility', 'addMinimalPrice', 'addFinalPrice', 'addTaxPercents', 'addAttributeToSelect', 'addUrlRewrite', 'addStoreFilter', 'setPageSize', 'setCurPage'])->disableOriginalConstructor()->getMock(); $collection->expects($this->once())->method('setVisibility')->with([Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH])->willReturnSelf(); $collection->expects($this->once())->method('addMinimalPrice')->willReturnSelf(); $collection->expects($this->once())->method('addFinalPrice')->willReturnSelf(); $collection->expects($this->once())->method('addTaxPercents')->willReturnSelf(); $collection->expects($this->once())->method('addAttributeToSelect')->willReturnSelf(); $collection->expects($this->once())->method('addUrlRewrite')->willReturnSelf(); $collection->expects($this->once())->method('addStoreFilter')->willReturnSelf(); $collection->expects($this->once())->method('setPageSize')->with($expectedPageSize)->willReturnSelf(); $collection->expects($this->once())->method('setCurPage')->willReturnSelf(); $this->collectionFactory->expects($this->once())->method('create')->willReturn($collection); $this->productsList->setData('conditions_encoded', 'some_serialized_conditions'); $conditions = $this->getMockBuilder('\\Magento\\Rule\\Model\\Condition\\Combine')->setMethods(['collectValidatedAttributes'])->disableOriginalConstructor()->getMock(); $conditions->expects($this->once())->method('collectValidatedAttributes')->with($collection)->willReturnSelf(); $this->builder->expects($this->once())->method('attachConditionToCollection')->with($collection, $conditions)->willReturnSelf(); $this->rule->expects($this->once())->method('loadPost')->willReturnSelf(); $this->rule->expects($this->once())->method('getConditions')->willReturn($conditions); if ($productsPerPage) { $this->productsList->setData('products_per_page', $productsPerPage); } else { $this->productsList->unsetData('products_per_page'); } $this->productsList->setData('show_pager', $pagerEnable); $this->productsList->setData('products_count', $productsCount); $this->assertSame($collection, $this->productsList->createCollection()); }
public function testExecutePageRequested() { $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(['placeholder' => true]); $this->request->expects($this->any())->method('getParams')->willReturn(['namespace' => 'product_listing', 'exclude' => true, 'filters' => ['placeholder' => true]]); $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn([1, 2, 3]); $this->attributeHelper->expects($this->any())->method('setProductIds')->with([1, 2, 3]); $collection = $this->getMockBuilder('Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection')->setMethods(['getAllIds'])->disableOriginalConstructor()->getMock(); $collection->expects($this->any())->method('getAllIds')->willReturn([1, 2, 3]); $this->filter->expects($this->any())->method('getCollection')->with($collection)->willReturn($collection); $this->collectionFactory->expects($this->any())->method('create')->willReturn($collection); $title = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Title')->setMethods(['prepend'])->disableOriginalConstructor()->getMock(); $config = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->setMethods(['getTitle'])->disableOriginalConstructor()->getMock(); $config->expects($this->any())->method('getTitle')->willReturn($title); $this->resultPage->expects($this->any())->method('getConfig')->willReturn($config); $this->assertSame($this->resultPage, $this->object->execute()); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { parent::setUp(); $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false); $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false); $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection)); $item = new \Magento\Framework\DataObject(['id' => 1, 'attribute_set_name' => 'Default', '_attribute_set' => 'Default']); $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([$item])); $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false); $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection', ['setAttributeSetFilter'], [], '', false); $superAttributes = []; foreach ($this->_getSuperAttributes() as $superAttribute) { $item = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isStatic'], $superAttribute, '', false); $item->setData($superAttribute); $item->method('isStatic')->will($this->returnValue(false)); $superAttributes[] = $item; } $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attrCollection)); $this->attrCollection->expects($this->any())->method('setAttributeSetFilter')->will($this->returnValue($superAttributes)); $this->_entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getConnection', 'getAttrSetIdToName', 'getErrorAggregator', 'getAttributeOptions'], [], '', false); $this->_entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject()); $this->params = [0 => $this->_entityModel, 1 => 'configurable']; $this->_connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false); $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false); $this->select->expects($this->any())->method('from')->will($this->returnSelf()); $this->select->expects($this->any())->method('where')->will($this->returnSelf()); $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf()); $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select)); $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false); $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query')); $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock); $this->_connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf(); $this->_connection->expects($this->any())->method('delete')->willReturnSelf(); $this->_connection->expects($this->any())->method('quoteInto')->willReturn(''); $this->_connection->expects($this->any())->method('fetchAll')->will($this->returnValue([])); $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false); $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection)); $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName')); $this->_entityModel->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection)); $this->productCollectionFactory = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false); $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addFieldToFilter', 'addAttributeToSelect'], [], '', false); $products = []; $testProducts = [['id' => 1, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 2, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 20, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1]]; foreach ($testProducts as $product) { $item = $this->getMock('\\Magento\\Framework\\DataObject', ['getAttributeSetId'], [], '', false); $item->setData($product); $item->expects($this->any())->method('getAttributeSetId')->willReturn(4); $products[] = $item; } $this->productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->productCollection)); $this->productCollection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($this->productCollection)); $this->productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnValue($products)); $this->_entityModel->expects($this->any())->method('getAttributeOptions')->will($this->returnValue(['attr2val1' => '1', 'attr2val2' => '2', 'attr2val3' => '3', 'testattr3v1' => '4', 'testattr30v1' => '4', 'testattr3v2' => '5', 'testattr3v3' => '6'])); $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableImportExport\\Model\\Import\\Product\\Type\\Configurable', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'resource' => $this->resource, 'productColFac' => $this->productCollectionFactory]); }
protected function prepareVariationCollection() { $this->productCollectionFactoryMock->expects($this->any())->method('create')->willReturn($this->productCollectionMock); $this->addfilterByParent(); }