diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index dcb6341a7a8dd..76d55de5954b1 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -419,7 +419,6 @@ public function subscribe($email) self::XML_PATH_CONFIRMATION_FLAG, \Magento\Store\Model\ScopeInterface::SCOPE_STORE ) == 1 ? true : false; - $isOwnSubscribes = false; $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $email; @@ -428,13 +427,7 @@ public function subscribe($email) || $this->getStatus() == self::STATUS_NOT_ACTIVE ) { if ($isConfirmNeed === true) { - // if user subscribes own login email - confirmation is not needed - $isOwnSubscribes = $isSubscribeOwnEmail; - if ($isOwnSubscribes == true) { - $this->setStatus(self::STATUS_SUBSCRIBED); - } else { - $this->setStatus(self::STATUS_NOT_ACTIVE); - } + $this->setStatus(self::STATUS_NOT_ACTIVE); } else { $this->setStatus(self::STATUS_SUBSCRIBED); } @@ -460,9 +453,7 @@ public function subscribe($email) try { /* Save model before sending out email */ $this->save(); - if ($isConfirmNeed === true - && $isOwnSubscribes === false - ) { + if ($isConfirmNeed === true) { $this->sendConfirmationRequestEmail(); } else { $this->sendConfirmationSuccessEmail(); diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php index 39beade9346d4..1318cb1f98f58 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php @@ -5,6 +5,8 @@ */ namespace Magento\Newsletter\Test\Unit\Model; +use Magento\Newsletter\Model\Subscriber; + /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ @@ -116,7 +118,7 @@ public function testSubscribe() $email = 'subscriber_email@magento.com'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn( [ - 'subscriber_status' => 3, + 'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED, 'subscriber_email' => $email, 'name' => 'subscriber_name' ] @@ -133,7 +135,7 @@ public function testSubscribe() $this->sendEmailCheck(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); - $this->assertEquals(1, $this->subscriber->subscribe($email)); + $this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email)); } public function testSubscribeNotLoggedIn() @@ -141,7 +143,7 @@ public function testSubscribeNotLoggedIn() $email = 'subscriber_email@magento.com'; $this->resource->expects($this->any())->method('loadByEmail')->willReturn( [ - 'subscriber_status' => 3, + 'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED, 'subscriber_email' => $email, 'name' => 'subscriber_name' ] @@ -158,7 +160,7 @@ public function testSubscribeNotLoggedIn() $this->sendEmailCheck(); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); - $this->assertEquals(2, $this->subscriber->subscribe($email)); + $this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->subscribe($email)); } public function testUpdateSubscription() @@ -175,7 +177,7 @@ public function testUpdateSubscription() ->willReturn( [ 'subscriber_id' => 1, - 'subscriber_status' => 1 + 'subscriber_status' => Subscriber::STATUS_SUBSCRIBED ] ); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); @@ -210,7 +212,7 @@ public function testUnsubscribeCustomerById() ->willReturn( [ 'subscriber_id' => 1, - 'subscriber_status' => 1 + 'subscriber_status' => Subscriber::STATUS_SUBSCRIBED ] ); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); @@ -236,7 +238,7 @@ public function testSubscribeCustomerById() ->willReturn( [ 'subscriber_id' => 1, - 'subscriber_status' => 3 + 'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED ] ); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); @@ -262,7 +264,7 @@ public function testSubscribeCustomerById1() ->willReturn( [ 'subscriber_id' => 1, - 'subscriber_status' => 3 + 'subscriber_status' => Subscriber::STATUS_UNSUBSCRIBED ] ); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); @@ -276,7 +278,7 @@ public function testSubscribeCustomerById1() $this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true); $this->subscriber->subscribeCustomerById($customerId); - $this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus()); + $this->assertEquals(Subscriber::STATUS_NOT_ACTIVE, $this->subscriber->getStatus()); } public function testSubscribeCustomerByIdAfterConfirmation() @@ -293,7 +295,7 @@ public function testSubscribeCustomerByIdAfterConfirmation() ->willReturn( [ 'subscriber_id' => 1, - 'subscriber_status' => 4 + 'subscriber_status' => Subscriber::STATUS_UNCONFIRMED ] ); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); @@ -305,7 +307,7 @@ public function testSubscribeCustomerByIdAfterConfirmation() $this->scopeConfig->expects($this->atLeastOnce())->method('getValue')->with()->willReturn(true); $this->subscriber->updateSubscription($customerId); - $this->assertEquals(\Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus()); + $this->assertEquals(Subscriber::STATUS_SUBSCRIBED, $this->subscriber->getStatus()); } public function testUnsubscribe()