Skip to content

Commit d422bd0

Browse files
committed
test: cover account identify method defaults
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent e1f4462 commit d422bd0

1 file changed

Lines changed: 50 additions & 8 deletions

File tree

tests/php/Unit/Service/IdentifyMethod/AccountTest.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ public static function providerValidateToRequestSuccess(): array {
191191
];
192192
}
193193

194+
public function testGetSettingsDisablesAccountWhenAnotherMethodIsEnabled(): void {
195+
$this->identifyService
196+
->expects($this->exactly(2))
197+
->method('getSavedSettings')
198+
->willReturn([
199+
[
200+
'name' => 'email',
201+
'enabled' => true,
202+
'mandatory' => true,
203+
'signatureMethods' => [
204+
'emailToken' => ['enabled' => true],
205+
],
206+
],
207+
]);
208+
209+
$settings = $this->getClass()->getSettings();
210+
211+
$this->assertFalse($settings['enabled']);
212+
}
213+
194214
private function createSignatureMethod(string $name, bool $enabled): ISignatureMethod {
195215
return new class($name, $enabled) implements ISignatureMethod {
196216
private string $name;
@@ -220,19 +240,41 @@ public function toArray(): array {
220240
}
221241

222242
private function createAccountWithMockSignatureMethods(array $signatureMethods): Account {
223-
$accountMock = new class($this->identifyService, $this->userManager, $this->eventDispatcher, $this->identifyMethodMapper, $this->userSession, $this->urlGenerator, $this->root, $this->hasher, $this->timeFactory, $this->logger, $this->sessionService, $this->mailService, ) extends Account {
224-
private array $mockSignatureMethods = [];
225-
226-
public function setMockSignatureMethods(array $methods): void {
227-
$this->mockSignatureMethods = $methods;
243+
return new class($this->identifyService, $this->userManager, $this->eventDispatcher, $this->identifyMethodMapper, $this->userSession, $this->urlGenerator, $this->root, $this->hasher, $this->timeFactory, $this->logger, $this->sessionService, $this->mailService, $signatureMethods) extends Account {
244+
public function __construct(
245+
IdentifyService $identifyService,
246+
IUserManager $userManager,
247+
IEventDispatcher $eventDispatcher,
248+
IdentifyMethodMapper $identifyMethodMapper,
249+
IUserSession $userSession,
250+
IURLGenerator $urlGenerator,
251+
IRootFolder $root,
252+
IHasher $hasher,
253+
ITimeFactory $timeFactory,
254+
LoggerInterface $logger,
255+
SessionService $sessionService,
256+
MailService $mailService,
257+
private array $mockSignatureMethods,
258+
) {
259+
parent::__construct(
260+
$identifyService,
261+
$userManager,
262+
$eventDispatcher,
263+
$identifyMethodMapper,
264+
$userSession,
265+
$urlGenerator,
266+
$root,
267+
$hasher,
268+
$timeFactory,
269+
$logger,
270+
$sessionService,
271+
$mailService,
272+
);
228273
}
229274

230275
public function getSignatureMethods(): array {
231276
return $this->mockSignatureMethods;
232277
}
233278
};
234-
235-
$accountMock->setMockSignatureMethods($signatureMethods);
236-
return $accountMock;
237279
}
238280
}

0 commit comments

Comments
 (0)