Skip to content

Commit 345b70e

Browse files
committed
Covering the Share Wishist by integration test
1 parent 6d8e725 commit 345b70e

File tree

1 file changed

+92
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Wishlist/Controller

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\Wishlist\Controller;
9+
10+
use Magento\Customer\Model\Session;
11+
use Magento\Framework\App\Area;
12+
use Magento\Framework\Data\Form\FormKey;
13+
use Magento\Framework\Message\MessageInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use Magento\TestFramework\Request;
16+
use Magento\TestFramework\TestCase\AbstractController;
17+
18+
/**
19+
* @magentoAppIsolation enabled
20+
*/
21+
class ShareTest extends AbstractController
22+
{
23+
/**
24+
* Test share wishlist with correct data
25+
*
26+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
27+
*/
28+
public function testSuccessfullyShareWishlist()
29+
{
30+
$this->login(1);
31+
$this->prepareRequestData();
32+
$this->dispatch('wishlist/index/send/');
33+
34+
$this->assertSessionMessages(
35+
$this->equalTo(['Your wish list has been shared.']),
36+
MessageInterface::TYPE_SUCCESS
37+
);
38+
}
39+
40+
/**
41+
* Test share wishlist with incorrect data
42+
*
43+
* @magentoDataFixture Magento/Wishlist/_files/wishlist.php
44+
*/
45+
public function testShareWishlistWithoutEmails()
46+
{
47+
$this->login(1);
48+
$this->prepareRequestData(true);
49+
$this->dispatch('wishlist/index/send/');
50+
51+
$this->assertSessionMessages(
52+
$this->equalTo(['Please enter an email address.']),
53+
MessageInterface::TYPE_ERROR
54+
);
55+
}
56+
57+
/**
58+
* Login the user
59+
*
60+
* @param string $customerId Customer to mark as logged in for the session
61+
* @return void
62+
*/
63+
protected function login($customerId)
64+
{
65+
/** @var Session $session */
66+
$session = $this->_objectManager->get(Session::class);
67+
$session->loginById($customerId);
68+
}
69+
70+
/**
71+
* Prepares the request with data
72+
*
73+
* @param bool $invalidData
74+
* @return void
75+
*/
76+
private function prepareRequestData($invalidData = false)
77+
{
78+
Bootstrap::getInstance()->loadArea(Area::AREA_FRONTEND);
79+
$emails = !$invalidData ? 'email-1@example.com,email-1@example.com' : '';
80+
81+
/** @var FormKey $formKey */
82+
$formKey = $this->_objectManager->get(FormKey::class);
83+
$post = [
84+
'emails' => $emails,
85+
'message' => '',
86+
'form_key' => $formKey->getFormKey(),
87+
];
88+
89+
$this->getRequest()->setMethod(Request::METHOD_POST);
90+
$this->getRequest()->setPostValue($post);
91+
}
92+
}

0 commit comments

Comments
 (0)