PluginProbe
ووسلام – همگام سازی ووکامرس و باسلام / trunk
ووسلام – همگام سازی ووکامرس و باسلام vtrunk
1.10.18 1.10.17 1.10.15 1.10.14 1.10.13 1.10.12 1.10.10 1.10.9 1.10.8 1.10.7 1.10.6 1.10.5 1.10.4 1.10.3 1.10.2 1.10.1 1.10.0 1.9.2 1.9.1 1.9.0 1.8.8 1.8.5 1.8.6 1.8.7 1.8.4 All 51 releases
sync-basalam / tests / Services / MediaUploadServiceTest.php

MediaUploadServiceTest.php in ووسلام – همگام سازی ووکامرس و باسلام trunk, at tests/Services/MediaUploadServiceTest.php

66 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SyncBasalam\Tests\Services;
4
5 use PHPUnit\Framework\TestCase;
6 use ReflectionClass;
7 use SyncBasalam\Services\MediaMimeType;
8 use SyncBasalam\Services\MediaUploadService;
9
10 class MediaUploadServiceTest extends TestCase
11 {
12 protected function tearDown(): void
13 {
14 unset(
15 $GLOBALS['sync_basalam_test_image_mime'],
16 $GLOBALS['sync_basalam_test_filetype_mime']
17 );
18 }
19
20 public function testJpegContentWinsOverNonStandardWordPressMimeAlias(): void
21 {
22 $filePath = tempnam(sys_get_temp_dir(), 'woosalam_jpeg_');
23 self::assertNotFalse($filePath);
24
25 // A complete one-pixel JPEG image. Its temporary path deliberately has no .jpg extension.
26 $jpeg = base64_decode(
27 '/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAP//////////////////////////////////////////////////////////////////////////////////////2wBDAf//////////////////////////////////////////////////////////////////////////////////////wAARCAABAAEDASIAAhEBAxEB/8QAFQABAQAAAAAAAAAAAAAAAAAAAAX/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAF//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABBQJ//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPwF//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPwF//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAGPwJ//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPyF//9oADAMBAAIAAwAAABAf/8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAwEBPxB//8QAFBEBAAAAAAAAAAAAAAAAAAAAAP/aAAgBAgEBPxB//8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQABPxB//9k=',
28 true
29 );
30 self::assertNotFalse($jpeg);
31 file_put_contents($filePath, $jpeg);
32
33 $GLOBALS['sync_basalam_test_image_mime'] = false;
34 $GLOBALS['sync_basalam_test_filetype_mime'] = 'image/jpg';
35
36 try {
37 $service = (new ReflectionClass(MediaUploadService::class))->newInstanceWithoutConstructor();
38 $method = new \ReflectionMethod(MediaUploadService::class, 'detectMimeType');
39 $method->setAccessible(true);
40
41 self::assertSame('image/jpeg', $method->invoke($service, $filePath));
42 } finally {
43 unlink($filePath);
44 }
45 }
46
47 /**
48 * @dataProvider mimeAliasProvider
49 */
50 public function testUploadioMimeAliasesAreCanonicalized(string $input, string $expected): void
51 {
52 self::assertSame($expected, MediaMimeType::canonicalize($input));
53 }
54
55 public function mimeAliasProvider(): array
56 {
57 return [
58 'jpg alias' => ['image/jpg', 'image/jpeg'],
59 'progressive jpg alias' => ['image/pjpeg', 'image/jpeg'],
60 'png alias' => ['image/x-png', 'image/png'],
61 'Microsoft bmp alias' => ['image/x-ms-bmp', 'image/bmp'],
62 'Windows bmp alias' => ['image/x-windows-bmp', 'image/bmp'],
63 ];
64 }
65 }
66