Skip to content

Commit 8f328ff

Browse files
committed
test: update policy controller assigned user cases
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 6e7a683 commit 8f328ff

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

tests/php/Unit/Controller/PolicyControllerTest.php

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,9 @@ public function testSetUserPolicyForTargetUserReturnsSavedExplicitPolicy(): void
658658
->willReturn(true);
659659

660660
$persistedPolicy = (new PolicyLayer())
661-
->setScope('user')
662-
->setValue('ordered_numeric');
661+
->setScope('user_policy')
662+
->setValue('ordered_numeric')
663+
->setAllowChildOverride(false);
663664

664665
$this->l10n
665666
->expects($this->once())
@@ -669,16 +670,17 @@ public function testSetUserPolicyForTargetUserReturnsSavedExplicitPolicy(): void
669670

670671
$this->policyService
671672
->expects($this->once())
672-
->method('saveUserPreferenceForUserId')
673-
->with('signature_flow', 'user1', 'ordered_numeric')
673+
->method('saveUserPolicyForUserId')
674+
->with('signature_flow', 'user1', 'ordered_numeric', false)
674675
->willReturn($persistedPolicy);
675676

676677
$response = $this->controller->setUserPolicyForUser('user1', 'signature_flow', 'ordered_numeric');
677678

678679
$this->assertSame(Http::STATUS_OK, $response->getStatus());
679-
$this->assertSame('user', $response->getData()['policy']['scope']);
680+
$this->assertSame('user_policy', $response->getData()['policy']['scope']);
680681
$this->assertSame('user1', $response->getData()['policy']['targetId']);
681682
$this->assertSame('ordered_numeric', $response->getData()['policy']['value']);
683+
$this->assertFalse($response->getData()['policy']['allowChildOverride']);
682684
}
683685

684686
public function testClearUserPolicyForTargetUserReturnsClearedExplicitPolicy(): void {
@@ -695,16 +697,17 @@ public function testClearUserPolicyForTargetUserReturnsClearedExplicitPolicy():
695697

696698
$this->policyService
697699
->expects($this->once())
698-
->method('clearUserPreferenceForUserId')
700+
->method('clearUserPolicyForUserId')
699701
->with('signature_flow', 'user1')
700702
->willReturn(null);
701703

702704
$response = $this->controller->clearUserPolicyForUser('user1', 'signature_flow');
703705

704706
$this->assertSame(Http::STATUS_OK, $response->getStatus());
705-
$this->assertSame('user', $response->getData()['policy']['scope']);
707+
$this->assertSame('user_policy', $response->getData()['policy']['scope']);
706708
$this->assertSame('user1', $response->getData()['policy']['targetId']);
707709
$this->assertNull($response->getData()['policy']['value']);
710+
$this->assertTrue($response->getData()['policy']['allowChildOverride']);
708711
}
709712

710713
public function testSetUserPolicyForTargetUserReturnsBadRequestWhenServiceBlocksSave(): void {
@@ -715,15 +718,15 @@ public function testSetUserPolicyForTargetUserReturnsBadRequestWhenServiceBlocks
715718

716719
$this->policyService
717720
->expects($this->once())
718-
->method('saveUserPreferenceForUserId')
719-
->with('signature_flow', 'user1', 'ordered_numeric')
720-
->willThrowException(new \InvalidArgumentException('Saving a user preference is not allowed for signature_flow'));
721+
->method('saveUserPolicyForUserId')
722+
->with('signature_flow', 'user1', 'ordered_numeric', false)
723+
->willThrowException(new \InvalidArgumentException('Invalid value for signature_flow'));
721724

722725
$response = $this->controller->setUserPolicyForUser('user1', 'signature_flow', 'ordered_numeric');
723726

724727
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
725728
$this->assertSame([
726-
'error' => 'Saving a user preference is not allowed for signature_flow',
729+
'error' => 'Invalid value for signature_flow',
727730
], $response->getData());
728731
}
729732

@@ -748,8 +751,8 @@ public function testSetUserPolicyForTargetUserBubblesUnexpectedExceptions(): voi
748751

749752
$this->policyService
750753
->expects($this->once())
751-
->method('saveUserPreferenceForUserId')
752-
->with('signature_flow', 'user1', 'ordered_numeric')
754+
->method('saveUserPolicyForUserId')
755+
->with('signature_flow', 'user1', 'ordered_numeric', false)
753756
->willThrowException(new \RuntimeException('Unexpected policy failure'));
754757

755758
$this->expectException(\RuntimeException::class);
@@ -779,7 +782,7 @@ public function testClearUserPolicyForTargetUserBubblesUnexpectedExceptions(): v
779782

780783
$this->policyService
781784
->expects($this->once())
782-
->method('clearUserPreferenceForUserId')
785+
->method('clearUserPolicyForUserId')
783786
->with('signature_flow', 'user1')
784787
->willThrowException(new \RuntimeException('Unexpected policy failure'));
785788

@@ -804,7 +807,7 @@ public function testSetUserPolicyForTargetUserReturnsForbiddenWhenCurrentActorCa
804807
->with('Not allowed to manage this user policy')
805808
->willReturn('Not allowed to manage this user policy');
806809

807-
$this->policyService->expects($this->never())->method('saveUserPreferenceForUserId');
810+
$this->policyService->expects($this->never())->method('saveUserPolicyForUserId');
808811

809812
$response = $this->controller->setUserPolicyForUser('user1', 'signature_flow', 'ordered_numeric');
810813

@@ -829,7 +832,7 @@ public function testClearUserPolicyForTargetUserReturnsForbiddenWhenCurrentActor
829832
->with('Not allowed to manage this user policy')
830833
->willReturn('Not allowed to manage this user policy');
831834

832-
$this->policyService->expects($this->never())->method('clearUserPreferenceForUserId');
835+
$this->policyService->expects($this->never())->method('clearUserPolicyForUserId');
833836

834837
$response = $this->controller->clearUserPolicyForUser('user1', 'signature_flow');
835838

0 commit comments

Comments
 (0)