2020-01-13 00:11:16 +13:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\E2E\Services\Avatars;
|
|
|
|
|
|
|
|
use Tests\E2E\Client;
|
|
|
|
|
|
|
|
trait AvatarsBase
|
|
|
|
{
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetCreditCard(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/unknown', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/credit-cards/visa', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 2001,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetBrowser(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/unknown', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/browsers/ch', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 2001,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetFlag(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/flags/unknown', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/flags/us', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'width' => 2001,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetImage(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
2023-09-30 06:25:22 +13:00
|
|
|
'url' => 'https://appwrite.io/images/open-graph/website.png',
|
2020-01-13 00:11:16 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
2023-09-30 06:25:22 +13:00
|
|
|
'url' => 'https://appwrite.io/images/open-graph/website.png',
|
2020-01-13 00:11:16 +13:00
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
2023-09-30 06:25:22 +13:00
|
|
|
'url' => 'https://appwrite.io/images/open-graph/website.png',
|
2020-01-13 00:11:16 +13:00
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'url' => 'https://appwrite.io/images/unknown.png',
|
|
|
|
'width' => 300,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
2023-09-30 06:25:22 +13:00
|
|
|
'url' => 'https://appwrite.io/images/open-graph/website.png',
|
2020-01-13 00:11:16 +13:00
|
|
|
'width' => 2001,
|
|
|
|
'height' => 300,
|
|
|
|
'quality' => 30,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-02-17 04:16:37 +13:00
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/image', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'url' => 'invalid://appwrite.io/images/apple.png'
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2020-01-13 00:11:16 +13:00
|
|
|
|
|
|
|
// TODO Add test for non-image file (PDF, WORD)
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetFavicon(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
2023-09-30 06:25:22 +13:00
|
|
|
'url' => 'https://github.com/',
|
2020-01-13 00:11:16 +13:00
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2023-09-30 06:25:22 +13:00
|
|
|
$this->assertEquals('image/x-icon', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'url' => 'unknown-address',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'url' => 'http://unknown-address.test',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2023-08-30 18:04:52 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'url' => 'http://localhost',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(404, $response['headers']['status-code']);
|
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-05-24 02:54:50 +12:00
|
|
|
public function testGetQR(): array
|
2020-01-13 00:11:16 +13:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
2021-01-10 18:53:58 +13:00
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$this->assertEquals(400, $image->getImageWidth());
|
|
|
|
$this->assertEquals(400, $image->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-default.png')), strlen($response['body']));
|
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
2021-01-10 18:53:58 +13:00
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$this->assertEquals(200, $image->getImageWidth());
|
|
|
|
$this->assertEquals(200, $image->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200.png')), strlen($response['body']));
|
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 200,
|
|
|
|
'margin' => 10,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
2021-01-10 18:53:58 +13:00
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$this->assertEquals(200, $image->getImageWidth());
|
|
|
|
$this->assertEquals(200, $image->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body']));
|
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 200,
|
|
|
|
'margin' => 10,
|
|
|
|
'download' => 1,
|
|
|
|
]);
|
|
|
|
|
2021-01-10 18:53:58 +13:00
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$this->assertEquals(200, $image->getImageWidth());
|
|
|
|
$this->assertEquals(200, $image->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/qr/qr-size-200-margin-10.png')), strlen($response['body']));
|
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('attachment; filename="qr.png"', $response['headers']['content-disposition']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-01-13 00:11:16 +13:00
|
|
|
$this->assertNotEmpty($response['body']);
|
2022-05-24 02:54:50 +12:00
|
|
|
|
2020-01-13 00:11:16 +13:00
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 1001,
|
|
|
|
'margin' => 10,
|
|
|
|
'download' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 400,
|
|
|
|
'margin' => 11,
|
|
|
|
'download' => 1,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/qr', [
|
2020-02-17 20:16:11 +13:00
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
2020-01-13 00:11:16 +13:00
|
|
|
], [
|
|
|
|
'text' => 'url:https://appwrite.io/',
|
|
|
|
'size' => 400,
|
|
|
|
'margin' => 10,
|
|
|
|
'download' => 2,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
2020-06-10 07:54:15 +12:00
|
|
|
|
|
|
|
|
|
|
|
public function testGetInitials()
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test for SUCCESS
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-06-10 07:54:15 +12:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-06-10 07:54:15 +12:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'W W',
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-06-10 07:54:15 +12:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'W W',
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
'background' => '000000',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
2020-07-07 07:53:26 +12:00
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
2020-06-10 07:54:15 +12:00
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for FAILURE
|
|
|
|
*/
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'W W',
|
|
|
|
'width' => 200000,
|
|
|
|
'height' => 200,
|
|
|
|
'background' => '000000',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(400, $response['headers']['status-code']);
|
2022-09-05 22:21:04 +12:00
|
|
|
}
|
2020-06-10 07:54:15 +12:00
|
|
|
|
2022-09-05 22:21:04 +12:00
|
|
|
public function testInitialImage()
|
|
|
|
{
|
2020-06-10 07:54:15 +12:00
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'W W',
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
2022-09-05 22:21:04 +12:00
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
2020-06-10 07:54:15 +12:00
|
|
|
|
2022-09-05 22:21:04 +12:00
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$original = new \Imagick(__DIR__ . '/../../../resources/initials.png');
|
2020-06-10 07:54:15 +12:00
|
|
|
|
2022-09-05 22:21:04 +12:00
|
|
|
$this->assertEquals($image->getImageWidth(), $original->getImageWidth());
|
|
|
|
$this->assertEquals($image->getImageHeight(), $original->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/initials.png')), strlen($response['body']));
|
2020-06-10 07:54:15 +12:00
|
|
|
}
|
2023-09-30 04:27:59 +13:00
|
|
|
|
|
|
|
public function testSpecialCharsInitalImage()
|
|
|
|
{
|
|
|
|
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
|
|
|
'x-appwrite-project' => $this->getProject()['$id'],
|
|
|
|
], [
|
|
|
|
'name' => 'W (Hello) W',
|
|
|
|
'width' => 200,
|
|
|
|
'height' => 200,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->assertEquals(200, $response['headers']['status-code']);
|
|
|
|
$this->assertEquals('image/png', $response['headers']['content-type']);
|
|
|
|
$this->assertNotEmpty($response['body']);
|
|
|
|
|
|
|
|
$image = new \Imagick();
|
|
|
|
$image->readImageBlob($response['body']);
|
|
|
|
$original = new \Imagick(__DIR__ . '/../../../resources/initials.png');
|
|
|
|
|
|
|
|
$this->assertEquals($image->getImageWidth(), $original->getImageWidth());
|
|
|
|
$this->assertEquals($image->getImageHeight(), $original->getImageHeight());
|
|
|
|
$this->assertEquals('PNG', $image->getImageFormat());
|
|
|
|
$this->assertEquals(strlen(\file_get_contents(__DIR__ . '/../../../resources/initials.png')), strlen($response['body']));
|
|
|
|
}
|
2022-05-24 02:54:50 +12:00
|
|
|
}
|