Completed
Push — master ( 38c8ea...c9712b )
by Joas
40:21
created
core/Command/Group/Add.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -36,48 +36,48 @@
 block discarded – undo
36 36
 use Symfony\Component\Console\Output\OutputInterface;
37 37
 
38 38
 class Add extends Base {
39
-	public function __construct(
40
-		protected IGroupManager $groupManager,
41
-	) {
42
-		parent::__construct();
43
-	}
39
+    public function __construct(
40
+        protected IGroupManager $groupManager,
41
+    ) {
42
+        parent::__construct();
43
+    }
44 44
 
45
-	protected function configure() {
46
-		$this
47
-			->setName('group:add')
48
-			->setDescription('Add a group')
49
-			->addArgument(
50
-				'groupid',
51
-				InputArgument::REQUIRED,
52
-				'Group id'
53
-			)
54
-			->addOption(
55
-				'display-name',
56
-				null,
57
-				InputOption::VALUE_REQUIRED,
58
-				'Group name used in the web UI (can contain any characters)'
59
-			);
60
-	}
45
+    protected function configure() {
46
+        $this
47
+            ->setName('group:add')
48
+            ->setDescription('Add a group')
49
+            ->addArgument(
50
+                'groupid',
51
+                InputArgument::REQUIRED,
52
+                'Group id'
53
+            )
54
+            ->addOption(
55
+                'display-name',
56
+                null,
57
+                InputOption::VALUE_REQUIRED,
58
+                'Group name used in the web UI (can contain any characters)'
59
+            );
60
+    }
61 61
 
62
-	protected function execute(InputInterface $input, OutputInterface $output): int {
63
-		$gid = $input->getArgument('groupid');
64
-		$group = $this->groupManager->get($gid);
65
-		if ($group) {
66
-			$output->writeln('<error>Group "' . $gid . '" already exists.</error>');
67
-			return 1;
68
-		} else {
69
-			$group = $this->groupManager->createGroup($gid);
70
-			if (!$group instanceof IGroup) {
71
-				$output->writeln('<error>Could not create group</error>');
72
-				return 2;
73
-			}
74
-			$output->writeln('Created group "' . $group->getGID() . '"');
62
+    protected function execute(InputInterface $input, OutputInterface $output): int {
63
+        $gid = $input->getArgument('groupid');
64
+        $group = $this->groupManager->get($gid);
65
+        if ($group) {
66
+            $output->writeln('<error>Group "' . $gid . '" already exists.</error>');
67
+            return 1;
68
+        } else {
69
+            $group = $this->groupManager->createGroup($gid);
70
+            if (!$group instanceof IGroup) {
71
+                $output->writeln('<error>Could not create group</error>');
72
+                return 2;
73
+            }
74
+            $output->writeln('Created group "' . $group->getGID() . '"');
75 75
 
76
-			$displayName = trim((string)$input->getOption('display-name'));
77
-			if ($displayName !== '') {
78
-				$group->setDisplayName($displayName);
79
-			}
80
-		}
81
-		return 0;
82
-	}
76
+            $displayName = trim((string)$input->getOption('display-name'));
77
+            if ($displayName !== '') {
78
+                $group->setDisplayName($displayName);
79
+            }
80
+        }
81
+        return 0;
82
+    }
83 83
 }
Please login to merge, or discard this patch.
core/Command/Group/Info.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -35,56 +35,56 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Info extends Base {
38
-	public function __construct(
39
-		protected IGroupManager $groupManager,
40
-	) {
41
-		parent::__construct();
42
-	}
38
+    public function __construct(
39
+        protected IGroupManager $groupManager,
40
+    ) {
41
+        parent::__construct();
42
+    }
43 43
 
44
-	protected function configure() {
45
-		$this
46
-			->setName('group:info')
47
-			->setDescription('Show information about a group')
48
-			->addArgument(
49
-				'groupid',
50
-				InputArgument::REQUIRED,
51
-				'Group id'
52
-			)->addOption(
53
-				'output',
54
-				null,
55
-				InputOption::VALUE_OPTIONAL,
56
-				'Output format (plain, json or json_pretty, default is plain)',
57
-				$this->defaultOutputFormat
58
-			);
59
-	}
44
+    protected function configure() {
45
+        $this
46
+            ->setName('group:info')
47
+            ->setDescription('Show information about a group')
48
+            ->addArgument(
49
+                'groupid',
50
+                InputArgument::REQUIRED,
51
+                'Group id'
52
+            )->addOption(
53
+                'output',
54
+                null,
55
+                InputOption::VALUE_OPTIONAL,
56
+                'Output format (plain, json or json_pretty, default is plain)',
57
+                $this->defaultOutputFormat
58
+            );
59
+    }
60 60
 
61
-	protected function execute(InputInterface $input, OutputInterface $output): int {
62
-		$gid = $input->getArgument('groupid');
63
-		$group = $this->groupManager->get($gid);
64
-		if (!$group instanceof IGroup) {
65
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
-			return 1;
67
-		} else {
68
-			$groupOutput = [
69
-				'groupID' => $gid,
70
-				'displayName' => $group->getDisplayName(),
71
-				'backends' => $group->getBackendNames(),
72
-			];
61
+    protected function execute(InputInterface $input, OutputInterface $output): int {
62
+        $gid = $input->getArgument('groupid');
63
+        $group = $this->groupManager->get($gid);
64
+        if (!$group instanceof IGroup) {
65
+            $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
+            return 1;
67
+        } else {
68
+            $groupOutput = [
69
+                'groupID' => $gid,
70
+                'displayName' => $group->getDisplayName(),
71
+                'backends' => $group->getBackendNames(),
72
+            ];
73 73
 
74
-			$this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
-			return 0;
76
-		}
77
-	}
74
+            $this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
+            return 0;
76
+        }
77
+    }
78 78
 
79
-	/**
80
-	 * @param string $argumentName
81
-	 * @param CompletionContext $context
82
-	 * @return string[]
83
-	 */
84
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
85
-		if ($argumentName === 'groupid') {
86
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
-		}
88
-		return [];
89
-	}
79
+    /**
80
+     * @param string $argumentName
81
+     * @param CompletionContext $context
82
+     * @return string[]
83
+     */
84
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
85
+        if ($argumentName === 'groupid') {
86
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
+        }
88
+        return [];
89
+    }
90 90
 }
Please login to merge, or discard this patch.
core/Command/Group/Delete.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -35,52 +35,52 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Delete extends Base {
38
-	public function __construct(
39
-		protected IGroupManager $groupManager,
40
-	) {
41
-		parent::__construct();
42
-	}
38
+    public function __construct(
39
+        protected IGroupManager $groupManager,
40
+    ) {
41
+        parent::__construct();
42
+    }
43 43
 
44
-	protected function configure() {
45
-		$this
46
-			->setName('group:delete')
47
-			->setDescription('Remove a group')
48
-			->addArgument(
49
-				'groupid',
50
-				InputArgument::REQUIRED,
51
-				'Group name'
52
-			);
53
-	}
44
+    protected function configure() {
45
+        $this
46
+            ->setName('group:delete')
47
+            ->setDescription('Remove a group')
48
+            ->addArgument(
49
+                'groupid',
50
+                InputArgument::REQUIRED,
51
+                'Group name'
52
+            );
53
+    }
54 54
 
55
-	protected function execute(InputInterface $input, OutputInterface $output): int {
56
-		$gid = $input->getArgument('groupid');
57
-		if ($gid === 'admin') {
58
-			$output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
59
-			return 1;
60
-		}
61
-		if (!$this->groupManager->groupExists($gid)) {
62
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
63
-			return 1;
64
-		}
65
-		$group = $this->groupManager->get($gid);
66
-		if ($group->delete()) {
67
-			$output->writeln('Group "' . $gid . '" was removed');
68
-		} else {
69
-			$output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>');
70
-			return 1;
71
-		}
72
-		return 0;
73
-	}
55
+    protected function execute(InputInterface $input, OutputInterface $output): int {
56
+        $gid = $input->getArgument('groupid');
57
+        if ($gid === 'admin') {
58
+            $output->writeln('<error>Group "' . $gid . '" could not be deleted.</error>');
59
+            return 1;
60
+        }
61
+        if (!$this->groupManager->groupExists($gid)) {
62
+            $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
63
+            return 1;
64
+        }
65
+        $group = $this->groupManager->get($gid);
66
+        if ($group->delete()) {
67
+            $output->writeln('Group "' . $gid . '" was removed');
68
+        } else {
69
+            $output->writeln('<error>Group "' . $gid . '" could not be deleted. Please check the logs.</error>');
70
+            return 1;
71
+        }
72
+        return 0;
73
+    }
74 74
 
75
-	/**
76
-	 * @param string $argumentName
77
-	 * @param CompletionContext $context
78
-	 * @return string[]
79
-	 */
80
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
81
-		if ($argumentName === 'groupid') {
82
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
83
-		}
84
-		return [];
85
-	}
75
+    /**
76
+     * @param string $argumentName
77
+     * @param CompletionContext $context
78
+     * @return string[]
79
+     */
80
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
81
+        if ($argumentName === 'groupid') {
82
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
83
+        }
84
+        return [];
85
+    }
86 86
 }
Please login to merge, or discard this patch.
core/Command/Group/RemoveUser.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -34,60 +34,60 @@
 block discarded – undo
34 34
 use Symfony\Component\Console\Output\OutputInterface;
35 35
 
36 36
 class RemoveUser extends Base {
37
-	public function __construct(
38
-		protected IUserManager $userManager,
39
-		protected IGroupManager $groupManager,
40
-	) {
41
-		parent::__construct();
42
-	}
37
+    public function __construct(
38
+        protected IUserManager $userManager,
39
+        protected IGroupManager $groupManager,
40
+    ) {
41
+        parent::__construct();
42
+    }
43 43
 
44
-	protected function configure() {
45
-		$this
46
-			->setName('group:removeuser')
47
-			->setDescription('remove a user from a group')
48
-			->addArgument(
49
-				'group',
50
-				InputArgument::REQUIRED,
51
-				'group to remove the user from'
52
-			)->addArgument(
53
-				'user',
54
-				InputArgument::REQUIRED,
55
-				'user to remove from the group'
56
-			);
57
-	}
44
+    protected function configure() {
45
+        $this
46
+            ->setName('group:removeuser')
47
+            ->setDescription('remove a user from a group')
48
+            ->addArgument(
49
+                'group',
50
+                InputArgument::REQUIRED,
51
+                'group to remove the user from'
52
+            )->addArgument(
53
+                'user',
54
+                InputArgument::REQUIRED,
55
+                'user to remove from the group'
56
+            );
57
+    }
58 58
 
59
-	protected function execute(InputInterface $input, OutputInterface $output): int {
60
-		$group = $this->groupManager->get($input->getArgument('group'));
61
-		if (is_null($group)) {
62
-			$output->writeln('<error>group not found</error>');
63
-			return 1;
64
-		}
65
-		$user = $this->userManager->get($input->getArgument('user'));
66
-		if (is_null($user)) {
67
-			$output->writeln('<error>user not found</error>');
68
-			return 1;
69
-		}
70
-		$group->removeUser($user);
71
-		return 0;
72
-	}
59
+    protected function execute(InputInterface $input, OutputInterface $output): int {
60
+        $group = $this->groupManager->get($input->getArgument('group'));
61
+        if (is_null($group)) {
62
+            $output->writeln('<error>group not found</error>');
63
+            return 1;
64
+        }
65
+        $user = $this->userManager->get($input->getArgument('user'));
66
+        if (is_null($user)) {
67
+            $output->writeln('<error>user not found</error>');
68
+            return 1;
69
+        }
70
+        $group->removeUser($user);
71
+        return 0;
72
+    }
73 73
 
74
-	/**
75
-	 * @param string $argumentName
76
-	 * @param CompletionContext $context
77
-	 * @return string[]
78
-	 */
79
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
80
-		if ($argumentName === 'group') {
81
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
82
-		}
83
-		if ($argumentName === 'user') {
84
-			$groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
85
-			$group = $this->groupManager->get($groupId);
86
-			if ($group === null) {
87
-				return [];
88
-			}
89
-			return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
90
-		}
91
-		return [];
92
-	}
74
+    /**
75
+     * @param string $argumentName
76
+     * @param CompletionContext $context
77
+     * @return string[]
78
+     */
79
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
80
+        if ($argumentName === 'group') {
81
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
82
+        }
83
+        if ($argumentName === 'user') {
84
+            $groupId = $context->getWordAtIndex($context->getWordIndex() - 1);
85
+            $group = $this->groupManager->get($groupId);
86
+            if ($group === null) {
87
+                return [];
88
+            }
89
+            return array_map(static fn (IUser $user) => $user->getUID(), $group->searchUsers($context->getCurrentWord()));
90
+        }
91
+        return [];
92
+    }
93 93
 }
Please login to merge, or discard this patch.
core/Command/Encryption/Disable.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -27,26 +27,26 @@
 block discarded – undo
27 27
 use Symfony\Component\Console\Output\OutputInterface;
28 28
 
29 29
 class Disable extends Command {
30
-	public function __construct(
31
-		protected IConfig $config,
32
-	) {
33
-		parent::__construct();
34
-	}
30
+    public function __construct(
31
+        protected IConfig $config,
32
+    ) {
33
+        parent::__construct();
34
+    }
35 35
 
36
-	protected function configure() {
37
-		$this
38
-			->setName('encryption:disable')
39
-			->setDescription('Disable encryption')
40
-		;
41
-	}
36
+    protected function configure() {
37
+        $this
38
+            ->setName('encryption:disable')
39
+            ->setDescription('Disable encryption')
40
+        ;
41
+    }
42 42
 
43
-	protected function execute(InputInterface $input, OutputInterface $output): int {
44
-		if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') {
45
-			$output->writeln('Encryption is already disabled');
46
-		} else {
47
-			$this->config->setAppValue('core', 'encryption_enabled', 'no');
48
-			$output->writeln('<info>Encryption disabled</info>');
49
-		}
50
-		return 0;
51
-	}
43
+    protected function execute(InputInterface $input, OutputInterface $output): int {
44
+        if ($this->config->getAppValue('core', 'encryption_enabled', 'no') !== 'yes') {
45
+            $output->writeln('Encryption is already disabled');
46
+        } else {
47
+            $this->config->setAppValue('core', 'encryption_enabled', 'no');
48
+            $output->writeln('<info>Encryption disabled</info>');
49
+        }
50
+        return 0;
51
+    }
52 52
 }
Please login to merge, or discard this patch.
core/Command/Encryption/Status.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -27,26 +27,26 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/Command/Encryption/ShowKeyStorageRoot.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -29,25 +29,25 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
tests/Core/Controller/CssControllerTest.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 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
 }
Please login to merge, or discard this patch.
tests/Core/Controller/CSRFTokenControllerTest.php 1 patch
Indentation   +31 added lines, -31 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 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
 }
Please login to merge, or discard this patch.