Skip to content

Commit 7faae35

Browse files
committed
MC-29102: [2.4.x] [Magento Cloud] Customer receives newsletter unsubscription email after registering for new account
1 parent f86e831 commit 7faae35

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Controller\Ajax;
9+
10+
use Magento\TestFramework\TestCase\AbstractController;
11+
12+
/**
13+
* Test Subscriber status ajax
14+
*/
15+
class StatusTest extends AbstractController
16+
{
17+
const STATUS_NOT_SUBSCRIBED = '"subscribed":false';
18+
19+
/**
20+
* Check newsletter subscription status verification
21+
*
22+
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
23+
* @dataProvider ajaxSubscriberDataProvider
24+
* @param string $email
25+
* @param string $expected
26+
*
27+
* @return void
28+
*/
29+
public function testExecute(string $email, string $expected): void
30+
{
31+
$this->getRequest()->setParam('email', $email);
32+
$this->dispatch('newsletter/ajax/status');
33+
$actual = $this->getResponse()->getBody();
34+
35+
$this->assertContains($expected, $actual);
36+
}
37+
38+
/**
39+
* Provides data and Expected Result
40+
*
41+
* @param void
42+
* @return array
43+
*/
44+
public function ajaxSubscriberDataProvider(): array
45+
{
46+
return [
47+
[
48+
'',
49+
self::STATUS_NOT_SUBSCRIBED,
50+
],
51+
[
52+
53+
self::STATUS_NOT_SUBSCRIBED,
54+
],
55+
[
56+
57+
self::STATUS_NOT_SUBSCRIBED,
58+
],
59+
[
60+
61+
'"subscribed":true',
62+
],
63+
[
64+
65+
self::STATUS_NOT_SUBSCRIBED,
66+
],
67+
];
68+
}
69+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'squire',
8+
'ko',
9+
'jquery',
10+
'mage/validation'
11+
], function (Squire, ko, $) {
12+
'use strict';
13+
14+
var injector = new Squire(),
15+
obj,
16+
checkbox,
17+
emailElem,
18+
button,
19+
resolveStatus = ko.observable(true),
20+
resolverMock = jasmine.createSpy('subscription-status-resolver', function (email, deferred) {
21+
deferred.resolve(resolveStatus());
22+
}).and.callThrough(),
23+
mocks = {
24+
'Magento_Newsletter/js/subscription-status-resolver': resolverMock
25+
};
26+
27+
describe('Magento_Newsletter/js/newsletter-sign-up', function () {
28+
beforeEach(function (done) {
29+
checkbox = $('<input type="checkbox" class="checkbox" name="is_subscribed" id="is_subscribed"/>');
30+
emailElem = $('<input type="email" name="email" id="email_address"/>');
31+
button = $('<button type="submit" id="button"/>');
32+
$(document.body).append(checkbox).append(emailElem).append(button);
33+
34+
injector.mock(mocks);
35+
injector.require(['Magento_Newsletter/js/newsletter-sign-up'], function (Constr) {
36+
obj = new Constr({
37+
provider: 'provName',
38+
name: '',
39+
index: '',
40+
submitButton: '#button',
41+
signUpElement: '#is_subscribed'
42+
}, '#email_address');
43+
done();
44+
});
45+
});
46+
47+
afterEach(function () {
48+
try {
49+
injector.clean();
50+
injector.remove();
51+
} catch (e) {}
52+
53+
checkbox.remove();
54+
emailElem.remove();
55+
button.remove();
56+
});
57+
58+
it('Check for properties defined', function() {
59+
expect(obj.hasOwnProperty('submitButton')).toBeDefined();
60+
expect(typeof obj.submitButton).toEqual('string');
61+
expect(obj.hasOwnProperty('signUpElement')).toBeDefined();
62+
expect(typeof obj.signUpElement).toEqual('string');
63+
expect(obj.hasOwnProperty('element')).toBeDefined();
64+
expect(typeof obj.element).toEqual('string');
65+
});
66+
67+
it('Verify Subscription is checked', function() {
68+
emailElem.val('[email protected]');
69+
checkbox.prop('checked', true);
70+
expect(checkbox.is(':checked')).toBeTruthy();
71+
72+
obj.updateSignUpStatus();
73+
74+
expect(resolverMock).not.toHaveBeenCalled();
75+
expect(button.is(':disabled')).toBeFalsy();
76+
expect(checkbox.is(':checked')).toBeTruthy();
77+
});
78+
79+
it('Verify sign-up process without email', function() {
80+
checkbox.prop('checked', false);
81+
expect(checkbox.is(':checked')).toBeFalsy();
82+
83+
obj.updateSignUpStatus();
84+
85+
expect(resolverMock).not.toHaveBeenCalled();
86+
expect(checkbox.is(':checked')).toBeFalsy();
87+
});
88+
89+
it('Verify sign-up process with incorrect email', function() {
90+
emailElem.val('emailexample.com');
91+
checkbox.prop('checked', false);
92+
expect(checkbox.is(':checked')).toBeFalsy();
93+
94+
obj.updateSignUpStatus();
95+
96+
expect(resolverMock).not.toHaveBeenCalled();
97+
expect(checkbox.is(':checked')).toBeFalsy();
98+
});
99+
100+
it('Verify Subscription with correct data', function() {
101+
emailElem.val('[email protected]');
102+
checkbox.prop('checked', false);
103+
expect(checkbox.is(':checked')).toBeFalsy();
104+
105+
obj.updateSignUpStatus();
106+
107+
expect(resolverMock).toHaveBeenCalled();
108+
expect(checkbox.is(':checked')).toBeTruthy();
109+
expect(button.is(':disabled')).toBeFalsy();
110+
});
111+
112+
it('Verify sign-up process with non-subscribed email', function() {
113+
resolveStatus(false);
114+
emailElem.val('[email protected]');
115+
checkbox.prop('checked', false);
116+
expect(checkbox.is(':checked')).toBeFalsy();
117+
118+
obj.updateSignUpStatus();
119+
120+
expect(resolverMock).toHaveBeenCalled();
121+
expect(checkbox.is(':checked')).toBeFalsy();
122+
});
123+
});
124+
});

0 commit comments

Comments
 (0)