|
11 | 11 |
|
12 | 12 | use Imagick; |
13 | 13 | use OCA\Libresign\AppInfo\Application; |
| 14 | +use OCA\Libresign\Exception\LibresignException; |
14 | 15 | use OCA\Libresign\Service\SignatureTextService; |
15 | 16 | use OCP\IAppConfig; |
16 | 17 | use OCP\IDateTimeZone; |
@@ -218,4 +219,60 @@ public static function providerSignerNameImage(): array { |
218 | 219 | public function testHasFont(): void { |
219 | 220 | $this->assertFileExists($fallbackFond = __DIR__ . '/../../../../3rdparty/composer/mpdf/mpdf/ttfonts/DejaVuSerifCondensed.ttf'); |
220 | 221 | } |
| 222 | + |
| 223 | + #[DataProvider('providerInvalidSignatureDimensions')] |
| 224 | + public function testSaveShouldRejectInvalidSignatureDimensions(float $signatureWidth, float $signatureHeight): void { |
| 225 | + $this->expectException(LibresignException::class); |
| 226 | + |
| 227 | + $this->getClass()->save( |
| 228 | + template: 'valid', |
| 229 | + signatureWidth: $signatureWidth, |
| 230 | + signatureHeight: $signatureHeight, |
| 231 | + ); |
| 232 | + } |
| 233 | + |
| 234 | + public static function providerInvalidSignatureDimensions(): array { |
| 235 | + return [ |
| 236 | + 'zero width' => [0.0, 100.0], |
| 237 | + 'fractional width below minimum' => [0.9999, 100.0], |
| 238 | + 'subnormal width' => [1.0E-320, 100.0], |
| 239 | + 'scientific width below minimum' => [1.0E-6, 100.0], |
| 240 | + 'negative width' => [-1.0, 100.0], |
| 241 | + 'very small negative width' => [-0.0001, 100.0], |
| 242 | + 'NaN width' => [NAN, 100.0], |
| 243 | + 'INF width' => [INF, 100.0], |
| 244 | + '-INF width' => [-INF, 100.0], |
| 245 | + 'zero height' => [350.0, 0.0], |
| 246 | + 'fractional height below minimum' => [350.0, 0.9999], |
| 247 | + 'subnormal height' => [350.0, 1.0E-320], |
| 248 | + 'scientific height below minimum' => [350.0, 1.0E-6], |
| 249 | + 'negative height' => [350.0, -1.0], |
| 250 | + 'very small negative height' => [350.0, -0.0001], |
| 251 | + 'NaN height' => [350.0, NAN], |
| 252 | + 'INF height' => [350.0, INF], |
| 253 | + '-INF height' => [350.0, -INF], |
| 254 | + 'both dimensions zero' => [0.0, 0.0], |
| 255 | + 'both dimensions negative' => [-1.0, -1.0], |
| 256 | + 'both dimensions fractional below minimum' => [0.5, 0.5], |
| 257 | + 'both dimensions NaN' => [NAN, NAN], |
| 258 | + 'both dimensions INF' => [INF, INF], |
| 259 | + 'mixed NaN and -INF' => [NAN, -INF], |
| 260 | + ]; |
| 261 | + } |
| 262 | + |
| 263 | + public function testGetFullSignatureDimensionsShouldFallbackToDefaultsWhenConfigIsInvalid(): void { |
| 264 | + $this->appConfig->setValueFloat(Application::APP_ID, 'signature_width', 0.0); |
| 265 | + $this->appConfig->setValueFloat(Application::APP_ID, 'signature_height', -1.0); |
| 266 | + |
| 267 | + $class = $this->getClass(); |
| 268 | + |
| 269 | + $this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_WIDTH, $class->getFullSignatureWidth()); |
| 270 | + $this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_HEIGHT, $class->getFullSignatureHeight()); |
| 271 | + |
| 272 | + $this->appConfig->setValueFloat(Application::APP_ID, 'signature_width', NAN); |
| 273 | + $this->appConfig->setValueFloat(Application::APP_ID, 'signature_height', INF); |
| 274 | + |
| 275 | + $this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_WIDTH, $class->getFullSignatureWidth()); |
| 276 | + $this->assertEquals(SignatureTextService::DEFAULT_SIGNATURE_HEIGHT, $class->getFullSignatureHeight()); |
| 277 | + } |
221 | 278 | } |
0 commit comments