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)); }
public function testSubscribeNotLoggedIn() { $email = '*****@*****.**'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn(['subscriber_status' => 3, 'subscriber_email' => $email, 'name' => 'subscriber_name']); $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(false); $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->sendEmailCheck(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $this->assertEquals(2, $this->subscriber->subscribe($email)); }