Add Tests
+ Added Tests + Remove unneeded rand variable
This commit is contained in:
parent
37530d30df
commit
9e0e2f8e77
|
@ -368,8 +368,6 @@ App::get('/v1/avatars/initials')
|
|||
['background' => '#CBB1FC'] // Purple
|
||||
];
|
||||
|
||||
$rand = \rand(0, \count($themes) - 1);
|
||||
|
||||
$name = (!empty($name)) ? $name : $user->getAttribute('name', $user->getAttribute('email', ''));
|
||||
$words = \explode(' ', \strtoupper($name));
|
||||
// if there is no space, try to split by `_` underscore
|
||||
|
|
|
@ -491,7 +491,6 @@ trait AvatarsBase
|
|||
'name' => 'W W',
|
||||
'width' => 200,
|
||||
'height' => 200,
|
||||
'color' => 'ffffff',
|
||||
'background' => '000000',
|
||||
]);
|
||||
|
||||
|
@ -508,34 +507,33 @@ trait AvatarsBase
|
|||
'name' => 'W W',
|
||||
'width' => 200000,
|
||||
'height' => 200,
|
||||
'color' => 'ffffff',
|
||||
'background' => '000000',
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'name' => 'W W',
|
||||
'width' => 200,
|
||||
'height' => 200,
|
||||
'color' => 'white',
|
||||
'background' => '000000',
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
|
||||
$response = $this->client->call(Client::METHOD_GET, '/avatars/initials', [
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], [
|
||||
'name' => 'W W',
|
||||
'width' => 200,
|
||||
'height' => 200,
|
||||
'color' => 'ffffff',
|
||||
'background' => 'black',
|
||||
]);
|
||||
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
public function testInitialImage()
|
||||
{
|
||||
$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']);
|
||||
$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']));
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/resources/initials.png
Normal file
BIN
tests/resources/initials.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3 KiB |
Loading…
Reference in a new issue