Completed
Push — master ( ea98e4...98871f )
by
unknown
38:10 queued 14s
created
apps/theming/tests/CapabilitiesTest.php 1 patch
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -26,172 +26,172 @@
 block discarded – undo
26 26
  * @package OCA\Theming\Tests
27 27
  */
28 28
 class CapabilitiesTest extends TestCase {
29
-	protected ThemingDefaults&MockObject $theming;
30
-	protected IURLGenerator&MockObject $url;
31
-	protected IConfig&MockObject $config;
32
-	protected Util&MockObject $util;
33
-	protected IUserSession $userSession;
34
-	protected Capabilities $capabilities;
29
+    protected ThemingDefaults&MockObject $theming;
30
+    protected IURLGenerator&MockObject $url;
31
+    protected IConfig&MockObject $config;
32
+    protected Util&MockObject $util;
33
+    protected IUserSession $userSession;
34
+    protected Capabilities $capabilities;
35 35
 
36
-	protected function setUp(): void {
37
-		parent::setUp();
36
+    protected function setUp(): void {
37
+        parent::setUp();
38 38
 
39
-		$this->theming = $this->createMock(ThemingDefaults::class);
40
-		$this->url = $this->createMock(IURLGenerator::class);
41
-		$this->config = $this->createMock(IConfig::class);
42
-		$this->util = $this->createMock(Util::class);
43
-		$this->userSession = $this->createMock(IUserSession::class);
44
-		$this->capabilities = new Capabilities(
45
-			$this->theming,
46
-			$this->util,
47
-			$this->url,
48
-			$this->config,
49
-			$this->userSession,
50
-		);
51
-	}
39
+        $this->theming = $this->createMock(ThemingDefaults::class);
40
+        $this->url = $this->createMock(IURLGenerator::class);
41
+        $this->config = $this->createMock(IConfig::class);
42
+        $this->util = $this->createMock(Util::class);
43
+        $this->userSession = $this->createMock(IUserSession::class);
44
+        $this->capabilities = new Capabilities(
45
+            $this->theming,
46
+            $this->util,
47
+            $this->url,
48
+            $this->config,
49
+            $this->userSession,
50
+        );
51
+    }
52 52
 
53
-	public static function dataGetCapabilities(): array {
54
-		return [
55
-			['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
56
-				'name' => 'name',
57
-				'productName' => 'name',
58
-				'url' => 'url',
59
-				'slogan' => 'slogan',
60
-				'color' => '#FFFFFF',
61
-				'color-text' => '#000000',
62
-				'color-element' => '#b3b3b3',
63
-				'color-element-bright' => '#b3b3b3',
64
-				'color-element-dark' => '#FFFFFF',
65
-				'logo' => 'http://absolute/logo',
66
-				'background' => 'http://absolute/background',
67
-				'background-text' => '#000',
68
-				'background-plain' => false,
69
-				'background-default' => false,
70
-				'logoheader' => 'http://absolute/logo',
71
-				'favicon' => 'http://absolute/logo',
72
-			]],
73
-			['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', '#fff', '#000', 'http://localhost/', false, [
74
-				'name' => 'name1',
75
-				'productName' => 'name1',
76
-				'url' => 'url2',
77
-				'slogan' => 'slogan3',
78
-				'color' => '#01e4a0',
79
-				'color-text' => '#ffffff',
80
-				'color-element' => '#01e4a0',
81
-				'color-element-bright' => '#01e4a0',
82
-				'color-element-dark' => '#01e4a0',
83
-				'logo' => 'http://localhost/logo5',
84
-				'background' => 'http://localhost/background6',
85
-				'background-text' => '#000',
86
-				'background-plain' => false,
87
-				'background-default' => true,
88
-				'logoheader' => 'http://localhost/logo5',
89
-				'favicon' => 'http://localhost/logo5',
90
-			]],
91
-			['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', true, [
92
-				'name' => 'name1',
93
-				'productName' => 'name1',
94
-				'url' => 'url2',
95
-				'slogan' => 'slogan3',
96
-				'color' => '#000000',
97
-				'color-text' => '#ffffff',
98
-				'color-element' => '#4d4d4d',
99
-				'color-element-bright' => '#4d4d4d',
100
-				'color-element-dark' => '#4d4d4d',
101
-				'logo' => 'http://localhost/logo5',
102
-				'background' => '#000000',
103
-				'background-text' => '#ffffff',
104
-				'background-plain' => true,
105
-				'background-default' => false,
106
-				'logoheader' => 'http://localhost/logo5',
107
-				'favicon' => 'http://localhost/logo5',
108
-			]],
109
-			['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', false, [
110
-				'name' => 'name1',
111
-				'productName' => 'name1',
112
-				'url' => 'url2',
113
-				'slogan' => 'slogan3',
114
-				'color' => '#000000',
115
-				'color-text' => '#ffffff',
116
-				'color-element' => '#4d4d4d',
117
-				'color-element-bright' => '#4d4d4d',
118
-				'color-element-dark' => '#4d4d4d',
119
-				'logo' => 'http://localhost/logo5',
120
-				'background' => '#000000',
121
-				'background-text' => '#ffffff',
122
-				'background-plain' => true,
123
-				'background-default' => true,
124
-				'logoheader' => 'http://localhost/logo5',
125
-				'favicon' => 'http://localhost/logo5',
126
-			]],
127
-		];
128
-	}
53
+    public static function dataGetCapabilities(): array {
54
+        return [
55
+            ['name', 'url', 'slogan', '#FFFFFF', '#000000', 'logo', 'background', '#fff', '#000', 'http://absolute/', true, [
56
+                'name' => 'name',
57
+                'productName' => 'name',
58
+                'url' => 'url',
59
+                'slogan' => 'slogan',
60
+                'color' => '#FFFFFF',
61
+                'color-text' => '#000000',
62
+                'color-element' => '#b3b3b3',
63
+                'color-element-bright' => '#b3b3b3',
64
+                'color-element-dark' => '#FFFFFF',
65
+                'logo' => 'http://absolute/logo',
66
+                'background' => 'http://absolute/background',
67
+                'background-text' => '#000',
68
+                'background-plain' => false,
69
+                'background-default' => false,
70
+                'logoheader' => 'http://absolute/logo',
71
+                'favicon' => 'http://absolute/logo',
72
+            ]],
73
+            ['name1', 'url2', 'slogan3', '#01e4a0', '#ffffff', 'logo5', 'background6', '#fff', '#000', 'http://localhost/', false, [
74
+                'name' => 'name1',
75
+                'productName' => 'name1',
76
+                'url' => 'url2',
77
+                'slogan' => 'slogan3',
78
+                'color' => '#01e4a0',
79
+                'color-text' => '#ffffff',
80
+                'color-element' => '#01e4a0',
81
+                'color-element-bright' => '#01e4a0',
82
+                'color-element-dark' => '#01e4a0',
83
+                'logo' => 'http://localhost/logo5',
84
+                'background' => 'http://localhost/background6',
85
+                'background-text' => '#000',
86
+                'background-plain' => false,
87
+                'background-default' => true,
88
+                'logoheader' => 'http://localhost/logo5',
89
+                'favicon' => 'http://localhost/logo5',
90
+            ]],
91
+            ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', true, [
92
+                'name' => 'name1',
93
+                'productName' => 'name1',
94
+                'url' => 'url2',
95
+                'slogan' => 'slogan3',
96
+                'color' => '#000000',
97
+                'color-text' => '#ffffff',
98
+                'color-element' => '#4d4d4d',
99
+                'color-element-bright' => '#4d4d4d',
100
+                'color-element-dark' => '#4d4d4d',
101
+                'logo' => 'http://localhost/logo5',
102
+                'background' => '#000000',
103
+                'background-text' => '#ffffff',
104
+                'background-plain' => true,
105
+                'background-default' => false,
106
+                'logoheader' => 'http://localhost/logo5',
107
+                'favicon' => 'http://localhost/logo5',
108
+            ]],
109
+            ['name1', 'url2', 'slogan3', '#000000', '#ffffff', 'logo5', 'backgroundColor', '#000000', '#ffffff', 'http://localhost/', false, [
110
+                'name' => 'name1',
111
+                'productName' => 'name1',
112
+                'url' => 'url2',
113
+                'slogan' => 'slogan3',
114
+                'color' => '#000000',
115
+                'color-text' => '#ffffff',
116
+                'color-element' => '#4d4d4d',
117
+                'color-element-bright' => '#4d4d4d',
118
+                'color-element-dark' => '#4d4d4d',
119
+                'logo' => 'http://localhost/logo5',
120
+                'background' => '#000000',
121
+                'background-text' => '#ffffff',
122
+                'background-plain' => true,
123
+                'background-default' => true,
124
+                'logoheader' => 'http://localhost/logo5',
125
+                'favicon' => 'http://localhost/logo5',
126
+            ]],
127
+        ];
128
+    }
129 129
 
130
-	/**
131
-	 * @dataProvider dataGetCapabilities
132
-	 * @param non-empty-array<string, string> $expected
133
-	 */
134
-	public function testGetCapabilities(string $name, string $url, string $slogan, string $color, string $textColor, string $logo, string $background, string $backgroundColor, string $backgroundTextColor, string $baseUrl, bool $backgroundThemed, array $expected): void {
135
-		$this->config->expects($this->once())
136
-			->method('getAppValue')
137
-			->willReturn($background);
138
-		$this->theming->expects($this->once())
139
-			->method('getName')
140
-			->willReturn($name);
141
-		$this->theming->expects($this->once())
142
-			->method('getProductName')
143
-			->willReturn($name);
144
-		$this->theming->expects($this->once())
145
-			->method('getBaseUrl')
146
-			->willReturn($url);
147
-		$this->theming->expects($this->once())
148
-			->method('getSlogan')
149
-			->willReturn($slogan);
150
-		$this->theming->expects($this->once())
151
-			->method('getColorBackground')
152
-			->willReturn($backgroundColor);
153
-		$this->theming->expects($this->once())
154
-			->method('getTextColorBackground')
155
-			->willReturn($backgroundTextColor);
156
-		$this->theming->expects($this->atLeast(1))
157
-			->method('getDefaultColorPrimary')
158
-			->willReturn($color);
159
-		$this->theming->expects($this->exactly(3))
160
-			->method('getLogo')
161
-			->willReturn($logo);
130
+    /**
131
+     * @dataProvider dataGetCapabilities
132
+     * @param non-empty-array<string, string> $expected
133
+     */
134
+    public function testGetCapabilities(string $name, string $url, string $slogan, string $color, string $textColor, string $logo, string $background, string $backgroundColor, string $backgroundTextColor, string $baseUrl, bool $backgroundThemed, array $expected): void {
135
+        $this->config->expects($this->once())
136
+            ->method('getAppValue')
137
+            ->willReturn($background);
138
+        $this->theming->expects($this->once())
139
+            ->method('getName')
140
+            ->willReturn($name);
141
+        $this->theming->expects($this->once())
142
+            ->method('getProductName')
143
+            ->willReturn($name);
144
+        $this->theming->expects($this->once())
145
+            ->method('getBaseUrl')
146
+            ->willReturn($url);
147
+        $this->theming->expects($this->once())
148
+            ->method('getSlogan')
149
+            ->willReturn($slogan);
150
+        $this->theming->expects($this->once())
151
+            ->method('getColorBackground')
152
+            ->willReturn($backgroundColor);
153
+        $this->theming->expects($this->once())
154
+            ->method('getTextColorBackground')
155
+            ->willReturn($backgroundTextColor);
156
+        $this->theming->expects($this->atLeast(1))
157
+            ->method('getDefaultColorPrimary')
158
+            ->willReturn($color);
159
+        $this->theming->expects($this->exactly(3))
160
+            ->method('getLogo')
161
+            ->willReturn($logo);
162 162
 
163
-		$util = new Util($this->createMock(ServerVersion::class), $this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));
164
-		$this->util->expects($this->exactly(3))
165
-			->method('elementColor')
166
-			->with($color)
167
-			->willReturnCallback(static function (string $color, ?bool $brightBackground = null) use ($util) {
168
-				return $util->elementColor($color, $brightBackground);
169
-			});
163
+        $util = new Util($this->createMock(ServerVersion::class), $this->config, $this->createMock(IAppManager::class), $this->createMock(IAppData::class), $this->createMock(ImageManager::class));
164
+        $this->util->expects($this->exactly(3))
165
+            ->method('elementColor')
166
+            ->with($color)
167
+            ->willReturnCallback(static function (string $color, ?bool $brightBackground = null) use ($util) {
168
+                return $util->elementColor($color, $brightBackground);
169
+            });
170 170
 
171
-		$this->util->expects($this->any())
172
-			->method('invertTextColor')
173
-			->willReturnCallback(fn () => $textColor === '#000000');
174
-		$this->util->expects($this->once())
175
-			->method('isBackgroundThemed')
176
-			->willReturn($backgroundThemed);
171
+        $this->util->expects($this->any())
172
+            ->method('invertTextColor')
173
+            ->willReturnCallback(fn () => $textColor === '#000000');
174
+        $this->util->expects($this->once())
175
+            ->method('isBackgroundThemed')
176
+            ->willReturn($backgroundThemed);
177 177
 
178
-		if ($background !== 'backgroundColor') {
179
-			$this->theming->expects($this->once())
180
-				->method('getBackground')
181
-				->willReturn($background);
182
-			$this->url->expects($this->exactly(4))
183
-				->method('getAbsoluteURL')
184
-				->willReturnCallback(function ($url) use ($baseUrl) {
185
-					return $baseUrl . $url;
186
-				});
187
-		} else {
188
-			$this->url->expects($this->exactly(3))
189
-				->method('getAbsoluteURL')
190
-				->willReturnCallback(function ($url) use ($baseUrl) {
191
-					return $baseUrl . $url;
192
-				});
193
-		}
178
+        if ($background !== 'backgroundColor') {
179
+            $this->theming->expects($this->once())
180
+                ->method('getBackground')
181
+                ->willReturn($background);
182
+            $this->url->expects($this->exactly(4))
183
+                ->method('getAbsoluteURL')
184
+                ->willReturnCallback(function ($url) use ($baseUrl) {
185
+                    return $baseUrl . $url;
186
+                });
187
+        } else {
188
+            $this->url->expects($this->exactly(3))
189
+                ->method('getAbsoluteURL')
190
+                ->willReturnCallback(function ($url) use ($baseUrl) {
191
+                    return $baseUrl . $url;
192
+                });
193
+        }
194 194
 
195
-		$this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
196
-	}
195
+        $this->assertEquals(['theming' => $expected], $this->capabilities->getCapabilities());
196
+    }
197 197
 }
Please login to merge, or discard this patch.
apps/theming/lib/Capabilities.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -20,97 +20,97 @@
 block discarded – undo
20 20
  */
21 21
 class Capabilities implements IPublicCapability {
22 22
 
23
-	/**
24
-	 * @param ThemingDefaults $theming
25
-	 * @param Util $util
26
-	 * @param IURLGenerator $url
27
-	 * @param IConfig $config
28
-	 */
29
-	public function __construct(
30
-		protected ThemingDefaults $theming,
31
-		protected Util $util,
32
-		protected IURLGenerator $url,
33
-		protected IConfig $config,
34
-		protected IUserSession $userSession,
35
-	) {
36
-	}
23
+    /**
24
+     * @param ThemingDefaults $theming
25
+     * @param Util $util
26
+     * @param IURLGenerator $url
27
+     * @param IConfig $config
28
+     */
29
+    public function __construct(
30
+        protected ThemingDefaults $theming,
31
+        protected Util $util,
32
+        protected IURLGenerator $url,
33
+        protected IConfig $config,
34
+        protected IUserSession $userSession,
35
+    ) {
36
+    }
37 37
 
38
-	/**
39
-	 * Return this classes capabilities
40
-	 *
41
-	 * @return array{
42
-	 *     theming: array{
43
-	 *         name: string,
44
-	 *         productName: string,
45
-	 *         url: string,
46
-	 *         slogan: string,
47
-	 *         color: string,
48
-	 *         color-text: string,
49
-	 *         color-element: string,
50
-	 *         color-element-bright: string,
51
-	 *         color-element-dark: string,
52
-	 *         logo: string,
53
-	 *         background: string,
54
-	 *         background-text: string,
55
-	 *         background-plain: bool,
56
-	 *         background-default: bool,
57
-	 *         logoheader: string,
58
-	 *         favicon: string,
59
-	 *     },
60
-	 * }
61
-	 */
62
-	public function getCapabilities() {
63
-		$color = $this->theming->getDefaultColorPrimary();
64
-		$colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
38
+    /**
39
+     * Return this classes capabilities
40
+     *
41
+     * @return array{
42
+     *     theming: array{
43
+     *         name: string,
44
+     *         productName: string,
45
+     *         url: string,
46
+     *         slogan: string,
47
+     *         color: string,
48
+     *         color-text: string,
49
+     *         color-element: string,
50
+     *         color-element-bright: string,
51
+     *         color-element-dark: string,
52
+     *         logo: string,
53
+     *         background: string,
54
+     *         background-text: string,
55
+     *         background-plain: bool,
56
+     *         background-default: bool,
57
+     *         logoheader: string,
58
+     *         favicon: string,
59
+     *     },
60
+     * }
61
+     */
62
+    public function getCapabilities() {
63
+        $color = $this->theming->getDefaultColorPrimary();
64
+        $colorText = $this->util->invertTextColor($color) ? '#000000' : '#ffffff';
65 65
 
66
-		$backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
67
-		$backgroundColor = $this->theming->getColorBackground();
68
-		$backgroundText = $this->theming->getTextColorBackground();
69
-		$backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $backgroundColor !== BackgroundService::DEFAULT_COLOR);
70
-		$background = $backgroundPlain ? $backgroundColor : $this->url->getAbsoluteURL($this->theming->getBackground());
66
+        $backgroundLogo = $this->config->getAppValue('theming', 'backgroundMime', '');
67
+        $backgroundColor = $this->theming->getColorBackground();
68
+        $backgroundText = $this->theming->getTextColorBackground();
69
+        $backgroundPlain = $backgroundLogo === 'backgroundColor' || ($backgroundLogo === '' && $backgroundColor !== BackgroundService::DEFAULT_COLOR);
70
+        $background = $backgroundPlain ? $backgroundColor : $this->url->getAbsoluteURL($this->theming->getBackground());
71 71
 
72
-		$user = $this->userSession->getUser();
73
-		if ($user instanceof IUser) {
74
-			/**
75
-			 * Mimics the logic of generateUserBackgroundVariables() that generates the CSS variables.
76
-			 * Also needs to be updated if the logic changes.
77
-			 * @see \OCA\Theming\Themes\CommonThemeTrait::generateUserBackgroundVariables()
78
-			 */
79
-			$color = $this->theming->getColorPrimary();
80
-			$colorText = $this->theming->getTextColorPrimary();
72
+        $user = $this->userSession->getUser();
73
+        if ($user instanceof IUser) {
74
+            /**
75
+             * Mimics the logic of generateUserBackgroundVariables() that generates the CSS variables.
76
+             * Also needs to be updated if the logic changes.
77
+             * @see \OCA\Theming\Themes\CommonThemeTrait::generateUserBackgroundVariables()
78
+             */
79
+            $color = $this->theming->getColorPrimary();
80
+            $colorText = $this->theming->getTextColorPrimary();
81 81
 
82
-			$backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
83
-			if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
84
-				$backgroundPlain = false;
85
-				$background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground');
86
-			} elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) {
87
-				$backgroundPlain = false;
88
-				$background = $this->url->linkTo(Application::APP_ID, "img/background/$backgroundImage");
89
-			} elseif ($backgroundImage !== BackgroundService::BACKGROUND_DEFAULT) {
90
-				$backgroundPlain = true;
91
-				$background = $backgroundColor;
92
-			}
93
-		}
82
+            $backgroundImage = $this->config->getUserValue($user->getUID(), Application::APP_ID, 'background_image', BackgroundService::BACKGROUND_DEFAULT);
83
+            if ($backgroundImage === BackgroundService::BACKGROUND_CUSTOM) {
84
+                $backgroundPlain = false;
85
+                $background = $this->url->linkToRouteAbsolute('theming.userTheme.getBackground');
86
+            } elseif (isset(BackgroundService::SHIPPED_BACKGROUNDS[$backgroundImage])) {
87
+                $backgroundPlain = false;
88
+                $background = $this->url->linkTo(Application::APP_ID, "img/background/$backgroundImage");
89
+            } elseif ($backgroundImage !== BackgroundService::BACKGROUND_DEFAULT) {
90
+                $backgroundPlain = true;
91
+                $background = $backgroundColor;
92
+            }
93
+        }
94 94
 
95
-		return [
96
-			'theming' => [
97
-				'name' => $this->theming->getName(),
98
-				'productName' => $this->theming->getProductName(),
99
-				'url' => $this->theming->getBaseUrl(),
100
-				'slogan' => $this->theming->getSlogan(),
101
-				'color' => $color,
102
-				'color-text' => $colorText,
103
-				'color-element' => $this->util->elementColor($color),
104
-				'color-element-bright' => $this->util->elementColor($color),
105
-				'color-element-dark' => $this->util->elementColor($color, false),
106
-				'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
107
-				'background' => $background,
108
-				'background-text' => $backgroundText,
109
-				'background-plain' => $backgroundPlain,
110
-				'background-default' => !$this->util->isBackgroundThemed(),
111
-				'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
112
-				'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
113
-			],
114
-		];
115
-	}
95
+        return [
96
+            'theming' => [
97
+                'name' => $this->theming->getName(),
98
+                'productName' => $this->theming->getProductName(),
99
+                'url' => $this->theming->getBaseUrl(),
100
+                'slogan' => $this->theming->getSlogan(),
101
+                'color' => $color,
102
+                'color-text' => $colorText,
103
+                'color-element' => $this->util->elementColor($color),
104
+                'color-element-bright' => $this->util->elementColor($color),
105
+                'color-element-dark' => $this->util->elementColor($color, false),
106
+                'logo' => $this->url->getAbsoluteURL($this->theming->getLogo()),
107
+                'background' => $background,
108
+                'background-text' => $backgroundText,
109
+                'background-plain' => $backgroundPlain,
110
+                'background-default' => !$this->util->isBackgroundThemed(),
111
+                'logoheader' => $this->url->getAbsoluteURL($this->theming->getLogo()),
112
+                'favicon' => $this->url->getAbsoluteURL($this->theming->getLogo()),
113
+            ],
114
+        ];
115
+    }
116 116
 }
Please login to merge, or discard this patch.