Completed
Push — master ( 6694cf...217be4 )
by
unknown
20:04 queued 15s
created
apps/settings/tests/UserMigration/AccountMigratorTest.php 2 patches
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -27,141 +27,141 @@
 block discarded – undo
27 27
  * @group DB
28 28
  */
29 29
 class AccountMigratorTest extends TestCase {
30
-	private IUserManager $userManager;
31
-	private IAvatarManager $avatarManager;
32
-	private AccountMigrator $migrator;
33
-	private IImportSource&MockObject $importSource;
34
-	private IExportDestination&MockObject $exportDestination;
35
-	private OutputInterface&MockObject $output;
36
-
37
-	private const ASSETS_DIR = __DIR__ . '/assets/';
38
-
39
-	private const REGEX_ACCOUNT_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
40
-
41
-	private const REGEX_AVATAR_FILE = '/^' . Application::APP_ID . '\/' . 'avatar\.(jpg|png)' . '$/';
42
-
43
-	private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
44
-
45
-	protected function setUp(): void {
46
-		parent::setUp();
47
-
48
-		$app = new App(Application::APP_ID);
49
-		$container = $app->getContainer();
50
-		$container->get(IConfig::class)->setSystemValue('has_internet_connection', false);
51
-
52
-		$this->userManager = $container->get(IUserManager::class);
53
-		$this->avatarManager = $container->get(IAvatarManager::class);
54
-		$this->migrator = $container->get(AccountMigrator::class);
55
-
56
-		$this->importSource = $this->createMock(IImportSource::class);
57
-		$this->exportDestination = $this->createMock(IExportDestination::class);
58
-		$this->output = $this->createMock(OutputInterface::class);
59
-	}
60
-
61
-	protected function tearDown(): void {
62
-		Server::get(IConfig::class)->setSystemValue('has_internet_connection', true);
63
-		parent::tearDown();
64
-	}
65
-
66
-	public static function dataImportExportAccount(): array {
67
-		return array_map(
68
-			static function (string $filename): array {
69
-				$dataPath = static::ASSETS_DIR . $filename;
70
-				// For each account json file there is an avatar image and a config json file with the same basename
71
-				$basename = pathinfo($filename, PATHINFO_FILENAME);
72
-				$avatarPath = static::ASSETS_DIR . (file_exists(static::ASSETS_DIR . "$basename.jpg") ? "$basename.jpg" : "$basename.png");
73
-				$configPath = static::ASSETS_DIR . "$basename-config." . pathinfo($filename, PATHINFO_EXTENSION);
74
-				return [
75
-					UUIDUtil::getUUID(),
76
-					json_decode(file_get_contents($dataPath), true, 512, JSON_THROW_ON_ERROR),
77
-					$avatarPath,
78
-					json_decode(file_get_contents($configPath), true, 512, JSON_THROW_ON_ERROR),
79
-				];
80
-			},
81
-			array_filter(
82
-				scandir(static::ASSETS_DIR),
83
-				fn (string $filename) => pathinfo($filename, PATHINFO_EXTENSION) === 'json' && mb_strpos(pathinfo($filename, PATHINFO_FILENAME), 'config') === false,
84
-			),
85
-		);
86
-	}
87
-
88
-	/**
89
-	 * @dataProvider dataImportExportAccount
90
-	 */
91
-	public function testImportExportAccount(string $userId, array $importData, string $avatarPath, array $importConfig): void {
92
-		$user = $this->userManager->createUser($userId, 'topsecretpassword');
93
-		$avatarExt = pathinfo($avatarPath, PATHINFO_EXTENSION);
94
-		$exportData = $importData;
95
-		$exportConfig = $importConfig;
96
-		// Verification status of email will be set to in progress on import so we set the export data to reflect that
97
-		$exportData[IAccountManager::PROPERTY_EMAIL]['verified'] = IAccountManager::VERIFICATION_IN_PROGRESS;
98
-
99
-		$this->importSource
100
-			->expects($this->once())
101
-			->method('getMigratorVersion')
102
-			->with($this->migrator->getId())
103
-			->willReturn(1);
104
-
105
-		$calls = [
106
-			[static::REGEX_ACCOUNT_FILE, json_encode($importData)],
107
-			[static::REGEX_CONFIG_FILE, json_encode($importConfig)],
108
-		];
109
-		$this->importSource
110
-			->expects($this->exactly(2))
111
-			->method('getFileContents')
112
-			->willReturnCallback(function ($path) use (&$calls) {
113
-				$expected = array_shift($calls);
114
-				$this->assertMatchesRegularExpression($expected[0], $path);
115
-				return $expected[1];
116
-			});
117
-
118
-		$this->importSource
119
-			->expects($this->once())
120
-			->method('getFolderListing')
121
-			->with(Application::APP_ID . '/')
122
-			->willReturn(["avatar.$avatarExt"]);
123
-
124
-		$this->importSource
125
-			->expects($this->once())
126
-			->method('getFileAsStream')
127
-			->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE))
128
-			->willReturn(fopen($avatarPath, 'r'));
129
-
130
-		$this->migrator->import($user, $this->importSource, $this->output);
131
-
132
-		$importedAvatar = $this->avatarManager->getAvatar($user->getUID());
133
-		$this->assertTrue($importedAvatar->isCustomAvatar());
134
-
135
-		/**
136
-		 * Avatar images are re-encoded on import therefore JPEG images which use lossy compression cannot be checked for equality
137
-		 * @see https://github.com/nextcloud/server/blob/9644b7e505dc90a1e683f77ad38dc6dc4e90fa2f/lib/private/legacy/OC_Image.php#L383-L390
138
-		 */
139
-
140
-		if ($avatarExt !== 'jpg') {
141
-			$this->assertStringEqualsFile(
142
-				$avatarPath,
143
-				$importedAvatar->getFile(-1)->getContent(),
144
-			);
145
-		}
146
-
147
-		$calls = [
148
-			[static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))],
149
-			[static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))],
150
-		];
151
-		$this->exportDestination
152
-			->expects($this->exactly(2))
153
-			->method('addFileContents')
154
-			->willReturnCallback(function ($path) use (&$calls) {
155
-				$expected = array_shift($calls);
156
-				$this->assertMatchesRegularExpression($expected[0], $path);
157
-				return $expected[1];
158
-			});
159
-
160
-		$this->exportDestination
161
-			->expects($this->once())
162
-			->method('addFileAsStream')
163
-			->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE), $this->isType('resource'));
164
-
165
-		$this->migrator->export($user, $this->exportDestination, $this->output);
166
-	}
30
+    private IUserManager $userManager;
31
+    private IAvatarManager $avatarManager;
32
+    private AccountMigrator $migrator;
33
+    private IImportSource&MockObject $importSource;
34
+    private IExportDestination&MockObject $exportDestination;
35
+    private OutputInterface&MockObject $output;
36
+
37
+    private const ASSETS_DIR = __DIR__ . '/assets/';
38
+
39
+    private const REGEX_ACCOUNT_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
40
+
41
+    private const REGEX_AVATAR_FILE = '/^' . Application::APP_ID . '\/' . 'avatar\.(jpg|png)' . '$/';
42
+
43
+    private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
44
+
45
+    protected function setUp(): void {
46
+        parent::setUp();
47
+
48
+        $app = new App(Application::APP_ID);
49
+        $container = $app->getContainer();
50
+        $container->get(IConfig::class)->setSystemValue('has_internet_connection', false);
51
+
52
+        $this->userManager = $container->get(IUserManager::class);
53
+        $this->avatarManager = $container->get(IAvatarManager::class);
54
+        $this->migrator = $container->get(AccountMigrator::class);
55
+
56
+        $this->importSource = $this->createMock(IImportSource::class);
57
+        $this->exportDestination = $this->createMock(IExportDestination::class);
58
+        $this->output = $this->createMock(OutputInterface::class);
59
+    }
60
+
61
+    protected function tearDown(): void {
62
+        Server::get(IConfig::class)->setSystemValue('has_internet_connection', true);
63
+        parent::tearDown();
64
+    }
65
+
66
+    public static function dataImportExportAccount(): array {
67
+        return array_map(
68
+            static function (string $filename): array {
69
+                $dataPath = static::ASSETS_DIR . $filename;
70
+                // For each account json file there is an avatar image and a config json file with the same basename
71
+                $basename = pathinfo($filename, PATHINFO_FILENAME);
72
+                $avatarPath = static::ASSETS_DIR . (file_exists(static::ASSETS_DIR . "$basename.jpg") ? "$basename.jpg" : "$basename.png");
73
+                $configPath = static::ASSETS_DIR . "$basename-config." . pathinfo($filename, PATHINFO_EXTENSION);
74
+                return [
75
+                    UUIDUtil::getUUID(),
76
+                    json_decode(file_get_contents($dataPath), true, 512, JSON_THROW_ON_ERROR),
77
+                    $avatarPath,
78
+                    json_decode(file_get_contents($configPath), true, 512, JSON_THROW_ON_ERROR),
79
+                ];
80
+            },
81
+            array_filter(
82
+                scandir(static::ASSETS_DIR),
83
+                fn (string $filename) => pathinfo($filename, PATHINFO_EXTENSION) === 'json' && mb_strpos(pathinfo($filename, PATHINFO_FILENAME), 'config') === false,
84
+            ),
85
+        );
86
+    }
87
+
88
+    /**
89
+     * @dataProvider dataImportExportAccount
90
+     */
91
+    public function testImportExportAccount(string $userId, array $importData, string $avatarPath, array $importConfig): void {
92
+        $user = $this->userManager->createUser($userId, 'topsecretpassword');
93
+        $avatarExt = pathinfo($avatarPath, PATHINFO_EXTENSION);
94
+        $exportData = $importData;
95
+        $exportConfig = $importConfig;
96
+        // Verification status of email will be set to in progress on import so we set the export data to reflect that
97
+        $exportData[IAccountManager::PROPERTY_EMAIL]['verified'] = IAccountManager::VERIFICATION_IN_PROGRESS;
98
+
99
+        $this->importSource
100
+            ->expects($this->once())
101
+            ->method('getMigratorVersion')
102
+            ->with($this->migrator->getId())
103
+            ->willReturn(1);
104
+
105
+        $calls = [
106
+            [static::REGEX_ACCOUNT_FILE, json_encode($importData)],
107
+            [static::REGEX_CONFIG_FILE, json_encode($importConfig)],
108
+        ];
109
+        $this->importSource
110
+            ->expects($this->exactly(2))
111
+            ->method('getFileContents')
112
+            ->willReturnCallback(function ($path) use (&$calls) {
113
+                $expected = array_shift($calls);
114
+                $this->assertMatchesRegularExpression($expected[0], $path);
115
+                return $expected[1];
116
+            });
117
+
118
+        $this->importSource
119
+            ->expects($this->once())
120
+            ->method('getFolderListing')
121
+            ->with(Application::APP_ID . '/')
122
+            ->willReturn(["avatar.$avatarExt"]);
123
+
124
+        $this->importSource
125
+            ->expects($this->once())
126
+            ->method('getFileAsStream')
127
+            ->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE))
128
+            ->willReturn(fopen($avatarPath, 'r'));
129
+
130
+        $this->migrator->import($user, $this->importSource, $this->output);
131
+
132
+        $importedAvatar = $this->avatarManager->getAvatar($user->getUID());
133
+        $this->assertTrue($importedAvatar->isCustomAvatar());
134
+
135
+        /**
136
+         * Avatar images are re-encoded on import therefore JPEG images which use lossy compression cannot be checked for equality
137
+         * @see https://github.com/nextcloud/server/blob/9644b7e505dc90a1e683f77ad38dc6dc4e90fa2f/lib/private/legacy/OC_Image.php#L383-L390
138
+         */
139
+
140
+        if ($avatarExt !== 'jpg') {
141
+            $this->assertStringEqualsFile(
142
+                $avatarPath,
143
+                $importedAvatar->getFile(-1)->getContent(),
144
+            );
145
+        }
146
+
147
+        $calls = [
148
+            [static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))],
149
+            [static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))],
150
+        ];
151
+        $this->exportDestination
152
+            ->expects($this->exactly(2))
153
+            ->method('addFileContents')
154
+            ->willReturnCallback(function ($path) use (&$calls) {
155
+                $expected = array_shift($calls);
156
+                $this->assertMatchesRegularExpression($expected[0], $path);
157
+                return $expected[1];
158
+            });
159
+
160
+        $this->exportDestination
161
+            ->expects($this->once())
162
+            ->method('addFileAsStream')
163
+            ->with($this->matchesRegularExpression(static::REGEX_AVATAR_FILE), $this->isType('resource'));
164
+
165
+        $this->migrator->export($user, $this->exportDestination, $this->output);
166
+    }
167 167
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@  discard block
 block discarded – undo
34 34
 	private IExportDestination&MockObject $exportDestination;
35 35
 	private OutputInterface&MockObject $output;
36 36
 
37
-	private const ASSETS_DIR = __DIR__ . '/assets/';
37
+	private const ASSETS_DIR = __DIR__.'/assets/';
38 38
 
39
-	private const REGEX_ACCOUNT_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
39
+	private const REGEX_ACCOUNT_FILE = '/^'.Application::APP_ID.'\/'.'[a-z]+\.json'.'$/';
40 40
 
41
-	private const REGEX_AVATAR_FILE = '/^' . Application::APP_ID . '\/' . 'avatar\.(jpg|png)' . '$/';
41
+	private const REGEX_AVATAR_FILE = '/^'.Application::APP_ID.'\/'.'avatar\.(jpg|png)'.'$/';
42 42
 
43
-	private const REGEX_CONFIG_FILE = '/^' . Application::APP_ID . '\/' . '[a-z]+\.json' . '$/';
43
+	private const REGEX_CONFIG_FILE = '/^'.Application::APP_ID.'\/'.'[a-z]+\.json'.'$/';
44 44
 
45 45
 	protected function setUp(): void {
46 46
 		parent::setUp();
@@ -65,12 +65,12 @@  discard block
 block discarded – undo
65 65
 
66 66
 	public static function dataImportExportAccount(): array {
67 67
 		return array_map(
68
-			static function (string $filename): array {
69
-				$dataPath = static::ASSETS_DIR . $filename;
68
+			static function(string $filename): array {
69
+				$dataPath = static::ASSETS_DIR.$filename;
70 70
 				// For each account json file there is an avatar image and a config json file with the same basename
71 71
 				$basename = pathinfo($filename, PATHINFO_FILENAME);
72
-				$avatarPath = static::ASSETS_DIR . (file_exists(static::ASSETS_DIR . "$basename.jpg") ? "$basename.jpg" : "$basename.png");
73
-				$configPath = static::ASSETS_DIR . "$basename-config." . pathinfo($filename, PATHINFO_EXTENSION);
72
+				$avatarPath = static::ASSETS_DIR.(file_exists(static::ASSETS_DIR."$basename.jpg") ? "$basename.jpg" : "$basename.png");
73
+				$configPath = static::ASSETS_DIR."$basename-config.".pathinfo($filename, PATHINFO_EXTENSION);
74 74
 				return [
75 75
 					UUIDUtil::getUUID(),
76 76
 					json_decode(file_get_contents($dataPath), true, 512, JSON_THROW_ON_ERROR),
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
 		$this->importSource
110 110
 			->expects($this->exactly(2))
111 111
 			->method('getFileContents')
112
-			->willReturnCallback(function ($path) use (&$calls) {
112
+			->willReturnCallback(function($path) use (&$calls) {
113 113
 				$expected = array_shift($calls);
114 114
 				$this->assertMatchesRegularExpression($expected[0], $path);
115 115
 				return $expected[1];
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$this->importSource
119 119
 			->expects($this->once())
120 120
 			->method('getFolderListing')
121
-			->with(Application::APP_ID . '/')
121
+			->with(Application::APP_ID.'/')
122 122
 			->willReturn(["avatar.$avatarExt"]);
123 123
 
124 124
 		$this->importSource
@@ -146,12 +146,12 @@  discard block
 block discarded – undo
146 146
 
147 147
 		$calls = [
148 148
 			[static::REGEX_ACCOUNT_FILE, new JsonMatches(json_encode($importData))],
149
-			[static::REGEX_CONFIG_FILE,new JsonMatches(json_encode($importConfig))],
149
+			[static::REGEX_CONFIG_FILE, new JsonMatches(json_encode($importConfig))],
150 150
 		];
151 151
 		$this->exportDestination
152 152
 			->expects($this->exactly(2))
153 153
 			->method('addFileContents')
154
-			->willReturnCallback(function ($path) use (&$calls) {
154
+			->willReturnCallback(function($path) use (&$calls) {
155 155
 				$expected = array_shift($calls);
156 156
 				$this->assertMatchesRegularExpression($expected[0], $path);
157 157
 				return $expected[1];
Please login to merge, or discard this patch.
apps/settings/tests/AppInfo/ApplicationTest.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -28,38 +28,38 @@
 block discarded – undo
28 28
  * @group DB
29 29
  */
30 30
 class ApplicationTest extends TestCase {
31
-	protected Application $app;
32
-	protected IAppContainer $container;
31
+    protected Application $app;
32
+    protected IAppContainer $container;
33 33
 
34
-	protected function setUp(): void {
35
-		parent::setUp();
36
-		$this->app = new Application();
37
-		$this->container = $this->app->getContainer();
38
-	}
34
+    protected function setUp(): void {
35
+        parent::setUp();
36
+        $this->app = new Application();
37
+        $this->container = $this->app->getContainer();
38
+    }
39 39
 
40
-	public function testContainerAppName(): void {
41
-		$this->app = new Application();
42
-		$this->assertEquals('settings', $this->container->getAppName());
43
-	}
40
+    public function testContainerAppName(): void {
41
+        $this->app = new Application();
42
+        $this->assertEquals('settings', $this->container->getAppName());
43
+    }
44 44
 
45
-	public static function dataContainerQuery(): array {
46
-		return [
47
-			[AdminSettingsController::class, Controller::class],
48
-			[AppSettingsController::class, Controller::class],
49
-			[AuthSettingsController::class, Controller::class],
50
-			[CheckSetupController::class, Controller::class],
51
-			[LogSettingsController::class, Controller::class],
52
-			[MailSettingsController::class, Controller::class],
53
-			[UsersController::class, Controller::class],
45
+    public static function dataContainerQuery(): array {
46
+        return [
47
+            [AdminSettingsController::class, Controller::class],
48
+            [AppSettingsController::class, Controller::class],
49
+            [AuthSettingsController::class, Controller::class],
50
+            [CheckSetupController::class, Controller::class],
51
+            [LogSettingsController::class, Controller::class],
52
+            [MailSettingsController::class, Controller::class],
53
+            [UsersController::class, Controller::class],
54 54
 
55
-			[SubadminMiddleware::class, Middleware::class],
56
-		];
57
-	}
55
+            [SubadminMiddleware::class, Middleware::class],
56
+        ];
57
+    }
58 58
 
59
-	/**
60
-	 * @dataProvider dataContainerQuery
61
-	 */
62
-	public function testContainerQuery(string $service, string $expected): void {
63
-		$this->assertTrue($this->container->query($service) instanceof $expected);
64
-	}
59
+    /**
60
+     * @dataProvider dataContainerQuery
61
+     */
62
+    public function testContainerQuery(string $service, string $expected): void {
63
+        $this->assertTrue($this->container->query($service) instanceof $expected);
64
+    }
65 65
 }
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/OcxProvicersTest.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -20,132 +20,132 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class OcxProvicersTest extends TestCase {
23
-	private IL10N|MockObject $l10n;
24
-	private IConfig|MockObject $config;
25
-	private IURLGenerator|MockObject $urlGenerator;
26
-	private IClientService|MockObject $clientService;
27
-	private LoggerInterface|MockObject $logger;
28
-	private OcxProviders|MockObject $setupcheck;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->l10n = $this->createMock(IL10N::class);
34
-		$this->l10n->expects($this->any())
35
-			->method('t')
36
-			->willReturnCallback(function ($message, array $replace) {
37
-				return vsprintf($message, $replace);
38
-			});
39
-
40
-		$this->config = $this->createMock(IConfig::class);
41
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
42
-		$this->clientService = $this->createMock(IClientService::class);
43
-		$this->logger = $this->createMock(LoggerInterface::class);
44
-
45
-		$this->setupcheck = $this->getMockBuilder(OcxProviders::class)
46
-			->onlyMethods(['runRequest'])
47
-			->setConstructorArgs([
48
-				$this->l10n,
49
-				$this->config,
50
-				$this->urlGenerator,
51
-				$this->clientService,
52
-				$this->logger,
53
-			])
54
-			->getMock();
55
-	}
56
-
57
-	public function testSuccess(): void {
58
-		$response = $this->createMock(IResponse::class);
59
-		$response->expects($this->any())->method('getStatusCode')->willReturn(200);
60
-
61
-		$this->setupcheck
62
-			->expects($this->exactly(2))
63
-			->method('runRequest')
64
-			->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response]));
65
-
66
-		$result = $this->setupcheck->run();
67
-		$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
68
-	}
69
-
70
-	public function testLateSuccess(): void {
71
-		$response1 = $this->createMock(IResponse::class);
72
-		$response1->expects($this->exactly(3))->method('getStatusCode')->willReturnOnConsecutiveCalls(404, 500, 200);
73
-		$response2 = $this->createMock(IResponse::class);
74
-		$response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
75
-
76
-		$this->setupcheck
77
-			->expects($this->exactly(2))
78
-			->method('runRequest')
79
-			->willReturnOnConsecutiveCalls($this->generate([$response1, $response1, $response1]), $this->generate([$response2])); // only one response out of two
80
-
81
-		$result = $this->setupcheck->run();
82
-		$this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
83
-	}
84
-
85
-	public function testNoResponse(): void {
86
-		$response = $this->createMock(IResponse::class);
87
-		$response->expects($this->any())->method('getStatusCode')->willReturn(200);
88
-
89
-		$this->setupcheck
90
-			->expects($this->exactly(2))
91
-			->method('runRequest')
92
-			->willReturnOnConsecutiveCalls($this->generate([]), $this->generate([])); // No responses
93
-
94
-		$result = $this->setupcheck->run();
95
-		$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
96
-		$this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
97
-	}
98
-
99
-	public function testPartialResponse(): void {
100
-		$response = $this->createMock(IResponse::class);
101
-		$response->expects($this->any())->method('getStatusCode')->willReturn(200);
102
-
103
-		$this->setupcheck
104
-			->expects($this->exactly(2))
105
-			->method('runRequest')
106
-			->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([])); // only one response out of two
107
-
108
-		$result = $this->setupcheck->run();
109
-		$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
110
-		$this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
111
-	}
112
-
113
-	public function testInvalidResponse(): void {
114
-		$response = $this->createMock(IResponse::class);
115
-		$response->expects($this->any())->method('getStatusCode')->willReturn(404);
116
-
117
-		$this->setupcheck
118
-			->expects($this->exactly(2))
119
-			->method('runRequest')
120
-			->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response])); // only one response out of two
121
-
122
-		$result = $this->setupcheck->run();
123
-		$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
124
-		$this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
125
-	}
126
-
127
-	public function testPartialInvalidResponse(): void {
128
-		$response1 = $this->createMock(IResponse::class);
129
-		$response1->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
130
-		$response2 = $this->createMock(IResponse::class);
131
-		$response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(404);
132
-
133
-		$this->setupcheck
134
-			->expects($this->exactly(2))
135
-			->method('runRequest')
136
-			->willReturnOnConsecutiveCalls($this->generate([$response1]), $this->generate([$response2]));
137
-
138
-		$result = $this->setupcheck->run();
139
-		$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
140
-		$this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
141
-	}
142
-
143
-	/**
144
-	 * Helper function creates a nicer interface for mocking Generator behavior
145
-	 */
146
-	protected function generate(array $yield_values) {
147
-		return $this->returnCallback(function () use ($yield_values) {
148
-			yield from $yield_values;
149
-		});
150
-	}
23
+    private IL10N|MockObject $l10n;
24
+    private IConfig|MockObject $config;
25
+    private IURLGenerator|MockObject $urlGenerator;
26
+    private IClientService|MockObject $clientService;
27
+    private LoggerInterface|MockObject $logger;
28
+    private OcxProviders|MockObject $setupcheck;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->l10n = $this->createMock(IL10N::class);
34
+        $this->l10n->expects($this->any())
35
+            ->method('t')
36
+            ->willReturnCallback(function ($message, array $replace) {
37
+                return vsprintf($message, $replace);
38
+            });
39
+
40
+        $this->config = $this->createMock(IConfig::class);
41
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
42
+        $this->clientService = $this->createMock(IClientService::class);
43
+        $this->logger = $this->createMock(LoggerInterface::class);
44
+
45
+        $this->setupcheck = $this->getMockBuilder(OcxProviders::class)
46
+            ->onlyMethods(['runRequest'])
47
+            ->setConstructorArgs([
48
+                $this->l10n,
49
+                $this->config,
50
+                $this->urlGenerator,
51
+                $this->clientService,
52
+                $this->logger,
53
+            ])
54
+            ->getMock();
55
+    }
56
+
57
+    public function testSuccess(): void {
58
+        $response = $this->createMock(IResponse::class);
59
+        $response->expects($this->any())->method('getStatusCode')->willReturn(200);
60
+
61
+        $this->setupcheck
62
+            ->expects($this->exactly(2))
63
+            ->method('runRequest')
64
+            ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response]));
65
+
66
+        $result = $this->setupcheck->run();
67
+        $this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
68
+    }
69
+
70
+    public function testLateSuccess(): void {
71
+        $response1 = $this->createMock(IResponse::class);
72
+        $response1->expects($this->exactly(3))->method('getStatusCode')->willReturnOnConsecutiveCalls(404, 500, 200);
73
+        $response2 = $this->createMock(IResponse::class);
74
+        $response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
75
+
76
+        $this->setupcheck
77
+            ->expects($this->exactly(2))
78
+            ->method('runRequest')
79
+            ->willReturnOnConsecutiveCalls($this->generate([$response1, $response1, $response1]), $this->generate([$response2])); // only one response out of two
80
+
81
+        $result = $this->setupcheck->run();
82
+        $this->assertEquals(SetupResult::SUCCESS, $result->getSeverity());
83
+    }
84
+
85
+    public function testNoResponse(): void {
86
+        $response = $this->createMock(IResponse::class);
87
+        $response->expects($this->any())->method('getStatusCode')->willReturn(200);
88
+
89
+        $this->setupcheck
90
+            ->expects($this->exactly(2))
91
+            ->method('runRequest')
92
+            ->willReturnOnConsecutiveCalls($this->generate([]), $this->generate([])); // No responses
93
+
94
+        $result = $this->setupcheck->run();
95
+        $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
96
+        $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
97
+    }
98
+
99
+    public function testPartialResponse(): void {
100
+        $response = $this->createMock(IResponse::class);
101
+        $response->expects($this->any())->method('getStatusCode')->willReturn(200);
102
+
103
+        $this->setupcheck
104
+            ->expects($this->exactly(2))
105
+            ->method('runRequest')
106
+            ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([])); // only one response out of two
107
+
108
+        $result = $this->setupcheck->run();
109
+        $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
110
+        $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
111
+    }
112
+
113
+    public function testInvalidResponse(): void {
114
+        $response = $this->createMock(IResponse::class);
115
+        $response->expects($this->any())->method('getStatusCode')->willReturn(404);
116
+
117
+        $this->setupcheck
118
+            ->expects($this->exactly(2))
119
+            ->method('runRequest')
120
+            ->willReturnOnConsecutiveCalls($this->generate([$response]), $this->generate([$response])); // only one response out of two
121
+
122
+        $result = $this->setupcheck->run();
123
+        $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
124
+        $this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
125
+    }
126
+
127
+    public function testPartialInvalidResponse(): void {
128
+        $response1 = $this->createMock(IResponse::class);
129
+        $response1->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(200);
130
+        $response2 = $this->createMock(IResponse::class);
131
+        $response2->expects($this->any())->method('getStatusCode')->willReturnOnConsecutiveCalls(404);
132
+
133
+        $this->setupcheck
134
+            ->expects($this->exactly(2))
135
+            ->method('runRequest')
136
+            ->willReturnOnConsecutiveCalls($this->generate([$response1]), $this->generate([$response2]));
137
+
138
+        $result = $this->setupcheck->run();
139
+        $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
140
+        $this->assertMatchesRegularExpression('/^Your web server is not properly set up/', $result->getDescription());
141
+    }
142
+
143
+    /**
144
+     * Helper function creates a nicer interface for mocking Generator behavior
145
+     */
146
+    protected function generate(array $yield_values) {
147
+        return $this->returnCallback(function () use ($yield_values) {
148
+            yield from $yield_values;
149
+        });
150
+    }
151 151
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class OcxProvicersTest extends TestCase {
23
-	private IL10N|MockObject $l10n;
24
-	private IConfig|MockObject $config;
25
-	private IURLGenerator|MockObject $urlGenerator;
26
-	private IClientService|MockObject $clientService;
27
-	private LoggerInterface|MockObject $logger;
28
-	private OcxProviders|MockObject $setupcheck;
23
+	private IL10N | MockObject $l10n;
24
+	private IConfig | MockObject $config;
25
+	private IURLGenerator | MockObject $urlGenerator;
26
+	private IClientService | MockObject $clientService;
27
+	private LoggerInterface | MockObject $logger;
28
+	private OcxProviders | MockObject $setupcheck;
29 29
 
30 30
 	protected function setUp(): void {
31 31
 		parent::setUp();
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		$this->l10n = $this->createMock(IL10N::class);
34 34
 		$this->l10n->expects($this->any())
35 35
 			->method('t')
36
-			->willReturnCallback(function ($message, array $replace) {
36
+			->willReturnCallback(function($message, array $replace) {
37 37
 				return vsprintf($message, $replace);
38 38
 			});
39 39
 
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * Helper function creates a nicer interface for mocking Generator behavior
145 145
 	 */
146 146
 	protected function generate(array $yield_values) {
147
-		return $this->returnCallback(function () use ($yield_values) {
147
+		return $this->returnCallback(function() use ($yield_values) {
148 148
 			yield from $yield_values;
149 149
 		});
150 150
 	}
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/ForwardedForHeadersTest.php 2 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -17,105 +17,105 @@
 block discarded – undo
17 17
 use Test\TestCase;
18 18
 
19 19
 class ForwardedForHeadersTest extends TestCase {
20
-	private IL10N $l10n;
21
-	private IConfig $config;
22
-	private IURLGenerator $urlGenerator;
23
-	private IRequest $request;
24
-	private ForwardedForHeaders $check;
20
+    private IL10N $l10n;
21
+    private IConfig $config;
22
+    private IURLGenerator $urlGenerator;
23
+    private IRequest $request;
24
+    private ForwardedForHeaders $check;
25 25
 
26
-	protected function setUp(): void {
27
-		parent::setUp();
26
+    protected function setUp(): void {
27
+        parent::setUp();
28 28
 
29
-		$this->l10n = $this->createMock(IL10N::class);
30
-		$this->l10n->expects($this->any())
31
-			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
33
-				return vsprintf($message, $replace);
34
-			});
35
-		$this->config = $this->getMockBuilder(IConfig::class)->getMock();
36
-		$this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
37
-		$this->request = $this->getMockBuilder(IRequest::class)->getMock();
38
-		$this->check = new ForwardedForHeaders(
39
-			$this->l10n,
40
-			$this->config,
41
-			$this->urlGenerator,
42
-			$this->request,
43
-		);
44
-	}
29
+        $this->l10n = $this->createMock(IL10N::class);
30
+        $this->l10n->expects($this->any())
31
+            ->method('t')
32
+            ->willReturnCallback(function ($message, array $replace) {
33
+                return vsprintf($message, $replace);
34
+            });
35
+        $this->config = $this->getMockBuilder(IConfig::class)->getMock();
36
+        $this->urlGenerator = $this->getMockBuilder(IURLGenerator::class)->getMock();
37
+        $this->request = $this->getMockBuilder(IRequest::class)->getMock();
38
+        $this->check = new ForwardedForHeaders(
39
+            $this->l10n,
40
+            $this->config,
41
+            $this->urlGenerator,
42
+            $this->request,
43
+        );
44
+    }
45 45
 
46
-	/**
47
-	 * @dataProvider dataForwardedForHeadersWorking
48
-	 */
49
-	public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, string $result): void {
50
-		$this->config->expects($this->once())
51
-			->method('getSystemValue')
52
-			->with('trusted_proxies', [])
53
-			->willReturn($trustedProxies);
54
-		$this->request->expects($this->atLeastOnce())
55
-			->method('getHeader')
56
-			->willReturnMap([
57
-				['REMOTE_ADDR', $remoteAddrNotForwarded],
58
-				['X-Forwarded-Host', '']
59
-			]);
60
-		$this->request->expects($this->any())
61
-			->method('getRemoteAddress')
62
-			->willReturn($remoteAddr);
46
+    /**
47
+     * @dataProvider dataForwardedForHeadersWorking
48
+     */
49
+    public function testForwardedForHeadersWorking(array $trustedProxies, string $remoteAddrNotForwarded, string $remoteAddr, string $result): void {
50
+        $this->config->expects($this->once())
51
+            ->method('getSystemValue')
52
+            ->with('trusted_proxies', [])
53
+            ->willReturn($trustedProxies);
54
+        $this->request->expects($this->atLeastOnce())
55
+            ->method('getHeader')
56
+            ->willReturnMap([
57
+                ['REMOTE_ADDR', $remoteAddrNotForwarded],
58
+                ['X-Forwarded-Host', '']
59
+            ]);
60
+        $this->request->expects($this->any())
61
+            ->method('getRemoteAddress')
62
+            ->willReturn($remoteAddr);
63 63
 
64
-		$this->assertEquals(
65
-			$result,
66
-			$this->check->run()->getSeverity()
67
-		);
68
-	}
64
+        $this->assertEquals(
65
+            $result,
66
+            $this->check->run()->getSeverity()
67
+        );
68
+    }
69 69
 
70
-	public static function dataForwardedForHeadersWorking(): array {
71
-		return [
72
-			// description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
73
-			'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
74
-			'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
75
-			'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', SetupResult::SUCCESS],
76
-			'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', SetupResult::WARNING],
77
-		];
78
-	}
70
+    public static function dataForwardedForHeadersWorking(): array {
71
+        return [
72
+            // description => trusted proxies, getHeader('REMOTE_ADDR'), getRemoteAddr, expected result
73
+            'no trusted proxies' => [[], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
74
+            'trusted proxy, remote addr not trusted proxy' => [['1.1.1.1'], '2.2.2.2', '2.2.2.2', SetupResult::SUCCESS],
75
+            'trusted proxy, remote addr is trusted proxy, x-forwarded-for working' => [['1.1.1.1'], '1.1.1.1', '2.2.2.2', SetupResult::SUCCESS],
76
+            'trusted proxy, remote addr is trusted proxy, x-forwarded-for not set' => [['1.1.1.1'], '1.1.1.1', '1.1.1.1', SetupResult::WARNING],
77
+        ];
78
+    }
79 79
 
80
-	public function testForwardedHostPresentButTrustedProxiesNotAnArray(): void {
81
-		$this->config->expects($this->once())
82
-			->method('getSystemValue')
83
-			->with('trusted_proxies', [])
84
-			->willReturn('1.1.1.1');
85
-		$this->request->expects($this->atLeastOnce())
86
-			->method('getHeader')
87
-			->willReturnMap([
88
-				['REMOTE_ADDR', '1.1.1.1'],
89
-				['X-Forwarded-Host', 'nextcloud.test']
90
-			]);
91
-		$this->request->expects($this->any())
92
-			->method('getRemoteAddress')
93
-			->willReturn('1.1.1.1');
80
+    public function testForwardedHostPresentButTrustedProxiesNotAnArray(): void {
81
+        $this->config->expects($this->once())
82
+            ->method('getSystemValue')
83
+            ->with('trusted_proxies', [])
84
+            ->willReturn('1.1.1.1');
85
+        $this->request->expects($this->atLeastOnce())
86
+            ->method('getHeader')
87
+            ->willReturnMap([
88
+                ['REMOTE_ADDR', '1.1.1.1'],
89
+                ['X-Forwarded-Host', 'nextcloud.test']
90
+            ]);
91
+        $this->request->expects($this->any())
92
+            ->method('getRemoteAddress')
93
+            ->willReturn('1.1.1.1');
94 94
 
95
-		$this->assertEquals(
96
-			SetupResult::ERROR,
97
-			$this->check->run()->getSeverity()
98
-		);
99
-	}
95
+        $this->assertEquals(
96
+            SetupResult::ERROR,
97
+            $this->check->run()->getSeverity()
98
+        );
99
+    }
100 100
 
101
-	public function testForwardedHostPresentButTrustedProxiesEmpty(): void {
102
-		$this->config->expects($this->once())
103
-			->method('getSystemValue')
104
-			->with('trusted_proxies', [])
105
-			->willReturn([]);
106
-		$this->request->expects($this->atLeastOnce())
107
-			->method('getHeader')
108
-			->willReturnMap([
109
-				['REMOTE_ADDR', '1.1.1.1'],
110
-				['X-Forwarded-Host', 'nextcloud.test']
111
-			]);
112
-		$this->request->expects($this->any())
113
-			->method('getRemoteAddress')
114
-			->willReturn('1.1.1.1');
101
+    public function testForwardedHostPresentButTrustedProxiesEmpty(): void {
102
+        $this->config->expects($this->once())
103
+            ->method('getSystemValue')
104
+            ->with('trusted_proxies', [])
105
+            ->willReturn([]);
106
+        $this->request->expects($this->atLeastOnce())
107
+            ->method('getHeader')
108
+            ->willReturnMap([
109
+                ['REMOTE_ADDR', '1.1.1.1'],
110
+                ['X-Forwarded-Host', 'nextcloud.test']
111
+            ]);
112
+        $this->request->expects($this->any())
113
+            ->method('getRemoteAddress')
114
+            ->willReturn('1.1.1.1');
115 115
 
116
-		$this->assertEquals(
117
-			SetupResult::ERROR,
118
-			$this->check->run()->getSeverity()
119
-		);
120
-	}
116
+        $this->assertEquals(
117
+            SetupResult::ERROR,
118
+            $this->check->run()->getSeverity()
119
+        );
120
+    }
121 121
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
 		$this->l10n = $this->createMock(IL10N::class);
30 30
 		$this->l10n->expects($this->any())
31 31
 			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
32
+			->willReturnCallback(function($message, array $replace) {
33 33
 				return vsprintf($message, $replace);
34 34
 			});
35 35
 		$this->config = $this->getMockBuilder(IConfig::class)->getMock();
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/PhpOutputBufferingTest.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,27 +15,27 @@
 block discarded – undo
15 15
 use Test\TestCase;
16 16
 
17 17
 class PhpOutputBufferingTest extends TestCase {
18
-	/** @var IL10N|MockObject */
19
-	private $l10n;
18
+    /** @var IL10N|MockObject */
19
+    private $l10n;
20 20
 
21
-	protected function setUp(): void {
22
-		parent::setUp();
21
+    protected function setUp(): void {
22
+        parent::setUp();
23 23
 
24
-		$this->l10n = $this->createMock(IL10N::class);
25
-		$this->l10n->expects($this->any())
26
-			->method('t')
27
-			->willReturnCallback(function ($message, array $replace) {
28
-				return vsprintf($message, $replace);
29
-			});
30
-	}
24
+        $this->l10n = $this->createMock(IL10N::class);
25
+        $this->l10n->expects($this->any())
26
+            ->method('t')
27
+            ->willReturnCallback(function ($message, array $replace) {
28
+                return vsprintf($message, $replace);
29
+            });
30
+    }
31 31
 
32
-	/*
32
+    /*
33 33
 	 * output_buffer is PHP_INI_PERDIR and cannot changed at runtime.
34 34
 	 * Run this test with -d output_buffering=1 to validate the fail case.
35 35
 	 */
36 36
 
37
-	public function testPass(): void {
38
-		$check = new PhpOutputBuffering($this->l10n);
39
-		$this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
40
-	}
37
+    public function testPass(): void {
38
+        $check = new PhpOutputBuffering($this->l10n);
39
+        $this->assertEquals(SetupResult::SUCCESS, $check->run()->getSeverity());
40
+    }
41 41
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 		$this->l10n = $this->createMock(IL10N::class);
25 25
 		$this->l10n->expects($this->any())
26 26
 			->method('t')
27
-			->willReturnCallback(function ($message, array $replace) {
27
+			->willReturnCallback(function($message, array $replace) {
28 28
 				return vsprintf($message, $replace);
29 29
 			});
30 30
 	}
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/SupportedDatabaseTest.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -20,32 +20,32 @@
 block discarded – undo
20 20
  * @group DB
21 21
  */
22 22
 class SupportedDatabaseTest extends TestCase {
23
-	private IL10N $l10n;
24
-	private IUrlGenerator $urlGenerator;
25
-	private IDBConnection $connection;
26
-
27
-	private SupportedDatabase $check;
28
-
29
-	protected function setUp(): void {
30
-		parent::setUp();
31
-
32
-		$this->l10n = $this->createMock(IL10N::class);
33
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
34
-		$this->connection = Server::get(IDBConnection::class);
35
-
36
-		$this->check = new SupportedDatabase(
37
-			$this->l10n,
38
-			$this->urlGenerator,
39
-			Server::get(IDBConnection::class)
40
-		);
41
-	}
42
-
43
-	public function testPass(): void {
44
-		if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
45
-			/** SQlite always gets a warning */
46
-			$this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
47
-		} else {
48
-			$this->assertContains($this->check->run()->getSeverity(), [SetupResult::SUCCESS, SetupResult::INFO]);
49
-		}
50
-	}
23
+    private IL10N $l10n;
24
+    private IUrlGenerator $urlGenerator;
25
+    private IDBConnection $connection;
26
+
27
+    private SupportedDatabase $check;
28
+
29
+    protected function setUp(): void {
30
+        parent::setUp();
31
+
32
+        $this->l10n = $this->createMock(IL10N::class);
33
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
34
+        $this->connection = Server::get(IDBConnection::class);
35
+
36
+        $this->check = new SupportedDatabase(
37
+            $this->l10n,
38
+            $this->urlGenerator,
39
+            Server::get(IDBConnection::class)
40
+        );
41
+    }
42
+
43
+    public function testPass(): void {
44
+        if ($this->connection->getDatabaseProvider() === IDBConnection::PLATFORM_SQLITE) {
45
+            /** SQlite always gets a warning */
46
+            $this->assertEquals(SetupResult::WARNING, $this->check->run()->getSeverity());
47
+        } else {
48
+            $this->assertContains($this->check->run()->getSeverity(), [SetupResult::SUCCESS, SetupResult::INFO]);
49
+        }
50
+    }
51 51
 }
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/LoggingLevelTest.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -19,58 +19,58 @@
 block discarded – undo
19 19
 use Test\TestCase;
20 20
 
21 21
 class LoggingLevelTest extends TestCase {
22
-	private IL10N&MockObject $l10n;
23
-	private IConfig&MockObject $config;
24
-	private IURLGenerator&MockObject $urlGenerator;
22
+    private IL10N&MockObject $l10n;
23
+    private IConfig&MockObject $config;
24
+    private IURLGenerator&MockObject $urlGenerator;
25 25
 
26
-	protected function setUp(): void {
27
-		parent::setUp();
26
+    protected function setUp(): void {
27
+        parent::setUp();
28 28
 
29
-		$this->l10n = $this->createMock(IL10N::class);
30
-		$this->l10n->expects($this->any())
31
-			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
33
-				return vsprintf($message, $replace);
34
-			});
35
-		$this->config = $this->createMock(IConfig::class);
36
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
37
-	}
29
+        $this->l10n = $this->createMock(IL10N::class);
30
+        $this->l10n->expects($this->any())
31
+            ->method('t')
32
+            ->willReturnCallback(function ($message, array $replace) {
33
+                return vsprintf($message, $replace);
34
+            });
35
+        $this->config = $this->createMock(IConfig::class);
36
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
37
+    }
38 38
 
39
-	public static function dataRun(): array {
40
-		return [
41
-			[ILogger::INFO, SetupResult::SUCCESS],
42
-			[ILogger::WARN, SetupResult::SUCCESS],
43
-			[ILogger::ERROR, SetupResult::SUCCESS],
44
-			[ILogger::FATAL, SetupResult::SUCCESS],
39
+    public static function dataRun(): array {
40
+        return [
41
+            [ILogger::INFO, SetupResult::SUCCESS],
42
+            [ILogger::WARN, SetupResult::SUCCESS],
43
+            [ILogger::ERROR, SetupResult::SUCCESS],
44
+            [ILogger::FATAL, SetupResult::SUCCESS],
45 45
 
46
-			// Debug is valid but will result in an warning
47
-			[ILogger::DEBUG, SetupResult::WARNING],
46
+            // Debug is valid but will result in an warning
47
+            [ILogger::DEBUG, SetupResult::WARNING],
48 48
 
49
-			// negative - invalid range
50
-			[-1, SetupResult::ERROR],
51
-			// string value instead of number
52
-			['1', SetupResult::ERROR],
53
-			// random string value
54
-			['error', SetupResult::ERROR],
55
-			// PSR logger value
56
-			[LogLevel::ALERT, SetupResult::ERROR],
57
-			// out of range
58
-			[ILogger::FATAL + 1, SetupResult::ERROR],
59
-		];
60
-	}
49
+            // negative - invalid range
50
+            [-1, SetupResult::ERROR],
51
+            // string value instead of number
52
+            ['1', SetupResult::ERROR],
53
+            // random string value
54
+            ['error', SetupResult::ERROR],
55
+            // PSR logger value
56
+            [LogLevel::ALERT, SetupResult::ERROR],
57
+            // out of range
58
+            [ILogger::FATAL + 1, SetupResult::ERROR],
59
+        ];
60
+    }
61 61
 
62
-	/** @dataProvider dataRun */
63
-	public function testRun(string|int $value, string $expected): void {
64
-		$this->urlGenerator->method('linkToDocs')->willReturn('admin-logging');
62
+    /** @dataProvider dataRun */
63
+    public function testRun(string|int $value, string $expected): void {
64
+        $this->urlGenerator->method('linkToDocs')->willReturn('admin-logging');
65 65
 
66
-		$this->config->expects(self::once())
67
-			->method('getSystemValue')
68
-			->with('loglevel', ILogger::WARN)
69
-			->willReturn($value);
66
+        $this->config->expects(self::once())
67
+            ->method('getSystemValue')
68
+            ->with('loglevel', ILogger::WARN)
69
+            ->willReturn($value);
70 70
 
71
-		$check = new LoggingLevel($this->l10n, $this->config, $this->urlGenerator);
71
+        $check = new LoggingLevel($this->l10n, $this->config, $this->urlGenerator);
72 72
 
73
-		$result = $check->run();
74
-		$this->assertEquals($expected, $result->getSeverity());
75
-	}
73
+        $result = $check->run();
74
+        $this->assertEquals($expected, $result->getSeverity());
75
+    }
76 76
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		$this->l10n = $this->createMock(IL10N::class);
30 30
 		$this->l10n->expects($this->any())
31 31
 			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
32
+			->willReturnCallback(function($message, array $replace) {
33 33
 				return vsprintf($message, $replace);
34 34
 			});
35 35
 		$this->config = $this->createMock(IConfig::class);
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	}
61 61
 
62 62
 	/** @dataProvider dataRun */
63
-	public function testRun(string|int $value, string $expected): void {
63
+	public function testRun(string | int $value, string $expected): void {
64 64
 		$this->urlGenerator->method('linkToDocs')->willReturn('admin-logging');
65 65
 
66 66
 		$this->config->expects(self::once())
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/DataDirectoryProtectedTest.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -20,100 +20,100 @@
 block discarded – undo
20 20
 use Test\TestCase;
21 21
 
22 22
 class DataDirectoryProtectedTest extends TestCase {
23
-	private IL10N&MockObject $l10n;
24
-	private IConfig&MockObject $config;
25
-	private IURLGenerator&MockObject $urlGenerator;
26
-	private IClientService&MockObject $clientService;
27
-	private LoggerInterface&MockObject $logger;
28
-	private DataDirectoryProtected&MockObject $setupcheck;
29
-
30
-	protected function setUp(): void {
31
-		parent::setUp();
32
-
33
-		$this->l10n = $this->createMock(IL10N::class);
34
-		$this->l10n->expects($this->any())
35
-			->method('t')
36
-			->willReturnCallback(function ($message, array $replace) {
37
-				return vsprintf($message, $replace);
38
-			});
39
-
40
-		$this->config = $this->createMock(IConfig::class);
41
-		$this->urlGenerator = $this->createMock(IURLGenerator::class);
42
-		$this->clientService = $this->createMock(IClientService::class);
43
-		$this->logger = $this->createMock(LoggerInterface::class);
44
-
45
-		$this->setupcheck = $this->getMockBuilder(DataDirectoryProtected::class)
46
-			->onlyMethods(['runRequest'])
47
-			->setConstructorArgs([
48
-				$this->l10n,
49
-				$this->config,
50
-				$this->urlGenerator,
51
-				$this->clientService,
52
-				$this->logger,
53
-			])
54
-			->getMock();
55
-	}
56
-
57
-	/**
58
-	 * @dataProvider dataTestStatusCode
59
-	 */
60
-	public function testStatusCode(array $status, string $expected, bool $hasBody): void {
61
-		$responses = array_map(function ($state) use ($hasBody) {
62
-			$response = $this->createMock(IResponse::class);
63
-			$response->expects($this->any())->method('getStatusCode')->willReturn($state);
64
-			$response->expects(($this->atMost(1)))->method('getBody')->willReturn($hasBody ? '# Nextcloud data directory' : 'something else');
65
-			return $response;
66
-		}, $status);
67
-
68
-		$this->setupcheck
69
-			->expects($this->once())
70
-			->method('runRequest')
71
-			->will($this->generate($responses));
72
-
73
-		$this->config
74
-			->expects($this->once())
75
-			->method('getSystemValueString')
76
-			->willReturn('');
77
-
78
-		$result = $this->setupcheck->run();
79
-		$this->assertEquals($expected, $result->getSeverity());
80
-	}
81
-
82
-	public static function dataTestStatusCode(): array {
83
-		return [
84
-			'success: forbidden access' => [[403], SetupResult::SUCCESS, true],
85
-			'success: forbidden access with redirect' => [[200], SetupResult::SUCCESS, false],
86
-			'error: can access' => [[200], SetupResult::ERROR, true],
87
-			'error: one forbidden one can access' => [[403, 200], SetupResult::ERROR, true],
88
-			'warning: connection issue' => [[], SetupResult::WARNING, true],
89
-		];
90
-	}
91
-
92
-	public function testNoResponse(): void {
93
-		$response = $this->createMock(IResponse::class);
94
-		$response->expects($this->any())->method('getStatusCode')->willReturn(200);
95
-
96
-		$this->setupcheck
97
-			->expects($this->once())
98
-			->method('runRequest')
99
-			->will($this->generate([]));
100
-
101
-		$this->config
102
-			->expects($this->once())
103
-			->method('getSystemValueString')
104
-			->willReturn('');
105
-
106
-		$result = $this->setupcheck->run();
107
-		$this->assertEquals(SetupResult::WARNING, $result->getSeverity());
108
-		$this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
109
-	}
110
-
111
-	/**
112
-	 * Helper function creates a nicer interface for mocking Generator behavior
113
-	 */
114
-	protected function generate(array $yield_values) {
115
-		return $this->returnCallback(function () use ($yield_values) {
116
-			yield from $yield_values;
117
-		});
118
-	}
23
+    private IL10N&MockObject $l10n;
24
+    private IConfig&MockObject $config;
25
+    private IURLGenerator&MockObject $urlGenerator;
26
+    private IClientService&MockObject $clientService;
27
+    private LoggerInterface&MockObject $logger;
28
+    private DataDirectoryProtected&MockObject $setupcheck;
29
+
30
+    protected function setUp(): void {
31
+        parent::setUp();
32
+
33
+        $this->l10n = $this->createMock(IL10N::class);
34
+        $this->l10n->expects($this->any())
35
+            ->method('t')
36
+            ->willReturnCallback(function ($message, array $replace) {
37
+                return vsprintf($message, $replace);
38
+            });
39
+
40
+        $this->config = $this->createMock(IConfig::class);
41
+        $this->urlGenerator = $this->createMock(IURLGenerator::class);
42
+        $this->clientService = $this->createMock(IClientService::class);
43
+        $this->logger = $this->createMock(LoggerInterface::class);
44
+
45
+        $this->setupcheck = $this->getMockBuilder(DataDirectoryProtected::class)
46
+            ->onlyMethods(['runRequest'])
47
+            ->setConstructorArgs([
48
+                $this->l10n,
49
+                $this->config,
50
+                $this->urlGenerator,
51
+                $this->clientService,
52
+                $this->logger,
53
+            ])
54
+            ->getMock();
55
+    }
56
+
57
+    /**
58
+     * @dataProvider dataTestStatusCode
59
+     */
60
+    public function testStatusCode(array $status, string $expected, bool $hasBody): void {
61
+        $responses = array_map(function ($state) use ($hasBody) {
62
+            $response = $this->createMock(IResponse::class);
63
+            $response->expects($this->any())->method('getStatusCode')->willReturn($state);
64
+            $response->expects(($this->atMost(1)))->method('getBody')->willReturn($hasBody ? '# Nextcloud data directory' : 'something else');
65
+            return $response;
66
+        }, $status);
67
+
68
+        $this->setupcheck
69
+            ->expects($this->once())
70
+            ->method('runRequest')
71
+            ->will($this->generate($responses));
72
+
73
+        $this->config
74
+            ->expects($this->once())
75
+            ->method('getSystemValueString')
76
+            ->willReturn('');
77
+
78
+        $result = $this->setupcheck->run();
79
+        $this->assertEquals($expected, $result->getSeverity());
80
+    }
81
+
82
+    public static function dataTestStatusCode(): array {
83
+        return [
84
+            'success: forbidden access' => [[403], SetupResult::SUCCESS, true],
85
+            'success: forbidden access with redirect' => [[200], SetupResult::SUCCESS, false],
86
+            'error: can access' => [[200], SetupResult::ERROR, true],
87
+            'error: one forbidden one can access' => [[403, 200], SetupResult::ERROR, true],
88
+            'warning: connection issue' => [[], SetupResult::WARNING, true],
89
+        ];
90
+    }
91
+
92
+    public function testNoResponse(): void {
93
+        $response = $this->createMock(IResponse::class);
94
+        $response->expects($this->any())->method('getStatusCode')->willReturn(200);
95
+
96
+        $this->setupcheck
97
+            ->expects($this->once())
98
+            ->method('runRequest')
99
+            ->will($this->generate([]));
100
+
101
+        $this->config
102
+            ->expects($this->once())
103
+            ->method('getSystemValueString')
104
+            ->willReturn('');
105
+
106
+        $result = $this->setupcheck->run();
107
+        $this->assertEquals(SetupResult::WARNING, $result->getSeverity());
108
+        $this->assertMatchesRegularExpression('/^Could not check/', $result->getDescription());
109
+    }
110
+
111
+    /**
112
+     * Helper function creates a nicer interface for mocking Generator behavior
113
+     */
114
+    protected function generate(array $yield_values) {
115
+        return $this->returnCallback(function () use ($yield_values) {
116
+            yield from $yield_values;
117
+        });
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		$this->l10n = $this->createMock(IL10N::class);
34 34
 		$this->l10n->expects($this->any())
35 35
 			->method('t')
36
-			->willReturnCallback(function ($message, array $replace) {
36
+			->willReturnCallback(function($message, array $replace) {
37 37
 				return vsprintf($message, $replace);
38 38
 			});
39 39
 
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	 * @dataProvider dataTestStatusCode
59 59
 	 */
60 60
 	public function testStatusCode(array $status, string $expected, bool $hasBody): void {
61
-		$responses = array_map(function ($state) use ($hasBody) {
61
+		$responses = array_map(function($state) use ($hasBody) {
62 62
 			$response = $this->createMock(IResponse::class);
63 63
 			$response->expects($this->any())->method('getStatusCode')->willReturn($state);
64 64
 			$response->expects(($this->atMost(1)))->method('getBody')->willReturn($hasBody ? '# Nextcloud data directory' : 'something else');
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * Helper function creates a nicer interface for mocking Generator behavior
113 113
 	 */
114 114
 	protected function generate(array $yield_values) {
115
-		return $this->returnCallback(function () use ($yield_values) {
115
+		return $this->returnCallback(function() use ($yield_values) {
116 116
 			yield from $yield_values;
117 117
 		});
118 118
 	}
Please login to merge, or discard this patch.
apps/settings/tests/SetupChecks/AppDirsWithDifferentOwnerTest.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -13,90 +13,90 @@
 block discarded – undo
13 13
 use Test\TestCase;
14 14
 
15 15
 class AppDirsWithDifferentOwnerTest extends TestCase {
16
-	private IL10N $l10n;
17
-	private AppDirsWithDifferentOwner $check;
16
+    private IL10N $l10n;
17
+    private AppDirsWithDifferentOwner $check;
18 18
 
19
-	/**
20
-	 * Holds a list of directories created during tests.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	private $dirsToRemove = [];
19
+    /**
20
+     * Holds a list of directories created during tests.
21
+     *
22
+     * @var array
23
+     */
24
+    private $dirsToRemove = [];
25 25
 
26
-	protected function setUp(): void {
27
-		parent::setUp();
26
+    protected function setUp(): void {
27
+        parent::setUp();
28 28
 
29
-		$this->l10n = $this->createMock(IL10N::class);
30
-		$this->l10n->expects($this->any())
31
-			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
33
-				return vsprintf($message, $replace);
34
-			});
35
-		$this->check = new AppDirsWithDifferentOwner(
36
-			$this->l10n,
37
-		);
38
-	}
29
+        $this->l10n = $this->createMock(IL10N::class);
30
+        $this->l10n->expects($this->any())
31
+            ->method('t')
32
+            ->willReturnCallback(function ($message, array $replace) {
33
+                return vsprintf($message, $replace);
34
+            });
35
+        $this->check = new AppDirsWithDifferentOwner(
36
+            $this->l10n,
37
+        );
38
+    }
39 39
 
40
-	/**
41
-	 * Setups a temp directory and some subdirectories.
42
-	 * Then calls the 'getAppDirsWithDifferentOwner' method.
43
-	 * The result is expected to be empty since
44
-	 * there are no directories with different owners than the current user.
45
-	 *
46
-	 * @return void
47
-	 */
48
-	public function testAppDirectoryOwnersOk(): void {
49
-		$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
50
-		mkdir($tempDir);
51
-		mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
52
-		mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
53
-		$this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
54
-		$this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
55
-		$this->dirsToRemove[] = $tempDir;
56
-		\OC::$APPSROOTS = [
57
-			[
58
-				'path' => $tempDir,
59
-				'url' => '/apps',
60
-				'writable' => true,
61
-			],
62
-		];
63
-		$this->assertSame(
64
-			[],
65
-			$this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
66
-		);
67
-	}
40
+    /**
41
+     * Setups a temp directory and some subdirectories.
42
+     * Then calls the 'getAppDirsWithDifferentOwner' method.
43
+     * The result is expected to be empty since
44
+     * there are no directories with different owners than the current user.
45
+     *
46
+     * @return void
47
+     */
48
+    public function testAppDirectoryOwnersOk(): void {
49
+        $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
50
+        mkdir($tempDir);
51
+        mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
52
+        mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
53
+        $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
54
+        $this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
55
+        $this->dirsToRemove[] = $tempDir;
56
+        \OC::$APPSROOTS = [
57
+            [
58
+                'path' => $tempDir,
59
+                'url' => '/apps',
60
+                'writable' => true,
61
+            ],
62
+        ];
63
+        $this->assertSame(
64
+            [],
65
+            $this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
66
+        );
67
+    }
68 68
 
69
-	/**
70
-	 * Calls the check for a none existing app root that is marked as not writable.
71
-	 * It's expected that no error happens since the check shouldn't apply.
72
-	 *
73
-	 * @return void
74
-	 */
75
-	public function testAppDirectoryOwnersNotWritable(): void {
76
-		$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
77
-		\OC::$APPSROOTS = [
78
-			[
79
-				'path' => $tempDir,
80
-				'url' => '/apps',
81
-				'writable' => false,
82
-			],
83
-		];
84
-		$this->assertSame(
85
-			[],
86
-			$this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
87
-		);
88
-	}
69
+    /**
70
+     * Calls the check for a none existing app root that is marked as not writable.
71
+     * It's expected that no error happens since the check shouldn't apply.
72
+     *
73
+     * @return void
74
+     */
75
+    public function testAppDirectoryOwnersNotWritable(): void {
76
+        $tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
77
+        \OC::$APPSROOTS = [
78
+            [
79
+                'path' => $tempDir,
80
+                'url' => '/apps',
81
+                'writable' => false,
82
+            ],
83
+        ];
84
+        $this->assertSame(
85
+            [],
86
+            $this->invokePrivate($this->check, 'getAppDirsWithDifferentOwner', [posix_getuid()])
87
+        );
88
+    }
89 89
 
90
-	/**
91
-	 * Removes directories created during tests.
92
-	 *
93
-	 * @after
94
-	 * @return void
95
-	 */
96
-	public function removeTestDirectories() {
97
-		foreach ($this->dirsToRemove as $dirToRemove) {
98
-			rmdir($dirToRemove);
99
-		}
100
-		$this->dirsToRemove = [];
101
-	}
90
+    /**
91
+     * Removes directories created during tests.
92
+     *
93
+     * @after
94
+     * @return void
95
+     */
96
+    public function removeTestDirectories() {
97
+        foreach ($this->dirsToRemove as $dirToRemove) {
98
+            rmdir($dirToRemove);
99
+        }
100
+        $this->dirsToRemove = [];
101
+    }
102 102
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		$this->l10n = $this->createMock(IL10N::class);
30 30
 		$this->l10n->expects($this->any())
31 31
 			->method('t')
32
-			->willReturnCallback(function ($message, array $replace) {
32
+			->willReturnCallback(function($message, array $replace) {
33 33
 				return vsprintf($message, $replace);
34 34
 			});
35 35
 		$this->check = new AppDirsWithDifferentOwner(
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 	 * @return void
47 47
 	 */
48 48
 	public function testAppDirectoryOwnersOk(): void {
49
-		$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
49
+		$tempDir = tempnam(sys_get_temp_dir(), 'apps').'dir';
50 50
 		mkdir($tempDir);
51
-		mkdir($tempDir . DIRECTORY_SEPARATOR . 'app1');
52
-		mkdir($tempDir . DIRECTORY_SEPARATOR . 'app2');
53
-		$this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app1';
54
-		$this->dirsToRemove[] = $tempDir . DIRECTORY_SEPARATOR . 'app2';
51
+		mkdir($tempDir.DIRECTORY_SEPARATOR.'app1');
52
+		mkdir($tempDir.DIRECTORY_SEPARATOR.'app2');
53
+		$this->dirsToRemove[] = $tempDir.DIRECTORY_SEPARATOR.'app1';
54
+		$this->dirsToRemove[] = $tempDir.DIRECTORY_SEPARATOR.'app2';
55 55
 		$this->dirsToRemove[] = $tempDir;
56 56
 		\OC::$APPSROOTS = [
57 57
 			[
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	 * @return void
74 74
 	 */
75 75
 	public function testAppDirectoryOwnersNotWritable(): void {
76
-		$tempDir = tempnam(sys_get_temp_dir(), 'apps') . 'dir';
76
+		$tempDir = tempnam(sys_get_temp_dir(), 'apps').'dir';
77 77
 		\OC::$APPSROOTS = [
78 78
 			[
79 79
 				'path' => $tempDir,
Please login to merge, or discard this patch.