2017-12-04 15:11:23 +08:00
|
|
|
<?php
|
|
|
|
|
2018-08-17 15:25:08 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2017-12-04 15:11:23 +08:00
|
|
|
use App\Services\Minecraft;
|
2019-03-14 00:02:00 +08:00
|
|
|
use Illuminate\Http\Testing\FileFactory;
|
2017-12-04 15:11:23 +08:00
|
|
|
use App\Http\Controllers\TextureController;
|
|
|
|
|
|
|
|
class MinecraftTest extends TestCase
|
|
|
|
{
|
2019-03-14 00:02:00 +08:00
|
|
|
private $fileFactory;
|
|
|
|
|
2019-02-27 23:44:50 +08:00
|
|
|
protected function setUp(): void
|
2017-12-04 15:11:23 +08:00
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-03-14 00:02:00 +08:00
|
|
|
$this->fileFactory = new FileFactory();
|
2017-12-04 15:11:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGenerateAvatarFromSkin()
|
|
|
|
{
|
2019-03-14 00:02:00 +08:00
|
|
|
$file = $this->fileFactory->image('skin.png');
|
|
|
|
|
|
|
|
imagepng(imagecreatetruecolor(64, 32), $file->path());
|
|
|
|
$avatar = Minecraft::generateAvatarFromSkin(file_get_contents($file->path()), 50);
|
2017-12-04 15:11:23 +08:00
|
|
|
$this->assertEquals(50, imagesx($avatar));
|
|
|
|
$this->assertEquals(50, imagesy($avatar));
|
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(128, 64), $file->path());
|
|
|
|
$avatar = Minecraft::generateAvatarFromSkin(file_get_contents($file->path()), 50);
|
2017-12-04 15:11:23 +08:00
|
|
|
$this->assertEquals(50, imagesx($avatar));
|
|
|
|
$this->assertEquals(50, imagesy($avatar));
|
|
|
|
|
|
|
|
$avatar = Minecraft::generateAvatarFromSkin(
|
2018-06-28 21:55:33 +08:00
|
|
|
base64_decode(TextureController::getDefaultSteveSkin()), 50, 'l'
|
2017-12-04 15:11:23 +08:00
|
|
|
);
|
|
|
|
$this->assertEquals(50, imagesx($avatar));
|
|
|
|
$this->assertEquals(50, imagesy($avatar));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGeneratePreviewFromSkin()
|
|
|
|
{
|
2019-03-14 00:02:00 +08:00
|
|
|
$file = $this->fileFactory->image('skin.png');
|
|
|
|
|
|
|
|
imagepng(imagecreatetruecolor(64, 32), $file->path());
|
2018-06-28 21:55:33 +08:00
|
|
|
$preview = Minecraft::generatePreviewFromSkin(
|
2019-03-14 00:02:00 +08:00
|
|
|
file_get_contents($file->path()), 50, false, 'front'
|
2018-06-28 21:55:33 +08:00
|
|
|
);
|
2017-12-04 15:11:23 +08:00
|
|
|
$this->assertEquals(25, imagesx($preview));
|
|
|
|
$this->assertEquals(50, imagesy($preview));
|
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(64, 32), $file->path());
|
2018-01-04 10:00:15 +08:00
|
|
|
$preview = Minecraft::generatePreviewFromSkin(
|
2019-03-14 00:02:00 +08:00
|
|
|
file_get_contents($file->path()),
|
2018-01-04 10:00:15 +08:00
|
|
|
50,
|
2018-06-28 21:55:33 +08:00
|
|
|
true, // Alex model
|
|
|
|
'both',
|
|
|
|
4
|
2018-01-04 10:00:15 +08:00
|
|
|
);
|
|
|
|
$this->assertEquals(56, imagesx($preview));
|
|
|
|
$this->assertEquals(50, imagesy($preview));
|
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(64, 64), $file->path());
|
2018-01-04 10:00:15 +08:00
|
|
|
$preview = Minecraft::generatePreviewFromSkin(
|
2019-03-14 00:02:00 +08:00
|
|
|
file_get_contents($file->path()),
|
2018-06-28 21:55:33 +08:00
|
|
|
100,
|
|
|
|
true, // Alex model
|
|
|
|
'both',
|
|
|
|
8
|
2018-01-04 10:00:15 +08:00
|
|
|
);
|
2018-06-28 21:55:33 +08:00
|
|
|
$this->assertEquals(125, imagesx($preview));
|
|
|
|
$this->assertEquals(100, imagesy($preview));
|
2018-01-04 10:00:15 +08:00
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(128, 64), $file->path());
|
|
|
|
$preview = Minecraft::generatePreviewFromSkin(file_get_contents($file->path()), 50);
|
2017-12-04 15:11:23 +08:00
|
|
|
$this->assertEquals(56, imagesx($preview));
|
|
|
|
$this->assertEquals(50, imagesy($preview));
|
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(128, 128), $file->path());
|
|
|
|
$preview = Minecraft::generatePreviewFromSkin(file_get_contents($file->path()), 50);
|
2017-12-04 15:11:23 +08:00
|
|
|
$this->assertEquals(56, imagesx($preview));
|
|
|
|
$this->assertEquals(50, imagesy($preview));
|
|
|
|
|
|
|
|
$preview = Minecraft::generatePreviewFromSkin(
|
2018-06-28 21:55:33 +08:00
|
|
|
base64_decode(TextureController::getDefaultSteveSkin()),
|
2017-12-04 15:11:23 +08:00
|
|
|
50,
|
2018-06-28 21:55:33 +08:00
|
|
|
false,
|
|
|
|
'back'
|
2017-12-04 15:11:23 +08:00
|
|
|
);
|
|
|
|
$this->assertEquals(25, imagesx($preview));
|
|
|
|
$this->assertEquals(50, imagesy($preview));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGeneratePreviewFromCape()
|
|
|
|
{
|
2019-03-14 00:02:00 +08:00
|
|
|
$file = $this->fileFactory->image('cape.png');
|
|
|
|
|
|
|
|
imagepng(imagecreatetruecolor(128, 64), $file->path());
|
|
|
|
$preview = Minecraft::generatePreviewFromCape(file_get_contents($file->path()), 64);
|
2018-06-28 21:55:33 +08:00
|
|
|
$this->assertEquals(40, imagesx($preview));
|
|
|
|
$this->assertEquals(64, imagesy($preview));
|
|
|
|
|
2019-03-14 00:02:00 +08:00
|
|
|
imagepng(imagecreatetruecolor(128, 64), $file->path());
|
2018-06-28 21:55:33 +08:00
|
|
|
$preview = Minecraft::generatePreviewFromCape(
|
2019-03-14 00:02:00 +08:00
|
|
|
file_get_contents($file->path()),
|
2018-06-28 21:55:33 +08:00
|
|
|
64,
|
|
|
|
281,
|
|
|
|
250
|
|
|
|
);
|
|
|
|
$this->assertEquals(281, imagesx($preview));
|
|
|
|
$this->assertEquals(250, imagesy($preview));
|
2017-12-04 15:11:23 +08:00
|
|
|
}
|
|
|
|
}
|