Skip to content

Commit

Permalink
test: added test for Gravatar class
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Mar 31, 2024
1 parent 244dc5d commit 378959f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpmyfaq/src/phpMyFAQ/Services/Gravatar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

/**
* Service class for Gravatar support.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
Expand Down
40 changes: 40 additions & 0 deletions tests/phpMyFAQ/Services/GravatarTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace phpMyFAQ\Services;

use PHPUnit\Framework\TestCase;

class GravatarTest extends TestCase
{
public function testGetImage(): void
{
// Create a Gravatar object
$gravatar = new Gravatar();

// Test case 1: Test default parameters
$email = 'test@example.com';
$expectedResult1 = '<img src="https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0" class="" alt="Gravatar">';
$result1 = $gravatar->getImage($email);
$this->assertEquals($expectedResult1, $result1);

// Test case 2: Test with custom parameters
$params = [
'size' => 100,
'default' => 'identicon',
'rating' => 'pg',
'force_default' => true,
'class' => 'avatar-img'
];
$expectedResult2 = '<img src="https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?default=identicon&amp;size=100&amp;rating=pg&amp;forcedefault=y" class="avatar-img" alt="Gravatar">';
$result2 = $gravatar->getImage($email, $params);
$this->assertEquals($expectedResult2, $result2);

// Test case 3: Test with only class parameter
$params = [
'class' => 'rounded-img'
];
$expectedResult3 = '<img src="https://secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0" class="rounded-img" alt="Gravatar">';
$result3 = $gravatar->getImage($email, $params);
$this->assertEquals($expectedResult3, $result3);
}
}

0 comments on commit 378959f

Please sign in to comment.