SendTest.php 3.1 KB

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