1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Customer\Controller;
use Magento\TestFramework\TestCase\AbstractController;
use Magento\Customer\Api\AccountManagementInterface;
use Magento\Framework\Data\Form\FormKey;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Customer\Model\Session;
use Psr\Log\LoggerInterface;
class SendTest extends AbstractController
{
/** @var AccountManagementInterface */
private $accountManagement;
/** @var FormKey */
private $formKey;
/**
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function setUp()
{
parent::setUp();
$logger = $this->createMock(LoggerInterface::class);
$session = Bootstrap::getObjectManager()->create(
Session::class,
[$logger]
);
$this->accountManagement = Bootstrap::getObjectManager()->create(AccountManagementInterface::class);
$this->formKey = Bootstrap::getObjectManager()->create(FormKey::class);
$customer = $this->accountManagement->authenticate('customer@example.com', 'password');
$session->setCustomerDataAsLoggedIn($customer);
}
/**
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testExecutePost()
{
$this->getRequest()
->setMethod('POST')
->setPostValue(
[
'form_key' => $this->formKey->getFormKey(),
'emails' => 'example1@gmail.com, example2@gmail.com, example3@gmail.com'
]
);
$this->dispatch('wishlist/index/send');
$this->assertRedirect($this->stringContains('wishlist/index/index'));
$this->assertSessionMessages(
$this->equalTo(['Your wish list has been shared.']),
\Magento\Framework\Message\MessageInterface::TYPE_SUCCESS
);
}
/**
* @magentoAppIsolation enabled
* @magentoConfigFixture default_store customer/captcha/enable 1
* @magentoConfigFixture default_store customer/captcha/failed_attempts_login 0
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoConfigFixture default_store customer/captcha/forms user_forgotpassword,user_login,share_wishlist_form
*
*/
public function testCaptchaFailed()
{
$this->getRequest()
->setMethod('POST')
->setPostValue(
[
'form_key' => $this->formKey->getFormKey(),
'emails' => 'example1@gmail.com, example2@gmail.com, example3@gmail.com',
'captcha' => [
'share_wishlist_form' => 'wrong_captcha_word'
]
]
);
$this->dispatch('wishlist/index/send');
$this->assertRedirect($this->stringContains('wishlist/index/share'));
$this->assertSessionMessages(
$this->equalTo(['Incorrect CAPTCHA']),
\Magento\Framework\Message\MessageInterface::TYPE_ERROR
);
}
}