30 lines
1.4 KiB
PHP
30 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace JumPHP\Ide\Tests;
|
|
|
|
use JumPHP\Ide\Workspace\ClipboardImage;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class ClipboardImageTest extends TestCase
|
|
{
|
|
public function testEachSystemReadsTheClipboardsPictureWithItsOwnTool(): void
|
|
{
|
|
self::assertSame('xclip', ClipboardImage::commands('Linux', '')[0]['command'][0]);
|
|
self::assertSame(['wl-paste', 'xclip'], array_map(fn ($w) => $w['command'][0], ClipboardImage::commands('Linux', 'wayland-0')));
|
|
self::assertSame('base64', ClipboardImage::commands('Windows')[0]['output']);
|
|
self::assertStringStartsWith('file:', ClipboardImage::commands('Darwin', null, '/tmp/x.png')[0]['output']);
|
|
}
|
|
|
|
public function testOnlyAPngIsTakenWhateverTheToolPrinted(): void
|
|
{
|
|
$png = "\x89PNG\r\n\x1a\n" . str_repeat("\0", 20);
|
|
self::assertSame($png, ClipboardImage::decode($png, 'raw'));
|
|
self::assertSame($png, ClipboardImage::decode(base64_encode($png) . "\r\n", 'base64'));
|
|
self::assertNull(ClipboardImage::decode('some text', 'raw'), 'text on the clipboard: no picture');
|
|
self::assertNull(ClipboardImage::decode('', 'base64'));
|
|
$file = sys_get_temp_dir() . '/clip-test-' . getmypid() . '.png';
|
|
file_put_contents($file, $png);
|
|
self::assertSame($png, ClipboardImage::decode('', 'file:' . $file));
|
|
self::assertFileDoesNotExist($file, 'the temporary file is removed');
|
|
}
|
|
}
|