Skip to content

How to write integration test for below condition?

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 CustomWebFrontendStopControllerIndex;

use CustomWebFrontendStopHelperConfig;
use CustomWebFrontendStopServiceFrontendStopCookie;
use MagentoFrameworkAppActionHttpPostActionInterface;
use MagentoFrameworkAppRequestInterface;
use MagentoFrameworkControllerResultFactory;
use MagentoFrameworkControllerResultInterface;
use MagentoFrameworkMessageManagerInterface;

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.