Completed
Push — master ( 38c8ea...c9712b )
by Joas
40:21
created
tests/Core/Controller/JsControllerTest.php 1 patch
Indentation   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -21,150 +21,150 @@
 block discarded – undo
21 21
 use Test\TestCase;
22 22
 
23 23
 class JsControllerTest extends TestCase {
24
-	/** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
25
-	private $appData;
26
-
27
-	/** @var JsController */
28
-	private $controller;
29
-
30
-	/** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
31
-	private $request;
32
-
33
-	protected function setUp(): void {
34
-		parent::setUp();
35
-
36
-		/** @var Factory|\PHPUnit\Framework\MockObject\MockObject $factory */
37
-		$factory = $this->createMock(Factory::class);
38
-		$this->appData = $this->createMock(AppData::class);
39
-		$factory->expects($this->once())
40
-			->method('get')
41
-			->with('js')
42
-			->willReturn($this->appData);
43
-
44
-		/** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $timeFactory */
45
-		$timeFactory = $this->createMock(ITimeFactory::class);
46
-		$timeFactory->method('getTime')
47
-			->willReturn(1337);
48
-
49
-		$this->request = $this->createMock(IRequest::class);
50
-
51
-		$this->controller = new JsController(
52
-			'core',
53
-			$this->request,
54
-			$factory,
55
-			$timeFactory
56
-		);
57
-	}
58
-
59
-	public function testNoCssFolderForApp(): void {
60
-		$this->appData->method('getFolder')
61
-			->with('myapp')
62
-			->willThrowException(new NotFoundException());
63
-
64
-		$result = $this->controller->getJs('file.css', 'myapp');
65
-
66
-		$this->assertInstanceOf(NotFoundResponse::class, $result);
67
-	}
68
-
69
-
70
-	public function testNoCssFile(): void {
71
-		$folder = $this->createMock(ISimpleFolder::class);
72
-		$this->appData->method('getFolder')
73
-			->with('myapp')
74
-			->willReturn($folder);
75
-
76
-		$folder->method('getFile')
77
-			->willThrowException(new NotFoundException());
78
-
79
-		$result = $this->controller->getJs('file.css', 'myapp');
80
-
81
-		$this->assertInstanceOf(NotFoundResponse::class, $result);
82
-	}
83
-
84
-	public function testGetFile(): void {
85
-		$folder = $this->createMock(ISimpleFolder::class);
86
-		$file = $this->createMock(ISimpleFile::class);
87
-		$file->method('getName')->willReturn('my name');
88
-		$file->method('getMTime')->willReturn(42);
89
-		$this->appData->method('getFolder')
90
-			->with('myapp')
91
-			->willReturn($folder);
92
-
93
-		$folder->method('getFile')
94
-			->with('file.js')
95
-			->willReturn($file);
96
-
97
-		$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
98
-		$expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
99
-		$expires = new \DateTime();
100
-		$expires->setTimestamp(1337);
101
-		$expires->add(new \DateInterval('PT31536000S'));
102
-		$expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
103
-
104
-		$result = $this->controller->getJs('file.js', 'myapp');
105
-		$this->assertEquals($expected, $result);
106
-	}
107
-
108
-	public function testGetGzipFile(): void {
109
-		$folder = $this->createMock(ISimpleFolder::class);
110
-		$gzipFile = $this->createMock(ISimpleFile::class);
111
-		$gzipFile->method('getName')->willReturn('my name');
112
-		$gzipFile->method('getMTime')->willReturn(42);
113
-		$this->appData->method('getFolder')
114
-			->with('myapp')
115
-			->willReturn($folder);
116
-
117
-		$folder->method('getFile')
118
-			->with('file.js.gzip')
119
-			->willReturn($gzipFile);
120
-
121
-		$this->request->method('getHeader')
122
-			->with('Accept-Encoding')
123
-			->willReturn('gzip, deflate');
124
-
125
-		$expected = new FileDisplayResponse($gzipFile, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
126
-		$expected->addHeader('Content-Encoding', 'gzip');
127
-		$expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
128
-		$expires = new \DateTime();
129
-		$expires->setTimestamp(1337);
130
-		$expires->add(new \DateInterval('PT31536000S'));
131
-		$expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
132
-
133
-		$result = $this->controller->getJs('file.js', 'myapp');
134
-		$this->assertEquals($expected, $result);
135
-	}
136
-
137
-	public function testGetGzipFileNotFound(): void {
138
-		$folder = $this->createMock(ISimpleFolder::class);
139
-		$file = $this->createMock(ISimpleFile::class);
140
-		$file->method('getName')->willReturn('my name');
141
-		$file->method('getMTime')->willReturn(42);
142
-		$this->appData->method('getFolder')
143
-			->with('myapp')
144
-			->willReturn($folder);
145
-
146
-		$folder->method('getFile')
147
-			->willReturnCallback(
148
-				function ($fileName) use ($file) {
149
-					if ($fileName === 'file.js') {
150
-						return $file;
151
-					}
152
-					throw new NotFoundException();
153
-				}
154
-			);
155
-
156
-		$this->request->method('getHeader')
157
-			->with('Accept-Encoding')
158
-			->willReturn('gzip, deflate');
159
-
160
-		$expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
161
-		$expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
162
-		$expires = new \DateTime();
163
-		$expires->setTimestamp(1337);
164
-		$expires->add(new \DateInterval('PT31536000S'));
165
-		$expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
166
-
167
-		$result = $this->controller->getJs('file.js', 'myapp');
168
-		$this->assertEquals($expected, $result);
169
-	}
24
+    /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */
25
+    private $appData;
26
+
27
+    /** @var JsController */
28
+    private $controller;
29
+
30
+    /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
31
+    private $request;
32
+
33
+    protected function setUp(): void {
34
+        parent::setUp();
35
+
36
+        /** @var Factory|\PHPUnit\Framework\MockObject\MockObject $factory */
37
+        $factory = $this->createMock(Factory::class);
38
+        $this->appData = $this->createMock(AppData::class);
39
+        $factory->expects($this->once())
40
+            ->method('get')
41
+            ->with('js')
42
+            ->willReturn($this->appData);
43
+
44
+        /** @var ITimeFactory|\PHPUnit\Framework\MockObject\MockObject $timeFactory */
45
+        $timeFactory = $this->createMock(ITimeFactory::class);
46
+        $timeFactory->method('getTime')
47
+            ->willReturn(1337);
48
+
49
+        $this->request = $this->createMock(IRequest::class);
50
+
51
+        $this->controller = new JsController(
52
+            'core',
53
+            $this->request,
54
+            $factory,
55
+            $timeFactory
56
+        );
57
+    }
58
+
59
+    public function testNoCssFolderForApp(): void {
60
+        $this->appData->method('getFolder')
61
+            ->with('myapp')
62
+            ->willThrowException(new NotFoundException());
63
+
64
+        $result = $this->controller->getJs('file.css', 'myapp');
65
+
66
+        $this->assertInstanceOf(NotFoundResponse::class, $result);
67
+    }
68
+
69
+
70
+    public function testNoCssFile(): void {
71
+        $folder = $this->createMock(ISimpleFolder::class);
72
+        $this->appData->method('getFolder')
73
+            ->with('myapp')
74
+            ->willReturn($folder);
75
+
76
+        $folder->method('getFile')
77
+            ->willThrowException(new NotFoundException());
78
+
79
+        $result = $this->controller->getJs('file.css', 'myapp');
80
+
81
+        $this->assertInstanceOf(NotFoundResponse::class, $result);
82
+    }
83
+
84
+    public function testGetFile(): void {
85
+        $folder = $this->createMock(ISimpleFolder::class);
86
+        $file = $this->createMock(ISimpleFile::class);
87
+        $file->method('getName')->willReturn('my name');
88
+        $file->method('getMTime')->willReturn(42);
89
+        $this->appData->method('getFolder')
90
+            ->with('myapp')
91
+            ->willReturn($folder);
92
+
93
+        $folder->method('getFile')
94
+            ->with('file.js')
95
+            ->willReturn($file);
96
+
97
+        $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
98
+        $expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
99
+        $expires = new \DateTime();
100
+        $expires->setTimestamp(1337);
101
+        $expires->add(new \DateInterval('PT31536000S'));
102
+        $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
103
+
104
+        $result = $this->controller->getJs('file.js', 'myapp');
105
+        $this->assertEquals($expected, $result);
106
+    }
107
+
108
+    public function testGetGzipFile(): void {
109
+        $folder = $this->createMock(ISimpleFolder::class);
110
+        $gzipFile = $this->createMock(ISimpleFile::class);
111
+        $gzipFile->method('getName')->willReturn('my name');
112
+        $gzipFile->method('getMTime')->willReturn(42);
113
+        $this->appData->method('getFolder')
114
+            ->with('myapp')
115
+            ->willReturn($folder);
116
+
117
+        $folder->method('getFile')
118
+            ->with('file.js.gzip')
119
+            ->willReturn($gzipFile);
120
+
121
+        $this->request->method('getHeader')
122
+            ->with('Accept-Encoding')
123
+            ->willReturn('gzip, deflate');
124
+
125
+        $expected = new FileDisplayResponse($gzipFile, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
126
+        $expected->addHeader('Content-Encoding', 'gzip');
127
+        $expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
128
+        $expires = new \DateTime();
129
+        $expires->setTimestamp(1337);
130
+        $expires->add(new \DateInterval('PT31536000S'));
131
+        $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
132
+
133
+        $result = $this->controller->getJs('file.js', 'myapp');
134
+        $this->assertEquals($expected, $result);
135
+    }
136
+
137
+    public function testGetGzipFileNotFound(): void {
138
+        $folder = $this->createMock(ISimpleFolder::class);
139
+        $file = $this->createMock(ISimpleFile::class);
140
+        $file->method('getName')->willReturn('my name');
141
+        $file->method('getMTime')->willReturn(42);
142
+        $this->appData->method('getFolder')
143
+            ->with('myapp')
144
+            ->willReturn($folder);
145
+
146
+        $folder->method('getFile')
147
+            ->willReturnCallback(
148
+                function ($fileName) use ($file) {
149
+                    if ($fileName === 'file.js') {
150
+                        return $file;
151
+                    }
152
+                    throw new NotFoundException();
153
+                }
154
+            );
155
+
156
+        $this->request->method('getHeader')
157
+            ->with('Accept-Encoding')
158
+            ->willReturn('gzip, deflate');
159
+
160
+        $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'application/javascript']);
161
+        $expected->addHeader('Cache-Control', 'max-age=31536000, immutable');
162
+        $expires = new \DateTime();
163
+        $expires->setTimestamp(1337);
164
+        $expires->add(new \DateInterval('PT31536000S'));
165
+        $expected->addHeader('Expires', $expires->format(\DateTime::RFC1123));
166
+
167
+        $result = $this->controller->getJs('file.js', 'myapp');
168
+        $this->assertEquals($expected, $result);
169
+    }
170 170
 }
Please login to merge, or discard this patch.
tests/Core/Controller/WellKnownControllerTest.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -18,52 +18,52 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class WellKnownControllerTest extends TestCase {
21
-	/** @var IRequest|MockObject */
22
-	private $request;
21
+    /** @var IRequest|MockObject */
22
+    private $request;
23 23
 
24
-	/** @var RequestManager|MockObject */
25
-	private $manager;
24
+    /** @var RequestManager|MockObject */
25
+    private $manager;
26 26
 
27
-	/** @var WellKnownController */
28
-	private $controller;
27
+    /** @var WellKnownController */
28
+    private $controller;
29 29
 
30
-	protected function setUp(): void {
31
-		parent::setUp();
30
+    protected function setUp(): void {
31
+        parent::setUp();
32 32
 
33
-		$this->request = $this->createMock(IRequest::class);
34
-		$this->manager = $this->createMock(RequestManager::class);
33
+        $this->request = $this->createMock(IRequest::class);
34
+        $this->manager = $this->createMock(RequestManager::class);
35 35
 
36
-		$this->controller = new WellKnownController(
37
-			$this->request,
38
-			$this->manager,
39
-		);
40
-	}
36
+        $this->controller = new WellKnownController(
37
+            $this->request,
38
+            $this->manager,
39
+        );
40
+    }
41 41
 
42
-	public function testHandleNotProcessed(): void {
43
-		$httpResponse = $this->controller->handle('nodeinfo');
42
+    public function testHandleNotProcessed(): void {
43
+        $httpResponse = $this->controller->handle('nodeinfo');
44 44
 
45
-		self::assertInstanceOf(JSONResponse::class, $httpResponse);
46
-		self::assertArrayHasKey('X-NEXTCLOUD-WELL-KNOWN', $httpResponse->getHeaders());
47
-	}
45
+        self::assertInstanceOf(JSONResponse::class, $httpResponse);
46
+        self::assertArrayHasKey('X-NEXTCLOUD-WELL-KNOWN', $httpResponse->getHeaders());
47
+    }
48 48
 
49
-	public function testHandle(): void {
50
-		$response = $this->createMock(IResponse::class);
51
-		$jsonResponse = $this->createMock(JSONResponse::class);
52
-		$response->expects(self::once())
53
-			->method('toHttpResponse')
54
-			->willReturn($jsonResponse);
55
-		$this->manager->expects(self::once())
56
-			->method('process')
57
-			->with(
58
-				'nodeinfo',
59
-				$this->request
60
-			)->willReturn($response);
61
-		$jsonResponse->expects(self::once())
62
-			->method('addHeader')
63
-			->willReturnSelf();
49
+    public function testHandle(): void {
50
+        $response = $this->createMock(IResponse::class);
51
+        $jsonResponse = $this->createMock(JSONResponse::class);
52
+        $response->expects(self::once())
53
+            ->method('toHttpResponse')
54
+            ->willReturn($jsonResponse);
55
+        $this->manager->expects(self::once())
56
+            ->method('process')
57
+            ->with(
58
+                'nodeinfo',
59
+                $this->request
60
+            )->willReturn($response);
61
+        $jsonResponse->expects(self::once())
62
+            ->method('addHeader')
63
+            ->willReturnSelf();
64 64
 
65
-		$httpResponse = $this->controller->handle('nodeinfo');
65
+        $httpResponse = $this->controller->handle('nodeinfo');
66 66
 
67
-		self::assertInstanceOf(JSONResponse::class, $httpResponse);
68
-	}
67
+        self::assertInstanceOf(JSONResponse::class, $httpResponse);
68
+    }
69 69
 }
Please login to merge, or discard this patch.
tests/Core/Controller/ContactsMenuControllerTest.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -17,72 +17,72 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class ContactsMenuControllerTest extends TestCase {
20
-	/** @var IUserSession|MockObject */
21
-	private $userSession;
22
-
23
-	/** @var Manager|MockObject */
24
-	private $contactsManager;
25
-
26
-	private ContactsMenuController $controller;
27
-
28
-	protected function setUp(): void {
29
-		parent::setUp();
30
-
31
-		$request = $this->createMock(IRequest::class);
32
-		$this->userSession = $this->createMock(IUserSession::class);
33
-		$this->contactsManager = $this->createMock(Manager::class);
34
-
35
-		$this->controller = new ContactsMenuController($request, $this->userSession, $this->contactsManager);
36
-	}
37
-
38
-	public function testIndex(): void {
39
-		$user = $this->createMock(IUser::class);
40
-		$entries = [
41
-			$this->createMock(IEntry::class),
42
-			$this->createMock(IEntry::class),
43
-		];
44
-		$this->userSession->expects($this->once())
45
-			->method('getUser')
46
-			->willReturn($user);
47
-		$this->contactsManager->expects($this->once())
48
-			->method('getEntries')
49
-			->with($this->equalTo($user), $this->equalTo(null))
50
-			->willReturn($entries);
51
-
52
-		$response = $this->controller->index();
53
-
54
-		$this->assertEquals($entries, $response);
55
-	}
56
-
57
-	public function testFindOne(): void {
58
-		$user = $this->createMock(IUser::class);
59
-		$entry = $this->createMock(IEntry::class);
60
-		$this->userSession->expects($this->once())
61
-			->method('getUser')
62
-			->willReturn($user);
63
-		$this->contactsManager->expects($this->once())
64
-			->method('findOne')
65
-			->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
66
-			->willReturn($entry);
67
-
68
-		$response = $this->controller->findOne(42, 'test-search-phrase');
69
-
70
-		$this->assertEquals($entry, $response);
71
-	}
72
-
73
-	public function testFindOne404(): void {
74
-		$user = $this->createMock(IUser::class);
75
-		$this->userSession->expects($this->once())
76
-			->method('getUser')
77
-			->willReturn($user);
78
-		$this->contactsManager->expects($this->once())
79
-			->method('findOne')
80
-			->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
81
-			->willReturn(null);
82
-
83
-		$response = $this->controller->findOne(42, 'test-search-phrase');
84
-
85
-		$this->assertEquals([], $response->getData());
86
-		$this->assertEquals(404, $response->getStatus());
87
-	}
20
+    /** @var IUserSession|MockObject */
21
+    private $userSession;
22
+
23
+    /** @var Manager|MockObject */
24
+    private $contactsManager;
25
+
26
+    private ContactsMenuController $controller;
27
+
28
+    protected function setUp(): void {
29
+        parent::setUp();
30
+
31
+        $request = $this->createMock(IRequest::class);
32
+        $this->userSession = $this->createMock(IUserSession::class);
33
+        $this->contactsManager = $this->createMock(Manager::class);
34
+
35
+        $this->controller = new ContactsMenuController($request, $this->userSession, $this->contactsManager);
36
+    }
37
+
38
+    public function testIndex(): void {
39
+        $user = $this->createMock(IUser::class);
40
+        $entries = [
41
+            $this->createMock(IEntry::class),
42
+            $this->createMock(IEntry::class),
43
+        ];
44
+        $this->userSession->expects($this->once())
45
+            ->method('getUser')
46
+            ->willReturn($user);
47
+        $this->contactsManager->expects($this->once())
48
+            ->method('getEntries')
49
+            ->with($this->equalTo($user), $this->equalTo(null))
50
+            ->willReturn($entries);
51
+
52
+        $response = $this->controller->index();
53
+
54
+        $this->assertEquals($entries, $response);
55
+    }
56
+
57
+    public function testFindOne(): void {
58
+        $user = $this->createMock(IUser::class);
59
+        $entry = $this->createMock(IEntry::class);
60
+        $this->userSession->expects($this->once())
61
+            ->method('getUser')
62
+            ->willReturn($user);
63
+        $this->contactsManager->expects($this->once())
64
+            ->method('findOne')
65
+            ->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
66
+            ->willReturn($entry);
67
+
68
+        $response = $this->controller->findOne(42, 'test-search-phrase');
69
+
70
+        $this->assertEquals($entry, $response);
71
+    }
72
+
73
+    public function testFindOne404(): void {
74
+        $user = $this->createMock(IUser::class);
75
+        $this->userSession->expects($this->once())
76
+            ->method('getUser')
77
+            ->willReturn($user);
78
+        $this->contactsManager->expects($this->once())
79
+            ->method('findOne')
80
+            ->with($this->equalTo($user), $this->equalTo(42), $this->equalTo('test-search-phrase'))
81
+            ->willReturn(null);
82
+
83
+        $response = $this->controller->findOne(42, 'test-search-phrase');
84
+
85
+        $this->assertEquals([], $response->getData());
86
+        $this->assertEquals(404, $response->getStatus());
87
+    }
88 88
 }
Please login to merge, or discard this patch.
tests/Core/Command/Maintenance/UpdateTheme.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -16,47 +16,47 @@
 block discarded – undo
16 16
 use Test\TestCase;
17 17
 
18 18
 class UpdateThemeTest extends TestCase {
19
-	/** @var IMimeTypeDetector */
20
-	protected $detector;
21
-	/** @var ICacheFactory */
22
-	protected $cacheFactory;
23
-
24
-
25
-	/** @var \PHPUnit\Framework\MockObject\MockObject */
26
-	protected $consoleInput;
27
-	/** @var \PHPUnit\Framework\MockObject\MockObject */
28
-	protected $consoleOutput;
29
-
30
-	/** @var \Symfony\Component\Console\Command\Command */
31
-	protected $command;
32
-
33
-	protected function setUp(): void {
34
-		parent::setUp();
35
-
36
-		$this->detector = $this->createMock(Detection::class);
37
-		$this->cacheFactory = $this->createMock(ICacheFactory::class);
38
-
39
-		$this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
40
-		$this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
41
-
42
-		$this->command = new UpdateTheme($this->detector, $this->cacheFactory);
43
-	}
44
-
45
-	public function testThemeUpdate(): void {
46
-		$this->consoleInput->method('getOption')
47
-			->with('maintenance:theme:update')
48
-			->willReturn(true);
49
-		$this->detector->expects($this->once())
50
-			->method('getAllAliases')
51
-			->willReturn([]);
52
-		$cache = $this->createMock(ICache::class);
53
-		$cache->expects($this->once())
54
-			->method('clear')
55
-			->with('');
56
-		$this->cacheFactory->expects($this->once())
57
-			->method('createDistributed')
58
-			->with('imagePath')
59
-			->willReturn($cache);
60
-		self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
61
-	}
19
+    /** @var IMimeTypeDetector */
20
+    protected $detector;
21
+    /** @var ICacheFactory */
22
+    protected $cacheFactory;
23
+
24
+
25
+    /** @var \PHPUnit\Framework\MockObject\MockObject */
26
+    protected $consoleInput;
27
+    /** @var \PHPUnit\Framework\MockObject\MockObject */
28
+    protected $consoleOutput;
29
+
30
+    /** @var \Symfony\Component\Console\Command\Command */
31
+    protected $command;
32
+
33
+    protected function setUp(): void {
34
+        parent::setUp();
35
+
36
+        $this->detector = $this->createMock(Detection::class);
37
+        $this->cacheFactory = $this->createMock(ICacheFactory::class);
38
+
39
+        $this->consoleInput = $this->getMockBuilder(InputInterface::class)->getMock();
40
+        $this->consoleOutput = $this->getMockBuilder(OutputInterface::class)->getMock();
41
+
42
+        $this->command = new UpdateTheme($this->detector, $this->cacheFactory);
43
+    }
44
+
45
+    public function testThemeUpdate(): void {
46
+        $this->consoleInput->method('getOption')
47
+            ->with('maintenance:theme:update')
48
+            ->willReturn(true);
49
+        $this->detector->expects($this->once())
50
+            ->method('getAllAliases')
51
+            ->willReturn([]);
52
+        $cache = $this->createMock(ICache::class);
53
+        $cache->expects($this->once())
54
+            ->method('clear')
55
+            ->with('');
56
+        $this->cacheFactory->expects($this->once())
57
+            ->method('createDistributed')
58
+            ->with('imagePath')
59
+            ->willReturn($cache);
60
+        self::invokePrivate($this->command, 'execute', [$this->consoleInput, $this->consoleOutput]);
61
+    }
62 62
 }
Please login to merge, or discard this patch.
tests/Core/Command/TwoFactorAuth/EnforceTest.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -17,112 +17,112 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class EnforceTest extends TestCase {
20
-	/** @var MandatoryTwoFactor|MockObject */
21
-	private $mandatoryTwoFactor;
22
-
23
-	/** @var CommandTester */
24
-	private $command;
25
-
26
-	protected function setUp(): void {
27
-		parent::setUp();
28
-
29
-		$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
30
-		$command = new Enforce($this->mandatoryTwoFactor);
31
-
32
-		$this->command = new CommandTester($command);
33
-	}
34
-
35
-	public function testEnforce(): void {
36
-		$this->mandatoryTwoFactor->expects($this->once())
37
-			->method('setState')
38
-			->with($this->equalTo(new EnforcementState(true)));
39
-		$this->mandatoryTwoFactor->expects($this->once())
40
-			->method('getState')
41
-			->willReturn(new EnforcementState(true));
42
-
43
-		$rc = $this->command->execute([
44
-			'--on' => true,
45
-		]);
46
-
47
-		$this->assertEquals(0, $rc);
48
-		$display = $this->command->getDisplay();
49
-		$this->assertStringContainsString('Two-factor authentication is enforced for all users', $display);
50
-	}
51
-
52
-	public function testEnforceForOneGroup(): void {
53
-		$this->mandatoryTwoFactor->expects($this->once())
54
-			->method('setState')
55
-			->with($this->equalTo(new EnforcementState(true, ['twofactorers'])));
56
-		$this->mandatoryTwoFactor->expects($this->once())
57
-			->method('getState')
58
-			->willReturn(new EnforcementState(true, ['twofactorers']));
59
-
60
-		$rc = $this->command->execute([
61
-			'--on' => true,
62
-			'--group' => ['twofactorers'],
63
-		]);
64
-
65
-		$this->assertEquals(0, $rc);
66
-		$display = $this->command->getDisplay();
67
-		$this->assertStringContainsString('Two-factor authentication is enforced for members of the group(s) twofactorers', $display);
68
-	}
69
-
70
-	public function testEnforceForAllExceptOneGroup(): void {
71
-		$this->mandatoryTwoFactor->expects($this->once())
72
-			->method('setState')
73
-			->with($this->equalTo(new EnforcementState(true, [], ['yoloers'])));
74
-		$this->mandatoryTwoFactor->expects($this->once())
75
-			->method('getState')
76
-			->willReturn(new EnforcementState(true, [], ['yoloers']));
77
-
78
-		$rc = $this->command->execute([
79
-			'--on' => true,
80
-			'--exclude' => ['yoloers'],
81
-		]);
82
-
83
-		$this->assertEquals(0, $rc);
84
-		$display = $this->command->getDisplay();
85
-		$this->assertStringContainsString('Two-factor authentication is enforced for all users, except members of yoloers', $display);
86
-	}
87
-
88
-	public function testDisableEnforced(): void {
89
-		$this->mandatoryTwoFactor->expects($this->once())
90
-			->method('setState')
91
-			->with(new EnforcementState(false));
92
-		$this->mandatoryTwoFactor->expects($this->once())
93
-			->method('getState')
94
-			->willReturn(new EnforcementState(false));
95
-
96
-		$rc = $this->command->execute([
97
-			'--off' => true,
98
-		]);
99
-
100
-		$this->assertEquals(0, $rc);
101
-		$display = $this->command->getDisplay();
102
-		$this->assertStringContainsString('Two-factor authentication is not enforced', $display);
103
-	}
104
-
105
-	public function testCurrentStateEnabled(): void {
106
-		$this->mandatoryTwoFactor->expects($this->once())
107
-			->method('getState')
108
-			->willReturn(new EnforcementState(true));
109
-
110
-		$rc = $this->command->execute([]);
111
-
112
-		$this->assertEquals(0, $rc);
113
-		$display = $this->command->getDisplay();
114
-		$this->assertStringContainsString('Two-factor authentication is enforced for all users', $display);
115
-	}
116
-
117
-	public function testCurrentStateDisabled(): void {
118
-		$this->mandatoryTwoFactor->expects($this->once())
119
-			->method('getState')
120
-			->willReturn(new EnforcementState(false));
121
-
122
-		$rc = $this->command->execute([]);
123
-
124
-		$this->assertEquals(0, $rc);
125
-		$display = $this->command->getDisplay();
126
-		$this->assertStringContainsString('Two-factor authentication is not enforced', $display);
127
-	}
20
+    /** @var MandatoryTwoFactor|MockObject */
21
+    private $mandatoryTwoFactor;
22
+
23
+    /** @var CommandTester */
24
+    private $command;
25
+
26
+    protected function setUp(): void {
27
+        parent::setUp();
28
+
29
+        $this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
30
+        $command = new Enforce($this->mandatoryTwoFactor);
31
+
32
+        $this->command = new CommandTester($command);
33
+    }
34
+
35
+    public function testEnforce(): void {
36
+        $this->mandatoryTwoFactor->expects($this->once())
37
+            ->method('setState')
38
+            ->with($this->equalTo(new EnforcementState(true)));
39
+        $this->mandatoryTwoFactor->expects($this->once())
40
+            ->method('getState')
41
+            ->willReturn(new EnforcementState(true));
42
+
43
+        $rc = $this->command->execute([
44
+            '--on' => true,
45
+        ]);
46
+
47
+        $this->assertEquals(0, $rc);
48
+        $display = $this->command->getDisplay();
49
+        $this->assertStringContainsString('Two-factor authentication is enforced for all users', $display);
50
+    }
51
+
52
+    public function testEnforceForOneGroup(): void {
53
+        $this->mandatoryTwoFactor->expects($this->once())
54
+            ->method('setState')
55
+            ->with($this->equalTo(new EnforcementState(true, ['twofactorers'])));
56
+        $this->mandatoryTwoFactor->expects($this->once())
57
+            ->method('getState')
58
+            ->willReturn(new EnforcementState(true, ['twofactorers']));
59
+
60
+        $rc = $this->command->execute([
61
+            '--on' => true,
62
+            '--group' => ['twofactorers'],
63
+        ]);
64
+
65
+        $this->assertEquals(0, $rc);
66
+        $display = $this->command->getDisplay();
67
+        $this->assertStringContainsString('Two-factor authentication is enforced for members of the group(s) twofactorers', $display);
68
+    }
69
+
70
+    public function testEnforceForAllExceptOneGroup(): void {
71
+        $this->mandatoryTwoFactor->expects($this->once())
72
+            ->method('setState')
73
+            ->with($this->equalTo(new EnforcementState(true, [], ['yoloers'])));
74
+        $this->mandatoryTwoFactor->expects($this->once())
75
+            ->method('getState')
76
+            ->willReturn(new EnforcementState(true, [], ['yoloers']));
77
+
78
+        $rc = $this->command->execute([
79
+            '--on' => true,
80
+            '--exclude' => ['yoloers'],
81
+        ]);
82
+
83
+        $this->assertEquals(0, $rc);
84
+        $display = $this->command->getDisplay();
85
+        $this->assertStringContainsString('Two-factor authentication is enforced for all users, except members of yoloers', $display);
86
+    }
87
+
88
+    public function testDisableEnforced(): void {
89
+        $this->mandatoryTwoFactor->expects($this->once())
90
+            ->method('setState')
91
+            ->with(new EnforcementState(false));
92
+        $this->mandatoryTwoFactor->expects($this->once())
93
+            ->method('getState')
94
+            ->willReturn(new EnforcementState(false));
95
+
96
+        $rc = $this->command->execute([
97
+            '--off' => true,
98
+        ]);
99
+
100
+        $this->assertEquals(0, $rc);
101
+        $display = $this->command->getDisplay();
102
+        $this->assertStringContainsString('Two-factor authentication is not enforced', $display);
103
+    }
104
+
105
+    public function testCurrentStateEnabled(): void {
106
+        $this->mandatoryTwoFactor->expects($this->once())
107
+            ->method('getState')
108
+            ->willReturn(new EnforcementState(true));
109
+
110
+        $rc = $this->command->execute([]);
111
+
112
+        $this->assertEquals(0, $rc);
113
+        $display = $this->command->getDisplay();
114
+        $this->assertStringContainsString('Two-factor authentication is enforced for all users', $display);
115
+    }
116
+
117
+    public function testCurrentStateDisabled(): void {
118
+        $this->mandatoryTwoFactor->expects($this->once())
119
+            ->method('getState')
120
+            ->willReturn(new EnforcementState(false));
121
+
122
+        $rc = $this->command->execute([]);
123
+
124
+        $this->assertEquals(0, $rc);
125
+        $display = $this->command->getDisplay();
126
+        $this->assertStringContainsString('Two-factor authentication is not enforced', $display);
127
+    }
128 128
 }
Please login to merge, or discard this patch.
tests/Core/Command/TwoFactorAuth/StateTest.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class StateTest extends TestCase {
21
-	/** @var IRegistry|MockObject */
22
-	private $registry;
23
-
24
-	/** @var IUserManager|MockObject */
25
-	private $userManager;
26
-
27
-	/** @var CommandTester|MockObject */
28
-	private $cmd;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->registry = $this->createMock(IRegistry::class);
34
-		$this->userManager = $this->createMock(IUserManager::class);
35
-
36
-		$cmd = new State($this->registry, $this->userManager);
37
-		$this->cmd = new CommandTester($cmd);
38
-	}
39
-
40
-	public function testWrongUID(): void {
41
-		$this->cmd->execute([
42
-			'uid' => 'nope',
43
-		]);
44
-
45
-		$output = $this->cmd->getDisplay();
46
-		$this->assertStringContainsString('Invalid UID', $output);
47
-	}
48
-
49
-	public function testStateNoProvidersActive(): void {
50
-		$user = $this->createMock(IUser::class);
51
-		$this->userManager->expects($this->once())
52
-			->method('get')
53
-			->with('eldora')
54
-			->willReturn($user);
55
-		$states = [
56
-			'u2f' => false,
57
-			'totp' => false,
58
-		];
59
-		$this->registry->expects($this->once())
60
-			->method('getProviderStates')
61
-			->with($user)
62
-			->willReturn($states);
63
-
64
-		$this->cmd->execute([
65
-			'uid' => 'eldora',
66
-		]);
67
-
68
-		$output = $this->cmd->getDisplay();
69
-		$this->assertStringContainsString('Two-factor authentication is not enabled for user eldora', $output);
70
-	}
71
-
72
-	public function testStateOneProviderActive(): void {
73
-		$user = $this->createMock(IUser::class);
74
-		$this->userManager->expects($this->once())
75
-			->method('get')
76
-			->with('mohamed')
77
-			->willReturn($user);
78
-		$states = [
79
-			'u2f' => true,
80
-			'totp' => false,
81
-		];
82
-		$this->registry->expects($this->once())
83
-			->method('getProviderStates')
84
-			->with($user)
85
-			->willReturn($states);
86
-
87
-		$this->cmd->execute([
88
-			'uid' => 'mohamed',
89
-		]);
90
-
91
-		$output = $this->cmd->getDisplay();
92
-		$this->assertStringContainsString('Two-factor authentication is enabled for user mohamed', $output);
93
-	}
21
+    /** @var IRegistry|MockObject */
22
+    private $registry;
23
+
24
+    /** @var IUserManager|MockObject */
25
+    private $userManager;
26
+
27
+    /** @var CommandTester|MockObject */
28
+    private $cmd;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->registry = $this->createMock(IRegistry::class);
34
+        $this->userManager = $this->createMock(IUserManager::class);
35
+
36
+        $cmd = new State($this->registry, $this->userManager);
37
+        $this->cmd = new CommandTester($cmd);
38
+    }
39
+
40
+    public function testWrongUID(): void {
41
+        $this->cmd->execute([
42
+            'uid' => 'nope',
43
+        ]);
44
+
45
+        $output = $this->cmd->getDisplay();
46
+        $this->assertStringContainsString('Invalid UID', $output);
47
+    }
48
+
49
+    public function testStateNoProvidersActive(): void {
50
+        $user = $this->createMock(IUser::class);
51
+        $this->userManager->expects($this->once())
52
+            ->method('get')
53
+            ->with('eldora')
54
+            ->willReturn($user);
55
+        $states = [
56
+            'u2f' => false,
57
+            'totp' => false,
58
+        ];
59
+        $this->registry->expects($this->once())
60
+            ->method('getProviderStates')
61
+            ->with($user)
62
+            ->willReturn($states);
63
+
64
+        $this->cmd->execute([
65
+            'uid' => 'eldora',
66
+        ]);
67
+
68
+        $output = $this->cmd->getDisplay();
69
+        $this->assertStringContainsString('Two-factor authentication is not enabled for user eldora', $output);
70
+    }
71
+
72
+    public function testStateOneProviderActive(): void {
73
+        $user = $this->createMock(IUser::class);
74
+        $this->userManager->expects($this->once())
75
+            ->method('get')
76
+            ->with('mohamed')
77
+            ->willReturn($user);
78
+        $states = [
79
+            'u2f' => true,
80
+            'totp' => false,
81
+        ];
82
+        $this->registry->expects($this->once())
83
+            ->method('getProviderStates')
84
+            ->with($user)
85
+            ->willReturn($states);
86
+
87
+        $this->cmd->execute([
88
+            'uid' => 'mohamed',
89
+        ]);
90
+
91
+        $output = $this->cmd->getDisplay();
92
+        $this->assertStringContainsString('Two-factor authentication is enabled for user mohamed', $output);
93
+    }
94 94
 }
Please login to merge, or discard this patch.
tests/Core/Command/TwoFactorAuth/CleanupTest.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -17,36 +17,36 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class CleanupTest extends TestCase {
20
-	/** @var IRegistry|MockObject */
21
-	private $registry;
20
+    /** @var IRegistry|MockObject */
21
+    private $registry;
22 22
 
23
-	/** @var IUserManager|MockObject */
24
-	private $userManager;
23
+    /** @var IUserManager|MockObject */
24
+    private $userManager;
25 25
 
26
-	/** @var CommandTester */
27
-	private $cmd;
26
+    /** @var CommandTester */
27
+    private $cmd;
28 28
 
29
-	protected function setUp(): void {
30
-		parent::setUp();
29
+    protected function setUp(): void {
30
+        parent::setUp();
31 31
 
32
-		$this->registry = $this->createMock(IRegistry::class);
33
-		$this->userManager = $this->createMock(IUserManager::class);
32
+        $this->registry = $this->createMock(IRegistry::class);
33
+        $this->userManager = $this->createMock(IUserManager::class);
34 34
 
35
-		$cmd = new Cleanup($this->registry, $this->userManager);
36
-		$this->cmd = new CommandTester($cmd);
37
-	}
35
+        $cmd = new Cleanup($this->registry, $this->userManager);
36
+        $this->cmd = new CommandTester($cmd);
37
+    }
38 38
 
39
-	public function testCleanup(): void {
40
-		$this->registry->expects($this->once())
41
-			->method('cleanUp')
42
-			->with('u2f');
39
+    public function testCleanup(): void {
40
+        $this->registry->expects($this->once())
41
+            ->method('cleanUp')
42
+            ->with('u2f');
43 43
 
44
-		$rc = $this->cmd->execute([
45
-			'provider-id' => 'u2f',
46
-		]);
44
+        $rc = $this->cmd->execute([
45
+            'provider-id' => 'u2f',
46
+        ]);
47 47
 
48
-		$this->assertEquals(0, $rc);
49
-		$output = $this->cmd->getDisplay();
50
-		$this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output);
51
-	}
48
+        $this->assertEquals(0, $rc);
49
+        $output = $this->cmd->getDisplay();
50
+        $this->assertStringContainsString('All user-provider associations for provider u2f have been removed', $output);
51
+    }
52 52
 }
Please login to merge, or discard this patch.
tests/Core/Command/TwoFactorAuth/EnableTest.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class EnableTest extends TestCase {
21
-	/** @var ProviderManager|MockObject */
22
-	private $providerManager;
23
-
24
-	/** @var IUserManager|MockObject */
25
-	private $userManager;
26
-
27
-	/** @var CommandTester */
28
-	private $command;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->providerManager = $this->createMock(ProviderManager::class);
34
-		$this->userManager = $this->createMock(IUserManager::class);
35
-
36
-		$cmd = new Enable($this->providerManager, $this->userManager);
37
-		$this->command = new CommandTester($cmd);
38
-	}
39
-
40
-	public function testInvalidUID(): void {
41
-		$this->userManager->expects($this->once())
42
-			->method('get')
43
-			->with('nope')
44
-			->willReturn(null);
45
-
46
-		$rc = $this->command->execute([
47
-			'uid' => 'nope',
48
-			'provider_id' => 'nope',
49
-		]);
50
-
51
-		$this->assertEquals(1, $rc);
52
-		$this->assertStringContainsString('Invalid UID', $this->command->getDisplay());
53
-	}
54
-
55
-	public function testEnableNotSupported(): void {
56
-		$user = $this->createMock(IUser::class);
57
-		$this->userManager->expects($this->once())
58
-			->method('get')
59
-			->with('belle')
60
-			->willReturn($user);
61
-		$this->providerManager->expects($this->once())
62
-			->method('tryEnableProviderFor')
63
-			->with('totp', $user)
64
-			->willReturn(false);
65
-
66
-		$rc = $this->command->execute([
67
-			'uid' => 'belle',
68
-			'provider_id' => 'totp',
69
-		]);
70
-
71
-		$this->assertEquals(2, $rc);
72
-		$this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay());
73
-	}
74
-
75
-	public function testEnabled(): void {
76
-		$user = $this->createMock(IUser::class);
77
-		$this->userManager->expects($this->once())
78
-			->method('get')
79
-			->with('belle')
80
-			->willReturn($user);
81
-		$this->providerManager->expects($this->once())
82
-			->method('tryEnableProviderFor')
83
-			->with('totp', $user)
84
-			->willReturn(true);
85
-
86
-		$rc = $this->command->execute([
87
-			'uid' => 'belle',
88
-			'provider_id' => 'totp',
89
-		]);
90
-
91
-		$this->assertEquals(0, $rc);
92
-		$this->assertStringContainsString('Two-factor provider totp enabled for user belle', $this->command->getDisplay());
93
-	}
21
+    /** @var ProviderManager|MockObject */
22
+    private $providerManager;
23
+
24
+    /** @var IUserManager|MockObject */
25
+    private $userManager;
26
+
27
+    /** @var CommandTester */
28
+    private $command;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->providerManager = $this->createMock(ProviderManager::class);
34
+        $this->userManager = $this->createMock(IUserManager::class);
35
+
36
+        $cmd = new Enable($this->providerManager, $this->userManager);
37
+        $this->command = new CommandTester($cmd);
38
+    }
39
+
40
+    public function testInvalidUID(): void {
41
+        $this->userManager->expects($this->once())
42
+            ->method('get')
43
+            ->with('nope')
44
+            ->willReturn(null);
45
+
46
+        $rc = $this->command->execute([
47
+            'uid' => 'nope',
48
+            'provider_id' => 'nope',
49
+        ]);
50
+
51
+        $this->assertEquals(1, $rc);
52
+        $this->assertStringContainsString('Invalid UID', $this->command->getDisplay());
53
+    }
54
+
55
+    public function testEnableNotSupported(): void {
56
+        $user = $this->createMock(IUser::class);
57
+        $this->userManager->expects($this->once())
58
+            ->method('get')
59
+            ->with('belle')
60
+            ->willReturn($user);
61
+        $this->providerManager->expects($this->once())
62
+            ->method('tryEnableProviderFor')
63
+            ->with('totp', $user)
64
+            ->willReturn(false);
65
+
66
+        $rc = $this->command->execute([
67
+            'uid' => 'belle',
68
+            'provider_id' => 'totp',
69
+        ]);
70
+
71
+        $this->assertEquals(2, $rc);
72
+        $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay());
73
+    }
74
+
75
+    public function testEnabled(): void {
76
+        $user = $this->createMock(IUser::class);
77
+        $this->userManager->expects($this->once())
78
+            ->method('get')
79
+            ->with('belle')
80
+            ->willReturn($user);
81
+        $this->providerManager->expects($this->once())
82
+            ->method('tryEnableProviderFor')
83
+            ->with('totp', $user)
84
+            ->willReturn(true);
85
+
86
+        $rc = $this->command->execute([
87
+            'uid' => 'belle',
88
+            'provider_id' => 'totp',
89
+        ]);
90
+
91
+        $this->assertEquals(0, $rc);
92
+        $this->assertStringContainsString('Two-factor provider totp enabled for user belle', $this->command->getDisplay());
93
+    }
94 94
 }
Please login to merge, or discard this patch.
tests/Core/Command/TwoFactorAuth/DisableTest.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -18,77 +18,77 @@
 block discarded – undo
18 18
 use Test\TestCase;
19 19
 
20 20
 class DisableTest extends TestCase {
21
-	/** @var ProviderManager|MockObject */
22
-	private $providerManager;
23
-
24
-	/** @var IUserManager|MockObject */
25
-	private $userManager;
26
-
27
-	/** @var CommandTester */
28
-	private $command;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->providerManager = $this->createMock(ProviderManager::class);
34
-		$this->userManager = $this->createMock(IUserManager::class);
35
-
36
-		$cmd = new Disable($this->providerManager, $this->userManager);
37
-		$this->command = new CommandTester($cmd);
38
-	}
39
-
40
-	public function testInvalidUID(): void {
41
-		$this->userManager->expects($this->once())
42
-			->method('get')
43
-			->with('nope')
44
-			->willReturn(null);
45
-
46
-		$rc = $this->command->execute([
47
-			'uid' => 'nope',
48
-			'provider_id' => 'nope',
49
-		]);
50
-
51
-		$this->assertEquals(1, $rc);
52
-		$this->assertStringContainsString('Invalid UID', $this->command->getDisplay());
53
-	}
54
-
55
-	public function testEnableNotSupported(): void {
56
-		$user = $this->createMock(IUser::class);
57
-		$this->userManager->expects($this->once())
58
-			->method('get')
59
-			->with('ricky')
60
-			->willReturn($user);
61
-		$this->providerManager->expects($this->once())
62
-			->method('tryDisableProviderFor')
63
-			->with('totp', $user)
64
-			->willReturn(false);
65
-
66
-		$rc = $this->command->execute([
67
-			'uid' => 'ricky',
68
-			'provider_id' => 'totp',
69
-		]);
70
-
71
-		$this->assertEquals(2, $rc);
72
-		$this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay());
73
-	}
74
-
75
-	public function testEnabled(): void {
76
-		$user = $this->createMock(IUser::class);
77
-		$this->userManager->expects($this->once())
78
-			->method('get')
79
-			->with('ricky')
80
-			->willReturn($user);
81
-		$this->providerManager->expects($this->once())
82
-			->method('tryDisableProviderFor')
83
-			->with('totp', $user)
84
-			->willReturn(true);
85
-
86
-		$rc = $this->command->execute([
87
-			'uid' => 'ricky',
88
-			'provider_id' => 'totp',
89
-		]);
90
-
91
-		$this->assertEquals(0, $rc);
92
-		$this->assertStringContainsString('Two-factor provider totp disabled for user ricky', $this->command->getDisplay());
93
-	}
21
+    /** @var ProviderManager|MockObject */
22
+    private $providerManager;
23
+
24
+    /** @var IUserManager|MockObject */
25
+    private $userManager;
26
+
27
+    /** @var CommandTester */
28
+    private $command;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->providerManager = $this->createMock(ProviderManager::class);
34
+        $this->userManager = $this->createMock(IUserManager::class);
35
+
36
+        $cmd = new Disable($this->providerManager, $this->userManager);
37
+        $this->command = new CommandTester($cmd);
38
+    }
39
+
40
+    public function testInvalidUID(): void {
41
+        $this->userManager->expects($this->once())
42
+            ->method('get')
43
+            ->with('nope')
44
+            ->willReturn(null);
45
+
46
+        $rc = $this->command->execute([
47
+            'uid' => 'nope',
48
+            'provider_id' => 'nope',
49
+        ]);
50
+
51
+        $this->assertEquals(1, $rc);
52
+        $this->assertStringContainsString('Invalid UID', $this->command->getDisplay());
53
+    }
54
+
55
+    public function testEnableNotSupported(): void {
56
+        $user = $this->createMock(IUser::class);
57
+        $this->userManager->expects($this->once())
58
+            ->method('get')
59
+            ->with('ricky')
60
+            ->willReturn($user);
61
+        $this->providerManager->expects($this->once())
62
+            ->method('tryDisableProviderFor')
63
+            ->with('totp', $user)
64
+            ->willReturn(false);
65
+
66
+        $rc = $this->command->execute([
67
+            'uid' => 'ricky',
68
+            'provider_id' => 'totp',
69
+        ]);
70
+
71
+        $this->assertEquals(2, $rc);
72
+        $this->assertStringContainsString('The provider does not support this operation', $this->command->getDisplay());
73
+    }
74
+
75
+    public function testEnabled(): void {
76
+        $user = $this->createMock(IUser::class);
77
+        $this->userManager->expects($this->once())
78
+            ->method('get')
79
+            ->with('ricky')
80
+            ->willReturn($user);
81
+        $this->providerManager->expects($this->once())
82
+            ->method('tryDisableProviderFor')
83
+            ->with('totp', $user)
84
+            ->willReturn(true);
85
+
86
+        $rc = $this->command->execute([
87
+            'uid' => 'ricky',
88
+            'provider_id' => 'totp',
89
+        ]);
90
+
91
+        $this->assertEquals(0, $rc);
92
+        $this->assertStringContainsString('Two-factor provider totp disabled for user ricky', $this->command->getDisplay());
93
+    }
94 94
 }
Please login to merge, or discard this patch.