public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', [], [], '', false); $resultRedirectFactory = $this->getMock('Magento\\Backend\\Model\\View\\Result\\RedirectFactory', [], [], '', false); $this->responseMock = $this->getMock('Magento\\Framework\\App\\ResponseInterface', [], [], '', false); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false); $this->customerCollectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $this->customerCollectionFactoryMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\CollectionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $redirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $resultFactoryMock->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($redirectMock); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirectMock); $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->once())->method('getResponse')->willReturn($this->responseMock); $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); $this->contextMock->expects($this->any())->method('getResultRedirectFactory')->willReturn($resultRedirectFactory); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($resultFactoryMock); $this->filterMock = $this->getMock('Magento\\Ui\\Component\\MassAction\\Filter', [], [], '', false); $this->filterMock->expects($this->once())->method('getCollection')->with($this->customerCollectionMock)->willReturnArgument(0); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->customerCollectionMock); $this->customerRepositoryMock = $this->getMockBuilder('Magento\\Customer\\Api\\CustomerRepositoryInterface')->getMockForAbstractClass(); $this->massAction = $objectManagerHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\MassAssignGroup', ['context' => $this->contextMock, 'filter' => $this->filterMock, 'collectionFactory' => $this->customerCollectionFactoryMock, 'customerRepository' => $this->customerRepositoryMock]); }
/** * @param CollectionFactory $customerCollectionFactory * @param Encryptor $encryptor */ public function __construct(CollectionFactory $customerCollectionFactory, Encryptor $encryptor) { parent::__construct(); $this->customerCollectionFactory = $customerCollectionFactory; $this->collection = $customerCollectionFactory->create(); $this->encryptor = $encryptor; }
public function testGetCount() { $customersMock = $this->getMock('\\Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection', [], [], '', false); $this->customersFactoryMock->expects($this->once())->method('create')->willReturn($customersMock); $customersMock->expects($this->once())->method('getSize')->willReturn('expected'); $this->assertEquals('expected', $this->model->getCount()); }
/** * Constructor * * @param string $name * @param string $primaryFieldName * @param string $requestFieldName * @param EavValidationRules $eavValidationRules * @param CustomerCollectionFactory $customerCollectionFactory * @param Config $eavConfig * @param FilterPool $filterPool * @param array $meta * @param array $data */ public function __construct($name, $primaryFieldName, $requestFieldName, EavValidationRules $eavValidationRules, CustomerCollectionFactory $customerCollectionFactory, Config $eavConfig, FilterPool $filterPool, array $meta = [], array $data = []) { parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data); $this->eavValidationRules = $eavValidationRules; $this->collection = $customerCollectionFactory->create(); $this->collection->addAttributeToSelect('*'); $this->eavConfig = $eavConfig; $this->filterPool = $filterPool; $this->meta['customer']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer')); $this->meta['address']['fields'] = $this->getAttributesMeta($this->eavConfig->getEntityType('customer_address')); }
/** * Execute action * * @return \Magento\Backend\Model\View\Result\Redirect * @throws \Magento\Framework\Exception\LocalizedException|\Exception */ public function execute() { try { $collection = $this->filter->getCollection($this->collectionFactory->create()); return $this->massAction($collection); } catch (\Exception $e) { $this->messageManager->addError($e->getMessage()); /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); return $resultRedirect->setPath($this->redirectUrl); } }
public function testGetDataWithCustomerFormData() { $customerId = 11; $customerFormData = ['customer' => ['email' => '*****@*****.**', 'default_billing' => 3, 'default_shipping' => 3, 'entity_id' => $customerId], 'address' => [3 => ['firstname' => 'firstname1', 'lastname' => 'lastname1', 'street' => ['street1', 'street2'], 'default_billing' => 3, 'default_shipping' => 3]]]; $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $address = $this->getMockBuilder('Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->getMock(); $collectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*'); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('getItems')->willReturn([$customer]); $customer->expects($this->once())->method('getData')->willReturn(['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2]); $customer->expects($this->once())->method('getId')->willReturn($customerId); $customer->expects($this->once())->method('getAddresses')->willReturn([$address]); $address->expects($this->atLeastOnce())->method('getId')->willReturn(2); $address->expects($this->once())->method('load')->with(2)->willReturnSelf(); $address->expects($this->once())->method('getData')->willReturn(['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => "street\nstreet"]); $helper = new ObjectManager($this); $dataProvider = $helper->getObject('\\Magento\\Customer\\Model\\Customer\\DataProvider', ['name' => 'test-name', 'primaryFieldName' => 'primary-field-name', 'requestFieldName' => 'request-field-name', 'eavValidationRules' => $this->eavValidationRulesMock, 'customerCollectionFactory' => $this->customerCollectionFactoryMock, 'eavConfig' => $this->getEavConfigMock()]); $reflection = new \ReflectionClass(get_class($dataProvider)); $reflectionProperty = $reflection->getProperty('session'); $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($dataProvider, $this->sessionMock); $this->sessionMock->expects($this->once())->method('getCustomerFormData')->willReturn($customerFormData); $this->sessionMock->expects($this->once())->method('unsCustomerFormData'); $this->assertEquals([$customerId => $customerFormData], $dataProvider->getData()); }
/** * Get shared items collection count * * @return int */ public function getSharedCount() { /** @var $collection \Magento\Customer\Model\ResourceModel\Customer\Collection */ $collection = $this->_customerResFactory->create(); $countSelect = $collection->getSelectCountSql(); $countSelect->joinLeft(['wt' => $this->getWishlistTable()], 'wt.customer_id = e.entity_id', [])->where('wt.shared > 0')->group('wt.wishlist_id'); return $countSelect->getConnection()->fetchOne($countSelect); }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $this->collection = $this->customerCollectionFactory->create(); $this->collection->addAttributeToSelect('*'); $customerCollection = $this->collection->getItems(); /** @var $customer Customer */ foreach ($customerCollection as $customer) { $customer->load($customer->getId()); if (!$this->encryptor->validateHashVersion($customer->getPasswordHash())) { list($hash, $salt, $version) = explode(Encryptor::DELIMITER, $customer->getPasswordHash(), 3); $version .= Encryptor::DELIMITER . Encryptor::HASH_VERSION_LATEST; $customer->setPasswordHash($this->encryptor->getHash($hash, $salt, $version)); $customer->save(); $output->write("."); } } $output->writeln("."); $output->writeln("<info>Finished</info>"); }
/** * Contact constructor. * * @param \Dotdigitalgroup\Email\Model\ProccessorFactory $proccessorFactory * @param CustomerFactory $customerFactory * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\App\ResourceConnection $resource * @param \Dotdigitalgroup\Email\Helper\File $file * @param \Dotdigitalgroup\Email\Helper\Data $helper * @param \Dotdigitalgroup\Email\Helper\Config $config * @param \Magento\Backend\App\Action\Context $context * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface * @param \Dotdigitalgroup\Email\Model\ContactFactory $contactFactory * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollectionFactory * @param \Dotdigitalgroup\Email\Model\Resource\Contact\CollectionFactory $contactCollectionFactory */ public function __construct(\Dotdigitalgroup\Email\Model\ProccessorFactory $proccessorFactory, \Dotdigitalgroup\Email\Model\Apiconnector\CustomerFactory $customerFactory, \Magento\Framework\Registry $registry, \Magento\Framework\App\ResourceConnection $resource, \Dotdigitalgroup\Email\Helper\File $file, \Dotdigitalgroup\Email\Helper\Data $helper, \Dotdigitalgroup\Email\Helper\Config $config, \Magento\Backend\App\Action\Context $context, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, \Dotdigitalgroup\Email\Model\ContactFactory $contactFactory, \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollectionFactory, \Dotdigitalgroup\Email\Model\Resource\Contact\CollectionFactory $contactCollectionFactory) { $this->_proccessorFactory = $proccessorFactory; $this->_file = $file; $this->_config = $config; $this->_helper = $helper; $this->_registry = $registry; $this->_resource = $resource; $this->_scopeConfig = $scopeConfig; $this->_storeManager = $storeManagerInterface; $this->_messageManager = $context->getMessageManager(); //email contact $this->_emailCustomer = $customerFactory; $this->_contactFactory = $contactFactory; $this->_customerCollection = $customerCollectionFactory->create(); $this->_customerCollection->addAttributeToSelect('*'); //email contact collection $this->_contactCollection = $contactCollectionFactory->create(); $this->_contactCollection->addFieldToSelect('*'); //newsletter subscriber $this->_subscriberFactory = $subscriberFactory->create(); }
public function testGetData() { $customer = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock(); $address = $this->getMockBuilder('Magento\\Customer\\Model\\Address')->disableOriginalConstructor()->getMock(); $collectionMock = $this->getMockBuilder('Magento\\Customer\\Model\\ResourceModel\\Customer\\Collection')->disableOriginalConstructor()->getMock(); $collectionMock->expects($this->once())->method('addAttributeToSelect')->with('*'); $this->customerCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('getItems')->willReturn([$customer]); $customer->expects($this->once())->method('getData')->willReturn(['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2]); $customer->expects($this->once())->method('getAddresses')->willReturn([$address]); $address->expects($this->atLeastOnce())->method('getId')->willReturn(2); $address->expects($this->once())->method('load')->with(2)->willReturnSelf(); $address->expects($this->once())->method('getData')->willReturn(['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => "street\nstreet"]); $helper = new ObjectManager($this); $dataProvider = $helper->getObject('\\Magento\\Customer\\Model\\Customer\\DataProvider', ['name' => 'test-name', 'primaryFieldName' => 'primary-field-name', 'requestFieldName' => 'request-field-name', 'eavValidationRules' => $this->eavValidationRulesMock, 'customerCollectionFactory' => $this->customerCollectionFactoryMock, 'eavConfig' => $this->getEavConfigMock()]); $this->assertEquals(['' => ['customer' => ['email' => '*****@*****.**', 'default_billing' => 2, 'default_shipping' => 2], 'address' => [2 => ['firstname' => 'firstname', 'lastname' => 'lastname', 'street' => ['street', 'street'], 'default_billing' => 2, 'default_shipping' => 2]]]], $dataProvider->getData()); }
/** * @return \Magento\Customer\Model\ResourceModel\Customer\Collection */ protected function _createCustomersCollection() { return $this->_customersFactory->create(); }
/** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory * @param \Magento\CustomerImportExport\Model\Export\CustomerFactory $eavCustomerFactory * @param \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $eavConfig, \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory, \Magento\CustomerImportExport\Model\Export\CustomerFactory $eavCustomerFactory, \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory, array $data = []) { parent::__construct($scopeConfig, $storeManager, $collectionFactory, $resourceColFactory, $localeDate, $eavConfig, $data); $this->_customerCollection = isset($data['customer_collection']) ? $data['customer_collection'] : $customerColFactory->create(); $this->_customerEntity = isset($data['customer_entity']) ? $data['customer_entity'] : $eavCustomerFactory->create(); $this->_addressCollection = isset($data['address_collection']) ? $data['address_collection'] : $addressColFactory->create(); $this->_initWebsites(true); $this->setFileName($this->getEntityTypeCode()); }
/** * {@inheritdoc} */ public function getCount() { $customers = $this->customersFactory->create(); /** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $customers */ return $customers->getSize(); }
/** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory * @param array $data */ public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $eavConfig, \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory, array $data = []) { parent::__construct($scopeConfig, $storeManager, $collectionFactory, $resourceColFactory, $localeDate, $eavConfig, $data); $this->_customerCollection = isset($data['customer_collection']) ? $data['customer_collection'] : $customerColFactory->create(); $this->_initAttributeValues()->_initStores()->_initWebsites(true); }
/** * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $colIteratorFactory * @param array $data */ public function __construct(\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $colIteratorFactory, array $data = []) { $this->_customerCollection = isset($data['customer_collection']) ? $data['customer_collection'] : $collectionFactory->create(); $this->_pageSize = isset($data['page_size']) ? $data['page_size'] : 0; $this->_byPagesIterator = isset($data['collection_by_pages_iterator']) ? $data['collection_by_pages_iterator'] : $colIteratorFactory->create(); }