mirror of
https://github.com/cgsmith/yii2-user.git
synced 2026-03-21 16:25:33 -05:00
Add additional features
This commit is contained in:
62
tests/unit/models/ProfileTest.php
Normal file
62
tests/unit/models/ProfileTest.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace tests\unit\models;
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use cgsmith\user\models\Profile;
|
||||
|
||||
class ProfileTest extends Unit
|
||||
{
|
||||
private Profile $profile;
|
||||
|
||||
protected function _before(): void
|
||||
{
|
||||
$this->profile = new Profile();
|
||||
}
|
||||
|
||||
public function testGravatarUrlGeneratesCorrectHash(): void
|
||||
{
|
||||
$url = $this->profile->getGravatarUrl('test@example.com');
|
||||
$expected = 'https://www.gravatar.com/avatar/' . md5('test@example.com') . '?s=200&d=identicon';
|
||||
$this->assertEquals($expected, $url);
|
||||
}
|
||||
|
||||
public function testGravatarUrlHandlesCaseAndWhitespace(): void
|
||||
{
|
||||
$url1 = $this->profile->getGravatarUrl(' Test@Example.COM ');
|
||||
$url2 = $this->profile->getGravatarUrl('test@example.com');
|
||||
$this->assertEquals($url1, $url2);
|
||||
}
|
||||
|
||||
public function testGravatarUrlRespectsCustomSize(): void
|
||||
{
|
||||
$url = $this->profile->getGravatarUrl('test@example.com', 80);
|
||||
$this->assertStringContainsString('s=80', $url);
|
||||
}
|
||||
|
||||
public function testTimezoneListIsNotEmpty(): void
|
||||
{
|
||||
$list = Profile::getTimezoneList();
|
||||
$this->assertNotEmpty($list);
|
||||
}
|
||||
|
||||
public function testTimezoneListKeysAreValidIdentifiers(): void
|
||||
{
|
||||
$list = Profile::getTimezoneList();
|
||||
$validIdentifiers = \DateTimeZone::listIdentifiers();
|
||||
|
||||
foreach (array_keys($list) as $key) {
|
||||
$this->assertContains($key, $validIdentifiers);
|
||||
}
|
||||
}
|
||||
|
||||
public function testTimezoneListValuesReplaceUnderscores(): void
|
||||
{
|
||||
$list = Profile::getTimezoneList();
|
||||
|
||||
$this->assertEquals('America/New York', $list['America/New_York']);
|
||||
$this->assertEquals('Europe/London', $list['Europe/London']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user