|
7 | 7 |
|
8 | 8 | use OCA\SystemTags\Settings\Admin; |
9 | 9 | use OCP\AppFramework\Http\TemplateResponse; |
| 10 | +use OCP\AppFramework\Services\IInitialState; |
| 11 | +use OCP\IAppConfig; |
10 | 12 | use Test\TestCase; |
11 | 13 |
|
12 | 14 | class AdminTest extends TestCase { |
13 | 15 | /** @var Admin */ |
14 | 16 | private $admin; |
| 17 | + /** @var IAppConfig|\PHPUnit\Framework\MockObject\MockObject */ |
| 18 | + private $appConfig; |
| 19 | + /** @var IInitialState|\PHPUnit\Framework\MockObject\MockObject */ |
| 20 | + private $initialState; |
15 | 21 |
|
16 | 22 | protected function setUp(): void { |
17 | 23 | parent::setUp(); |
18 | 24 |
|
19 | | - $this->admin = new Admin(); |
| 25 | + $this->appConfig = $this->createMock(IAppConfig::class); |
| 26 | + $this->initialState = $this->createMock(IInitialState::class); |
| 27 | + |
| 28 | + $this->admin = new Admin( |
| 29 | + $this->appConfig, |
| 30 | + $this->initialState |
| 31 | + ); |
20 | 32 | } |
21 | 33 |
|
22 | 34 | public function testGetForm(): void { |
| 35 | + $this->appConfig->expects($this->once()) |
| 36 | + ->method('getValueBool') |
| 37 | + ->with('systemtags', 'restrict_creation_to_admin', false) |
| 38 | + ->willReturn(false); |
| 39 | + |
| 40 | + $this->initialState->expects($this->once()) |
| 41 | + ->method('provideInitialState') |
| 42 | + ->with('restrictSystemTagsCreationToAdmin', false); |
| 43 | + |
| 44 | + $expected = new TemplateResponse('systemtags', 'admin', [], ''); |
| 45 | + $this->assertEquals($expected, $this->admin->getForm()); |
| 46 | + } |
| 47 | + |
| 48 | + public function testGetFormWithRestrictedCreation(): void { |
| 49 | + $this->appConfig->expects($this->once()) |
| 50 | + ->method('getValueBool') |
| 51 | + ->with('systemtags', 'restrict_creation_to_admin', false) |
| 52 | + ->willReturn(true); |
| 53 | + |
| 54 | + $this->initialState->expects($this->once()) |
| 55 | + ->method('provideInitialState') |
| 56 | + ->with('restrictSystemTagsCreationToAdmin', true); |
| 57 | + |
23 | 58 | $expected = new TemplateResponse('systemtags', 'admin', [], ''); |
24 | 59 | $this->assertEquals($expected, $this->admin->getForm()); |
25 | 60 | } |
|
0 commit comments