@@ -27,26 +27,26 @@ |
||
27 | 27 | use Symfony\Component\Console\Output\OutputInterface; |
28 | 28 | |
29 | 29 | class Status extends Base { |
30 | - public function __construct( |
|
31 | - protected IManager $encryptionManager, |
|
32 | - ) { |
|
33 | - parent::__construct(); |
|
34 | - } |
|
30 | + public function __construct( |
|
31 | + protected IManager $encryptionManager, |
|
32 | + ) { |
|
33 | + parent::__construct(); |
|
34 | + } |
|
35 | 35 | |
36 | - protected function configure() { |
|
37 | - parent::configure(); |
|
36 | + protected function configure() { |
|
37 | + parent::configure(); |
|
38 | 38 | |
39 | - $this |
|
40 | - ->setName('encryption:status') |
|
41 | - ->setDescription('Lists the current status of encryption') |
|
42 | - ; |
|
43 | - } |
|
39 | + $this |
|
40 | + ->setName('encryption:status') |
|
41 | + ->setDescription('Lists the current status of encryption') |
|
42 | + ; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
46 | - $this->writeArrayInOutputFormat($input, $output, [ |
|
47 | - 'enabled' => $this->encryptionManager->isEnabled(), |
|
48 | - 'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(), |
|
49 | - ]); |
|
50 | - return 0; |
|
51 | - } |
|
45 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
46 | + $this->writeArrayInOutputFormat($input, $output, [ |
|
47 | + 'enabled' => $this->encryptionManager->isEnabled(), |
|
48 | + 'defaultModule' => $this->encryptionManager->getDefaultEncryptionModuleId(), |
|
49 | + ]); |
|
50 | + return 0; |
|
51 | + } |
|
52 | 52 | } |
@@ -29,25 +29,25 @@ |
||
29 | 29 | use Symfony\Component\Console\Output\OutputInterface; |
30 | 30 | |
31 | 31 | class ShowKeyStorageRoot extends Command { |
32 | - public function __construct( |
|
33 | - protected Util $util, |
|
34 | - ) { |
|
35 | - parent::__construct(); |
|
36 | - } |
|
32 | + public function __construct( |
|
33 | + protected Util $util, |
|
34 | + ) { |
|
35 | + parent::__construct(); |
|
36 | + } |
|
37 | 37 | |
38 | - protected function configure() { |
|
39 | - parent::configure(); |
|
40 | - $this |
|
41 | - ->setName('encryption:show-key-storage-root') |
|
42 | - ->setDescription('Show current key storage root'); |
|
43 | - } |
|
38 | + protected function configure() { |
|
39 | + parent::configure(); |
|
40 | + $this |
|
41 | + ->setName('encryption:show-key-storage-root') |
|
42 | + ->setDescription('Show current key storage root'); |
|
43 | + } |
|
44 | 44 | |
45 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
46 | - $currentRoot = $this->util->getKeyStorageRoot(); |
|
45 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
46 | + $currentRoot = $this->util->getKeyStorageRoot(); |
|
47 | 47 | |
48 | - $rootDescription = $currentRoot !== '' ? $currentRoot : 'default storage location (data/)'; |
|
48 | + $rootDescription = $currentRoot !== '' ? $currentRoot : 'default storage location (data/)'; |
|
49 | 49 | |
50 | - $output->writeln("Current key storage root: <info>$rootDescription</info>"); |
|
51 | - return 0; |
|
52 | - } |
|
50 | + $output->writeln("Current key storage root: <info>$rootDescription</info>"); |
|
51 | + return 0; |
|
52 | + } |
|
53 | 53 | } |
@@ -21,150 +21,150 @@ |
||
21 | 21 | use Test\TestCase; |
22 | 22 | |
23 | 23 | class CssControllerTest extends TestCase { |
24 | - /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | - private $appData; |
|
26 | - |
|
27 | - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | - private $request; |
|
29 | - |
|
30 | - /** @var CssController */ |
|
31 | - private $controller; |
|
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('css') |
|
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 CssController( |
|
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->getCss('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->getCss('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.css') |
|
95 | - ->willReturn($file); |
|
96 | - |
|
97 | - $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
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->getCss('file.css', '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.css.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' => 'text/css']); |
|
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->getCss('file.css', '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.css') { |
|
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' => 'text/css']); |
|
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->getCss('file.css', 'myapp'); |
|
168 | - $this->assertEquals($expected, $result); |
|
169 | - } |
|
24 | + /** @var IAppData|\PHPUnit\Framework\MockObject\MockObject */ |
|
25 | + private $appData; |
|
26 | + |
|
27 | + /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
28 | + private $request; |
|
29 | + |
|
30 | + /** @var CssController */ |
|
31 | + private $controller; |
|
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('css') |
|
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 CssController( |
|
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->getCss('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->getCss('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.css') |
|
95 | + ->willReturn($file); |
|
96 | + |
|
97 | + $expected = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => 'text/css']); |
|
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->getCss('file.css', '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.css.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' => 'text/css']); |
|
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->getCss('file.css', '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.css') { |
|
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' => 'text/css']); |
|
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->getCss('file.css', 'myapp'); |
|
168 | + $this->assertEquals($expected, $result); |
|
169 | + } |
|
170 | 170 | } |
@@ -16,47 +16,47 @@ |
||
16 | 16 | use Test\TestCase; |
17 | 17 | |
18 | 18 | class CSRFTokenControllerTest extends TestCase { |
19 | - /** @var CSRFTokenController */ |
|
20 | - private $controller; |
|
19 | + /** @var CSRFTokenController */ |
|
20 | + private $controller; |
|
21 | 21 | |
22 | - /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | - private $request; |
|
22 | + /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */ |
|
23 | + private $request; |
|
24 | 24 | |
25 | - /** @var CsrfTokenManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
26 | - private $tokenManager; |
|
25 | + /** @var CsrfTokenManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
26 | + private $tokenManager; |
|
27 | 27 | |
28 | - protected function setUp(): void { |
|
29 | - parent::setUp(); |
|
28 | + protected function setUp(): void { |
|
29 | + parent::setUp(); |
|
30 | 30 | |
31 | - $this->request = $this->createMock(IRequest::class); |
|
32 | - $this->tokenManager = $this->createMock(CsrfTokenManager::class); |
|
31 | + $this->request = $this->createMock(IRequest::class); |
|
32 | + $this->tokenManager = $this->createMock(CsrfTokenManager::class); |
|
33 | 33 | |
34 | - $this->controller = new CSRFTokenController('core', $this->request, |
|
35 | - $this->tokenManager); |
|
36 | - } |
|
34 | + $this->controller = new CSRFTokenController('core', $this->request, |
|
35 | + $this->tokenManager); |
|
36 | + } |
|
37 | 37 | |
38 | - public function testGetToken(): void { |
|
39 | - $this->request->method('passesStrictCookieCheck')->willReturn(true); |
|
38 | + public function testGetToken(): void { |
|
39 | + $this->request->method('passesStrictCookieCheck')->willReturn(true); |
|
40 | 40 | |
41 | - $token = $this->createMock(CsrfToken::class); |
|
42 | - $this->tokenManager->method('getToken')->willReturn($token); |
|
43 | - $token->method('getEncryptedValue')->willReturn('toktok123'); |
|
41 | + $token = $this->createMock(CsrfToken::class); |
|
42 | + $this->tokenManager->method('getToken')->willReturn($token); |
|
43 | + $token->method('getEncryptedValue')->willReturn('toktok123'); |
|
44 | 44 | |
45 | - $response = $this->controller->index(); |
|
45 | + $response = $this->controller->index(); |
|
46 | 46 | |
47 | - $this->assertInstanceOf(JSONResponse::class, $response); |
|
48 | - $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
49 | - $this->assertEquals([ |
|
50 | - 'token' => 'toktok123' |
|
51 | - ], $response->getData()); |
|
52 | - } |
|
47 | + $this->assertInstanceOf(JSONResponse::class, $response); |
|
48 | + $this->assertSame(Http::STATUS_OK, $response->getStatus()); |
|
49 | + $this->assertEquals([ |
|
50 | + 'token' => 'toktok123' |
|
51 | + ], $response->getData()); |
|
52 | + } |
|
53 | 53 | |
54 | - public function testGetTokenNoStrictSameSiteCookie(): void { |
|
55 | - $this->request->method('passesStrictCookieCheck')->willReturn(false); |
|
54 | + public function testGetTokenNoStrictSameSiteCookie(): void { |
|
55 | + $this->request->method('passesStrictCookieCheck')->willReturn(false); |
|
56 | 56 | |
57 | - $response = $this->controller->index(); |
|
57 | + $response = $this->controller->index(); |
|
58 | 58 | |
59 | - $this->assertInstanceOf(JSONResponse::class, $response); |
|
60 | - $this->assertSame(Http::STATUS_FORBIDDEN, $response->getStatus()); |
|
61 | - } |
|
59 | + $this->assertInstanceOf(JSONResponse::class, $response); |
|
60 | + $this->assertSame(Http::STATUS_FORBIDDEN, $response->getStatus()); |
|
61 | + } |
|
62 | 62 | } |
@@ -14,46 +14,46 @@ |
||
14 | 14 | use Test\TestCase; |
15 | 15 | |
16 | 16 | class UserControllerTest extends TestCase { |
17 | - /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | - private $userManager; |
|
19 | - |
|
20 | - /** @var UserController */ |
|
21 | - private $controller; |
|
22 | - |
|
23 | - protected function setUp(): void { |
|
24 | - parent::setUp(); |
|
25 | - |
|
26 | - $this->userManager = $this->createMock(IUserManager::class); |
|
27 | - $this->controller = new UserController( |
|
28 | - 'core', |
|
29 | - $this->createMock(IRequest::class), |
|
30 | - $this->userManager |
|
31 | - ); |
|
32 | - } |
|
33 | - |
|
34 | - public function testGetDisplayNames(): void { |
|
35 | - $user = $this->createMock(IUser::class); |
|
36 | - $user->method('getDisplayName') |
|
37 | - ->willReturn('FooDisplay Name'); |
|
38 | - |
|
39 | - $this->userManager |
|
40 | - ->method('get') |
|
41 | - ->willReturnCallback(function ($uid) use ($user) { |
|
42 | - if ($uid === 'foo') { |
|
43 | - return $user; |
|
44 | - } |
|
45 | - return null; |
|
46 | - }); |
|
47 | - |
|
48 | - $expected = new JSONResponse([ |
|
49 | - 'users' => [ |
|
50 | - 'foo' => 'FooDisplay Name', |
|
51 | - 'bar' => 'bar', |
|
52 | - ], |
|
53 | - 'status' => 'success' |
|
54 | - ]); |
|
55 | - |
|
56 | - $result = $this->controller->getDisplayNames(['foo', 'bar']); |
|
57 | - $this->assertEquals($expected, $result); |
|
58 | - } |
|
17 | + /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */ |
|
18 | + private $userManager; |
|
19 | + |
|
20 | + /** @var UserController */ |
|
21 | + private $controller; |
|
22 | + |
|
23 | + protected function setUp(): void { |
|
24 | + parent::setUp(); |
|
25 | + |
|
26 | + $this->userManager = $this->createMock(IUserManager::class); |
|
27 | + $this->controller = new UserController( |
|
28 | + 'core', |
|
29 | + $this->createMock(IRequest::class), |
|
30 | + $this->userManager |
|
31 | + ); |
|
32 | + } |
|
33 | + |
|
34 | + public function testGetDisplayNames(): void { |
|
35 | + $user = $this->createMock(IUser::class); |
|
36 | + $user->method('getDisplayName') |
|
37 | + ->willReturn('FooDisplay Name'); |
|
38 | + |
|
39 | + $this->userManager |
|
40 | + ->method('get') |
|
41 | + ->willReturnCallback(function ($uid) use ($user) { |
|
42 | + if ($uid === 'foo') { |
|
43 | + return $user; |
|
44 | + } |
|
45 | + return null; |
|
46 | + }); |
|
47 | + |
|
48 | + $expected = new JSONResponse([ |
|
49 | + 'users' => [ |
|
50 | + 'foo' => 'FooDisplay Name', |
|
51 | + 'bar' => 'bar', |
|
52 | + ], |
|
53 | + 'status' => 'success' |
|
54 | + ]); |
|
55 | + |
|
56 | + $result = $this->controller->getDisplayNames(['foo', 'bar']); |
|
57 | + $this->assertEquals($expected, $result); |
|
58 | + } |
|
59 | 59 | } |
@@ -21,150 +21,150 @@ |
||
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 | } |
@@ -18,52 +18,52 @@ |
||
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 | } |
@@ -17,72 +17,72 @@ |
||
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 | } |
@@ -16,47 +16,47 @@ |
||
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 | } |