diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index afda28b86..2a2c73e3e 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -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 diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index e631fd439..e2ddc1a86 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -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'])); } } diff --git a/tests/resources/initials.png b/tests/resources/initials.png new file mode 100644 index 000000000..08a61594c Binary files /dev/null and b/tests/resources/initials.png differ