public function setUp()
 {
     $this->subscriber = $this->getMockBuilder('\\Magento\\Newsletter\\Model\\Subscriber')->setMethods(['loadByEmail', 'getId', 'delete', 'updateSubscription'])->disableOriginalConstructor()->getMock();
     $this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
     $this->plugin = $this->objectManager->getObject('Ebizmarts\\MageMonkey\\Model\\Plugin\\Subscriber', ['subscriberFactory' => $this->subscriberFactory]);
     $this->resource = $this->getMock('Magento\\Newsletter\\Model\\Resource\\Subscriber', ['loadByEmail', 'getIdFieldName', 'save', 'loadByCustomerData', 'received'], [], '', false);
 }
 public function setUp()
 {
     $this->subscriberFactory = $this->getMockBuilder('\\Magento\\Newsletter\\Model\\SubscriberFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->subscriber = $this->getMockBuilder('\\Magento\\Newsletter\\Model\\Subscriber')->setMethods(['loadByEmail', 'getId', 'delete', 'updateSubscription'])->disableOriginalConstructor()->getMock();
     $this->subscriberFactory->expects($this->any())->method('create')->willReturn($this->subscriber);
     $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->plugin = $this->objectManager->getObject('Magento\\Newsletter\\Model\\Plugin\\CustomerPlugin', ['subscriberFactory' => $this->subscriberFactory]);
 }
Esempio n. 3
0
 public function testToHtmlWithSubscriber()
 {
     $this->request->expects($this->any())->method('getParam')->willReturnMap([['id', null, 2], ['store', null, 1], ['subscriber', null, 3]]);
     $subscriber = $this->getMock('Magento\\Newsletter\\Model\\Subscriber', [], [], '', false);
     $subscriber->expects($this->atLeastOnce())->method('load')->with(3)->willReturnSelf();
     $this->subscriberFactory->expects($this->atLeastOnce())->method('create')->willReturn($subscriber);
     $this->template->expects($this->atLeastOnce())->method('emulateDesign')->with(1);
     $this->template->expects($this->atLeastOnce())->method('revertDesign');
     $this->appState->expects($this->atLeastOnce())->method('emulateAreaCode')->with(\Magento\Newsletter\Model\Template::DEFAULT_DESIGN_AREA, [$this->template, 'getProcessedTemplate'], [['subscriber' => $subscriber]])->willReturn('Processed Template');
     $this->assertEquals('Processed Template', $this->preview->toHtml());
 }
Esempio n. 4
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteWithNewCustomerAndException()
 {
     $subscription = 'false';
     $postValue = ['customer' => ['coolness' => false, 'disable_auto_group_change' => 'false'], 'subscription' => $subscription];
     $filteredData = ['coolness' => false, 'disable_auto_group_change' => 'false'];
     /** @var AttributeMetadataInterface|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $attributeMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface')->disableOriginalConstructor()->getMock();
     $attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('coolness');
     $attributeMock->expects($this->once())->method('getFrontendInput')->willReturn('int');
     $attributes = [$attributeMock];
     $this->requestMock->expects($this->exactly(2))->method('getPostValue')->willReturn($postValue);
     $this->requestMock->expects($this->exactly(2))->method('getPost')->willReturnMap([['customer', null, $postValue['customer']], ['address', null, null]]);
     /** @var \Magento\Customer\Model\Metadata\Form|\PHPUnit_Framework_MockObject_MockObject $formMock */
     $formMock = $this->getMockBuilder('Magento\\Customer\\Model\\Metadata\\Form')->disableOriginalConstructor()->getMock();
     $this->formFactoryMock->expects($this->once())->method('create')->with(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, 'adminhtml_customer', [], false, \Magento\Customer\Model\Metadata\Form::DONT_IGNORE_INVISIBLE)->willReturn($formMock);
     $formMock->expects($this->once())->method('extractData')->with($this->requestMock, 'customer')->willReturn($filteredData);
     /** @var \Magento\Framework\DataObject|\PHPUnit_Framework_MockObject_MockObject $objectMock */
     $objectMock = $this->getMockBuilder('Magento\\Framework\\DataObject')->disableOriginalConstructor()->getMock();
     $this->objectFactoryMock->expects($this->once())->method('create')->with(['data' => $postValue])->willReturn($objectMock);
     $objectMock->expects($this->once())->method('getData')->with('customer')->willReturn($postValue['customer']);
     $formMock->expects($this->once())->method('getAttributes')->willReturn($attributes);
     /** @var \Magento\Customer\Api\Data\CustomerInterface|\PHPUnit_Framework_MockObject_MockObject $customerMock */
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->disableOriginalConstructor()->getMock();
     $this->customerDataFactoryMock->expects($this->once())->method('create')->willReturn($customerMock);
     $exception = new \Exception(__('Exception'));
     $this->managementMock->expects($this->once())->method('createAccount')->with($customerMock, null, '')->willThrowException($exception);
     $customerMock->expects($this->never())->method('getId');
     $this->authorizationMock->expects($this->never())->method('isAllowed');
     $this->subscriberFactoryMock->expects($this->never())->method('create');
     $this->sessionMock->expects($this->never())->method('unsCustomerData');
     $this->registryMock->expects($this->never())->method('register');
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->messageManagerMock->expects($this->once())->method('addException')->with($exception, __('Something went wrong while saving the customer.'));
     $this->sessionMock->expects($this->once())->method('setCustomerData')->with($postValue);
     /** @var Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */
     $redirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock();
     $this->redirectFactoryMock->expects($this->once())->method('create')->with([])->willReturn($redirectMock);
     $redirectMock->expects($this->once())->method('setPath')->with('customer/*/new', ['_current' => true])->willReturn(true);
     $this->assertEquals($redirectMock, $this->model->execute());
 }