public function testAroundDeleteById() { $customerId = 1; $deleteCustomerById = function () { return true; }; $subject = $this->getMock('\\Magento\\Customer\\Api\\CustomerRepositoryInterface'); $customer = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface'); $subject->expects($this->once())->method('getById')->willReturn($customer); $customer->expects($this->once())->method('getEmail')->willReturn('*****@*****.**'); $this->subscriber->expects($this->once())->method('loadByEmail')->with('*****@*****.**')->willReturnSelf(); $this->subscriber->expects($this->once())->method('getId')->willReturn(1); $this->subscriber->expects($this->once())->method('delete')->willReturnSelf(); $this->assertEquals(true, $this->plugin->aroundDeleteById($subject, $deleteCustomerById, $customerId)); }
public function testSubscribe() { $email = '*****@*****.**'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']); $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field'); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true); $customerDataModel = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface'); $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel); $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1); $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email); $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel); $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1); $customerDataModel->expects($this->any())->method('getId')->willReturn(1); $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf(); $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf(); $storeModel = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('*****@*****.**'); $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); $storeModel->expects($this->any())->method('getId')->willReturn(1); $transport = $this->getMock('\\Magento\\Framework\\Mail\\TransportInterface'); $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); $transport->expects($this->any())->method('sendMessage')->willReturnSelf(); $inlineTranslation = $this->getMock('Magento\\Framework\\Translate\\Inline\\StateInterface'); $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $this->assertEquals(1, $this->subscriber->subscribe($email)); }
/** * Sends out confirmation success email * * @return $this */ public function sendConfirmationSuccessEmail() { if ($this->_scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS, 'store', $this->getStoreId())) { return $this; } else { return parent::sendConfirmationSuccessEmail(); } }
public function testExecute() { $customersIds = [10, 11, 12]; $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds); $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturnMap([[10, true], [11, true], [12, true]]); $this->subscriberMock->expects($this->any())->method('unsubscribeCustomerById')->willReturnMap([[10, true], [11, true], [12, true]]); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('A total of %1 record(s) were updated.', count($customersIds))); $this->resultRedirectMock->expects($this->any())->method('setPath')->with('customer/*/index')->willReturnSelf(); $this->massAction->execute(); }
/** * Get Customer Subscription Object Information * * @return \Magento\Newsletter\Model\Subscriber */ public function getSubscriptionObject() { if (!$this->_subscription) { $this->_subscription = $this->_createSubscriber(); $customer = $this->getCustomer(); if ($customer) { $this->_subscription->loadByEmail($customer->getEmail()); } } return $this->_subscription; }
public function testUnsubscribeCustomer() { //Creating customer and subscribe $customerData = $this->customerHelper->createSampleCustomer(["extension_attributes" => ["is_subscribed" => true]]); $this->assertNotNull($customerData['id']); $this->subscriber->loadByCustomerId($customerData['id']); $subscriptionId = $this->subscriber->getId(); $this->assertNotNull($subscriptionId); $this->assertEquals($customerData['id'], $this->subscriber->getCustomerId()); //Manage customer in order to unsubscribe $this->customerHelper->updateSampleCustomer(array_merge($customerData, ["extension_attributes" => ["is_subscribed" => false]]), $customerData["id"]); $this->initSubscriber(); $this->subscriber->loadByCustomerId($customerData['id']); $this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->subscriber->getStatus()); }
/** * Retrieve unsubsription url * * @param \Magento\Newsletter\Model\Subscriber $subscriber * @return string */ public function getUnsubscribeUrl($subscriber) { return $this->_urlBuilder->setScope($subscriber->getStoreId())->getUrl('newsletter/subscriber/unsubscribe', array('id' => $subscriber->getId(), 'code' => $subscriber->getCode(), '_nosid' => true)); }
/** * Updates data when subscriber received * * @param \Magento\Newsletter\Model\Subscriber $subscriber * @param \Magento\Newsletter\Model\Queue $queue * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ public function received(\Magento\Newsletter\Model\Subscriber $subscriber, \Magento\Newsletter\Model\Queue $queue) { $this->connection->beginTransaction(); try { $data['letter_sent_at'] = $this->_date->gmtDate(); $this->connection->update($this->_subscriberLinkTable, $data, ['subscriber_id = ?' => $subscriber->getId(), 'queue_id = ?' => $queue->getId()]); $this->connection->commit(); } catch (\Exception $e) { $this->connection->rollBack(); throw new \Magento\Framework\Exception\LocalizedException(__('We cannot mark as received subscriber.')); } return $this; }
/** * @param $customerId * @param $password * @param $confirmationStatus * @param $successUrl * @param $isSetFlag * @param $successMessage * * @dataProvider getSuccessRedirectDataProvider */ public function testSuccessRedirect($customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('regenerateId'); $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId)); $this->customerExtractorMock->expects($this->any())->method('extract')->with($this->equalTo('customer_account_create'), $this->equalTo($this->requestMock))->will($this->returnValue($this->customerMock)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true)); $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['password', null, $password], ['password_confirmation', null, $password], ['is_subscribed', false, true]]); $this->customerMock->expects($this->once())->method('setAddresses')->with($this->equalTo([]))->will($this->returnSelf()); $this->accountManagement->expects($this->once())->method('createAccount')->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password), '')->will($this->returnValue($this->customerMock)); $this->accountManagement->expects($this->once())->method('getConfirmationStatus')->with($this->equalTo($customerId))->will($this->returnValue($confirmationStatus)); $this->subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->will($this->returnSelf()); $this->urlMock->expects($this->any())->method('getUrl')->willReturnMap([['*/*/index', ['_secure' => true], $successUrl], ['*/*/create', ['_secure' => true], $successUrl]]); $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($successUrl))->will($this->returnValue($successUrl)); $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag)); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->model->execute(); }
/** * Add Subscriber Data * * @param \Magento\Newsletter\Model\Subscriber $subscriber * @return $this */ public function addSubscriberData(\Magento\Newsletter\Model\Subscriber $subscriber) { $this->setSubscriberId($subscriber->getId()); return $this; }
public function testReceived() { $queue = $this->getMockBuilder('\\Magento\\Newsletter\\Model\\Queue')->disableOriginalConstructor()->getMock(); $this->resource->expects($this->once())->method('received')->with($this->subscriber, $queue)->willReturnSelf(); $this->assertEquals($this->subscriber, $this->subscriber->received($queue)); }
public function aroundDelete(\Magento\Newsletter\Model\Subscriber $subscriber, \Closure $proceed) { $monkeyId = $subscriber->getMagemonkeyId(); $result = $proceed(); if ($monkeyId) { } $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper); $return = $api->listDeleteMember($this->_helper->getDefaultList(), $monkeyId); $result->setMagemonkeyId('')->save(); return $result; }