Skip to content

Commit

Permalink
fix: vol 5955 operators no admin role toggle off (#531)
Browse files Browse the repository at this point in the history
* fix: amended type safety on operator admin

* fix: add in mock operator admin session for true usecase
  • Loading branch information
sdh100shaun authored Jan 2, 2025
1 parent b1096ab commit bc869e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ protected function alterForm(Form $form)

$termsAgreed->setLabel($label);

if ($this->consultantRegistrationSession->getOperatorAdmin() === false) {
if (($this->consultantRegistrationSession->getOperatorAdmin() ?? true) === false) {
$form->get('fields')->get('licenceNumber')->setValue($this->consultantRegistrationSession->getExistingLicence())->setAttribute('type', 'hidden');
$form->get('fields')->get('isLicenceHolder')->setValue('Y')->setAttribute('type', 'hidden');
$form->get('fields')->get('isLicenceHolder')->setLabel('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Olcs\Session;

use Laminas\Session\Container;

/**
* Class ConsultantRegistration
*
* @template-extends \Laminas\Session\Container<string, mixed>
*/
class ConsultantRegistration extends \Laminas\Session\Container
class ConsultantRegistration extends Container
{
public const SESSION_NAME = 'ConsultantRegistration';
protected const OPERATOR_DETAILS = 'operatorDetails';
Expand Down Expand Up @@ -38,7 +40,7 @@ public function setOperatorAdmin( bool $hasOperatorAdmin ): self
return $this;
}

public function getOperatorAdmin(): bool
public function getOperatorAdmin(): ?bool
{
return $this->offsetGet(self::OPERATOR_ADMIN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Controller\UserRegistrationController as Sut;
use Olcs\Session\ConsultantRegistration;
use ReflectionClass;
use LmcRbacMvc\Service\AuthorizationService;

Expand All @@ -40,6 +41,9 @@ class UserRegistrationControllerTest extends TestCase

private $mockFormatSaveDataMapper;

private $mockConsultantRegistrationSession;


public function setUp(): void
{
$this->sut = m::mock(Sut::class)
Expand All @@ -54,6 +58,9 @@ public function setUp(): void
$this->mockUrlHelper = m::mock(UrlHelperService::class)->makePartial();
$this->mockTranslationHelper = m::mock(TranslationHelperService::class)->makePartial();
$this->mockFormatSaveDataMapper = m::mock(CreateAccountMapper::class)->makePartial();
$this->mockConsultantRegistrationSession = m::mock(ConsultantRegistration::class)->makePartial();

$this->mockConsultantRegistrationSession->shouldReceive('getOperatorAdmin')->andReturn(true);

$reflectionClass = new ReflectionClass(Sut::class);
$this->setMockedProperties($reflectionClass, 'niTextTranslationUtil', $this->mockniTextTranslationUtil);
Expand All @@ -64,6 +71,7 @@ public function setUp(): void
$this->setMockedProperties($reflectionClass, 'urlHelper', $this->mockUrlHelper);
$this->setMockedProperties($reflectionClass, 'translationHelper', $this->mockTranslationHelper);
$this->setMockedProperties($reflectionClass, 'formatDataMapper', $this->mockFormatSaveDataMapper);
$this->setMockedProperties($reflectionClass, 'consultantRegistrationSession', $this->mockConsultantRegistrationSession);
}

/**
Expand All @@ -82,6 +90,8 @@ public function testAddActionForGet(): void
$mockRequest->shouldReceive('isPost')->andReturn(false);
$this->sut->shouldReceive('getRequest')->andReturn($mockRequest);



$termsAgreedElement = new \Laminas\Form\Element();
$termsAgreedElement->setLabel('termsAgreedLabel');

Expand Down

0 comments on commit bc869e2

Please sign in to comment.