I am trying to write integration Test for my custom module that have very basic functionality to block the frontend page.
1 . created one controller to submit the password and on that basis we return the user on home page to allow access the sites and if failed on password then it keeps on the same password page
controller code like below
<?php
declare(strict_types=1);
namespace CustomWeb\FrontendStop\Controller\Index;
use CustomWeb\FrontendStop\Helper\Config;
use CustomWeb\FrontendStop\Service\FrontendStopCookie;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\ResultFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Message\ManagerInterface;
class Submit implements HttpPostActionInterface
{
public function __construct(
protected Config $helper,
protected FrontendStopCookie $service,
protected ResultFactory $resultFactory,
protected RequestInterface $request,
protected ManagerInterface $messageManager
) {
}
public function execute():ResultInterface
{
$password = $this->request->getParam('password');
$resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
if (empty($password)) {
$this->messageManager->addErrorMessage('Please provide a valid password.');
$resultRedirect->setUrl('/frontendblock/index/index');
return $resultRedirect;
}
if (!$this->helper->isValidPassword($password)) {
$this->messageManager->addErrorMessage('Please provide a valid password.');
$resultRedirect->setUrl('/frontendblock/index/index');
return $resultRedirect;
}
$this->service->setIsAuthenticated();
$this->messageManager->addSuccessMessage('Successfully Authenticated!');
$resultRedirect->setUrl('/home');
return $resultRedirect;
}
}
I would like to write the Integration Test for this class, for any help much appreciated.