providerManager = $this->createMock(ProviderManager::class); $this->userManager = $this->createMock(IUserManager::class); $cmd = new Disable($this->providerManager, $this->userManager); $this->command = new CommandTester($cmd); } public function testInvalidUID() { $this->userManager->expects($this->once()) ->method('get') ->with('nope') ->willReturn(null); $rc = $this->command->execute([ 'uid' => 'nope', 'provider_id' => 'nope', ]); $this->assertEquals(1, $rc); $this->assertStringContainsString("Invalid UID", $this->command->getDisplay()); } public function testEnableNotSupported() { $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('ricky') ->willReturn($user); $this->providerManager->expects($this->once()) ->method('tryDisableProviderFor') ->with('totp', $user) ->willReturn(false); $rc = $this->command->execute([ 'uid' => 'ricky', 'provider_id' => 'totp', ]); $this->assertEquals(2, $rc); $this->assertStringContainsString("The provider does not support this operation", $this->command->getDisplay()); } public function testEnabled() { $user = $this->createMock(IUser::class); $this->userManager->expects($this->once()) ->method('get') ->with('ricky') ->willReturn($user); $this->providerManager->expects($this->once()) ->method('tryDisableProviderFor') ->with('totp', $user) ->willReturn(true); $rc = $this->command->execute([ 'uid' => 'ricky', 'provider_id' => 'totp', ]); $this->assertEquals(0, $rc); $this->assertStringContainsString("Two-factor provider totp disabled for user ricky", $this->command->getDisplay()); } }