Created
March 18, 2022 16:48
-
-
Save vishwac09/1af7d53c795220a214498c98ae83b838 to your computer and use it in GitHub Desktop.
AuthZeroServiceTest UnitTest Case implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\Tests\authzero\Unit; | |
use Drupal\authzero\Service\AuthZeroService; | |
use Drupal\Core\Config\ConfigFactoryInterface; | |
use Drupal\Core\Config\ImmutableConfig; | |
use Drupal\Core\DependencyInjection\ContainerBuilder; | |
use Drupal\Tests\UnitTestCase; | |
use Symfony\Component\HttpFoundation\Request; | |
use Symfony\Component\HttpFoundation\RequestStack; | |
/** | |
* Test class for the AuthZeroService class. | |
* | |
* @group authzero_unit | |
*/ | |
class AuthZeroServiceTest extends UnitTestCase { | |
/** | |
* Instance of ConfigFactoryInterface. | |
* | |
* @var configFactory | |
*/ | |
private $configFactory; | |
/** | |
* Instance of ImmutableConfig. | |
* | |
* @var config | |
*/ | |
private $config; | |
/** | |
* Instance of AuthZeroService. | |
* | |
* @var authZeroService | |
*/ | |
private $authZeroService; | |
/** | |
* Do the initial setup. | |
*/ | |
public function setup(): void { | |
parent::setUp(); | |
$this->config = $this->prophesize(ImmutableConfig::class); | |
$this->config->get('domain')->willReturn('https://test.auth0.domain'); | |
$this->config->get('client_id')->willReturn('TEST_CLIENT_ID'); | |
// Initialize the ConfigFactoryInterface mock. | |
$this->configFactory = $this->prophesize(ConfigFactoryInterface::class); | |
// Will return instance of Immutable config. | |
$this->configFactory->get('authzero.settings')->willReturn($this->config->reveal()); | |
// Inject the mock of ConfigFactoryInterface. | |
$this->authZeroService = new AuthZeroService($this->configFactory->reveal()); | |
$container = new ContainerBuilder(); | |
\Drupal::setContainer($container); | |
$request = $this->prophesize(Request::class); | |
$request->getSchemeAndHttpHost()->willReturn('https://drupal.site'); | |
$requestStack = $this->prophesize(RequestStack::class); | |
$requestStack->getCurrentRequest()->willReturn($request->reveal()); | |
$container->set('request_stack', $requestStack->reveal()); | |
} | |
/** | |
* Check the function return type overrideLogout. | |
*/ | |
public function testGetLogoutLink() { | |
$config = $this->config->reveal(); | |
$link = 'https://%s/v2/logout?client_id=%s&federated=true&returnTo=%s?error_description=%s'; | |
$fullLink = sprintf( | |
$link, | |
$config->get('domain'), | |
$config->get('client_id'), | |
'https://drupal.site/auth0/login', | |
'' | |
); | |
$this->assertEquals($fullLink, $this->authZeroService->getLogoutLink()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment