Translated using Weblate (Portuguese)
[phpmyadmin.git] / tests / unit / FileTest.php
blob0b4db284118b980433d2f23c3e0c4280483ffc57
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\File;
8 use PhpMyAdmin\Import\ImportSettings;
9 use PHPUnit\Framework\Attributes\CoversClass;
10 use PHPUnit\Framework\Attributes\DataProvider;
11 use PHPUnit\Framework\Attributes\RequiresPhpExtension;
13 use function bin2hex;
14 use function file_get_contents;
16 #[CoversClass(File::class)]
17 class FileTest extends AbstractTestCase
19 /**
20 * Setup function for test cases
22 protected function setUp(): void
24 parent::setUp();
26 ImportSettings::$charsetConversion = false;
29 /**
30 * Test for File::getCompression
32 * @param string $file file string
33 * @param string $mime expected mime
35 #[DataProvider('compressedFiles')]
36 public function testMIME(string $file, string $mime): void
38 $arr = new File($file);
39 self::assertSame($mime, $arr->getCompression());
42 /**
43 * Test for File::getContent
45 * @param string $file file string
47 #[DataProvider('compressedFiles')]
48 public function testBinaryContent(string $file): void
50 $data = '0x' . bin2hex((string) file_get_contents($file));
51 $file = new File($file);
52 self::assertSame($data, $file->getContent());
55 /**
56 * Test for File::read
58 * @param string $file file string
60 #[DataProvider('compressedFiles')]
61 #[RequiresPhpExtension('bz2')]
62 #[RequiresPhpExtension('zip')]
63 public function testReadCompressed(string $file): void
65 $file = new File($file);
66 $file->setDecompressContent(true);
67 $file->open();
68 self::assertSame("TEST FILE\n", $file->read(100));
69 $file->close();
72 /** @return array<array{string, string}> */
73 public static function compressedFiles(): array
75 return [
76 ['./tests/test_data/test.gz', 'application/gzip'],
77 ['./tests/test_data/test.bz2', 'application/bzip2'],
78 ['./tests/test_data/test.zip', 'application/zip'],