1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00

Add Tests

+ Added Tests
+ Remove unneeded rand variable
This commit is contained in:
Bradley Schofield 2022-09-05 11:21:04 +01:00
parent 37530d30df
commit 9e0e2f8e77
3 changed files with 24 additions and 28 deletions

View file

@ -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

View file

@ -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']));
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB