Skip to content

Commit 514ba2c

Browse files
Merge pull request #14 from ARCANEDEV/patch-1
Updating the supported image types
2 parents 5b13a6e + bcd1425 commit 514ba2c

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

config/gravatar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| -----------------------------------------------------------------
1010
| The default avatar to display if we have no results.
1111
|
12-
| Supported: 'identicon', '404', 'mm', 'monsterid', 'wavatar', 'retro', false
12+
| Supported: 'identicon', '404', 'mp', 'monsterid', 'wavatar', 'retro', 'robohash', 'blank', false
1313
*/
1414

1515
'default' => 'identicon',

src/Exceptions/InvalidImageUrlException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*/
1111
class InvalidImageUrlException extends InvalidArgumentException
1212
{
13-
public static function make()
13+
public static function make($image)
1414
{
1515
return new static(
16-
'The default image specified is not a recognized gravatar "default" and is not a valid URL'
16+
"The default image specified is not a recognized gravatar `default` and is not a valid URL: `{$image}`"
1717
);
1818
}
1919
}

src/Gravatar.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ class Gravatar implements Contracts\Gravatar
7272
*
7373
* @var array
7474
*/
75-
private $supportedImages = ['404', 'mm', 'identicon', 'monsterid', 'wavatar', 'retro'];
75+
private $supportedImages = [
76+
'404', 'mp', 'identicon', 'monsterid', 'wavatar', 'retro', 'robohash', 'blank',
77+
];
7678

7779
/**
7880
* Supported image ratings.
7981
*
8082
* @var array
8183
*/
82-
private $supportedRatings = ['g', 'pg', 'r', 'x'];
84+
private $supportedRatings = [
85+
'g', 'pg', 'r', 'x'
86+
];
8387

8488
/* -----------------------------------------------------------------
8589
| Constructor
@@ -93,7 +97,7 @@ class Gravatar implements Contracts\Gravatar
9397
* @param int $size
9498
* @param string $rating
9599
*/
96-
public function __construct($default = 'mm', $size = 80, $rating = 'g')
100+
public function __construct($default = 'blank', $size = 80, $rating = 'g')
97101
{
98102
$this->setDefaultImage($default);
99103
$this->setSize($size);
@@ -360,7 +364,7 @@ public function exists($email)
360364
private function checkImageUrl($image)
361365
{
362366
if ( ! filter_var($image, FILTER_VALIDATE_URL)) {
363-
throw Exceptions\InvalidImageUrlException::make();
367+
throw Exceptions\InvalidImageUrlException::make($image);
364368
}
365369

366370
return $image;

tests/GravatarTest.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace Arcanedev\Gravatar\Tests;
22

3+
use Arcanedev\Gravatar\Exceptions\InvalidImageUrlException;
34
use Arcanedev\Gravatar\Gravatar;
45

56
/**
@@ -97,10 +98,10 @@ public function it_must_throw_an_invalid_rating_exception()
9798
}
9899

99100
/** @test */
100-
public function it_must_throw_invalid_image_url_on_setting_default_image()
101+
public function it_must_throw_invalid_image_url_when_setting_default_image()
101102
{
102103
$this->expectException(\Arcanedev\Gravatar\Exceptions\InvalidImageUrlException::class);
103-
$this->expectExceptionMessage('The default image specified is not a recognized gravatar "default" and is not a valid URL');
104+
$this->expectExceptionMessage('The default image specified is not a recognized gravatar `default` and is not a valid URL: `hello.com/img.png`');
104105

105106
new Gravatar('hello.com/img.png');
106107
}
@@ -283,6 +284,36 @@ public function it_get_profile()
283284
static::assertCount(1, $data['entry']);
284285
}
285286

287+
/** @test */
288+
public function it_can_check_if_image_type_is_supported()
289+
{
290+
$types = [
291+
'404',
292+
'mp',
293+
'identicon',
294+
'monsterid',
295+
'wavatar',
296+
'retro',
297+
'robohash',
298+
'blank',
299+
];
300+
301+
foreach ($types as $type) {
302+
$this->gravatar->setDefaultImage($type);
303+
304+
static::assertSame($type, $this->gravatar->getDefaultImage());
305+
}
306+
}
307+
308+
/** @test */
309+
public function it_must_throw_exception_when_default_image_not_supported()
310+
{
311+
$this->expectException(InvalidImageUrlException::class);
312+
$this->expectExceptionMessage('The default image specified is not a recognized gravatar `default` and is not a valid URL: `github`');
313+
314+
$this->gravatar->setDefaultImage('github');
315+
}
316+
286317
/* -----------------------------------------------------------------
287318
| Other Methods
288319
| -----------------------------------------------------------------

0 commit comments

Comments
 (0)