Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 2
0
 /**
  * @magentoDataFixture Magento/Newsletter/_files/subscribers.php
  * @magentoDataFixture Magento/Customer/_files/two_customers.php
  */
 public function testLoadByCustomerDataWithoutCustomerId()
 {
     /** @var \Magento\Customer\Service\V1\CustomerAccountServiceInterface $customerAccountService */
     $customerAccountService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     $customerData = $customerAccountService->getCustomerDetails(2)->getCustomer();
     $result = $this->_resourceModel->loadByCustomerData($customerData);
     $this->assertEquals(0, $result['customer_id']);
     $this->assertEquals('*****@*****.**', $result['subscriber_email']);
 }
Ejemplo n.º 3
0
 /**
  * @magentoDataFixture Magento/Newsletter/_files/subscribers.php
  * @magentoDataFixture Magento/Customer/_files/two_customers.php
  */
 public function testLoadByCustomerDataWithoutCustomerId()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerData = $customerRepository->getById(2);
     $result = $this->_resourceModel->loadByCustomerData($customerData);
     $this->assertEquals(0, $result['customer_id']);
     $this->assertEquals('*****@*****.**', $result['subscriber_email']);
 }
Ejemplo n.º 4
0
 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));
 }