league-oauth2-ely/tests/ResourceOwnerTest.php

84 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2016-11-25 16:56:29 +05:30
<?php
namespace Ely\OAuth2\Client\Test;
use DateTime;
2016-11-25 16:56:29 +05:30
use Ely\OAuth2\Client\ResourceOwner;
use PHPUnit\Framework\TestCase;
2016-11-25 16:56:29 +05:30
class ResourceOwnerTest extends TestCase {
2018-08-20 18:09:57 +05:30
public function testGetId() {
$this->assertSame(1, $this->createModel()->getId());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetUuid() {
$this->assertSame('ffc8fdc9-5824-509e-8a57-c99b940fb996', $this->createModel()->getUuid());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetUsername() {
$this->assertSame('ErickSkrauch', $this->createModel()->getUsername());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetEmail() {
$this->assertSame('erickskrauch@ely.by', $this->createModel()->getEmail());
2016-11-25 16:56:29 +05:30
$this->assertNull($this->createModelWithoutEmail()->getEmail());
}
2018-08-20 18:09:57 +05:30
public function testGetRegisteredAt() {
2016-11-25 16:56:29 +05:30
$registeredAt = $this->createModel()->getRegisteredAt();
$this->assertInstanceOf(DateTime::class, $registeredAt);
$this->assertSame(1470566470, $registeredAt->getTimestamp());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetProfileLink() {
$this->assertSame('http://ely.by/u1', $this->createModel()->getProfileLink());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetPreferredLanguage() {
$this->assertSame('be', $this->createModel()->getPreferredLanguage());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testGetSkinUrl() {
$this->assertSame('http://skinsystem.ely.by/skins/ErickSkrauch.png', $this->createModel()->getSkinUrl());
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
public function testToArray() {
2016-11-25 16:56:29 +05:30
$array = $this->createModel()->toArray();
$this->assertInternalType('array', $array);
$this->assertSame(1, $array['id']);
$this->assertSame('ffc8fdc9-5824-509e-8a57-c99b940fb996', $array['uuid']);
$this->assertSame('ErickSkrauch', $array['username']);
$this->assertSame('erickskrauch@ely.by', $array['email']);
$this->assertSame(1470566470, $array['registeredAt']);
$this->assertSame('http://ely.by/u1', $array['profileLink']);
$this->assertSame('http://skinsystem.ely.by/skins/ErickSkrauch.png', $array['skinUrl']);
2016-11-25 16:56:29 +05:30
$array = $this->createModelWithoutEmail()->toArray();
$this->assertArrayNotHasKey('email', $array);
}
2018-08-20 18:09:57 +05:30
private function createModelWithoutEmail() {
2016-11-25 16:56:29 +05:30
$params = $this->getAllResponseParams();
unset($params['email']);
return new ResourceOwner($params);
}
2018-08-20 18:09:57 +05:30
private function createModel() {
2016-11-25 16:56:29 +05:30
return new ResourceOwner($this->getAllResponseParams());
}
2018-08-20 18:09:57 +05:30
private function getAllResponseParams() {
return [
'id' => 1,
'uuid' => 'ffc8fdc9-5824-509e-8a57-c99b940fb996',
'username' => 'ErickSkrauch',
'registeredAt' => 1470566470,
'profileLink' => 'http://ely.by/u1',
'preferredLanguage' => 'be',
'email' => 'erickskrauch@ely.by',
];
2016-11-25 16:56:29 +05:30
}
2018-08-20 18:09:57 +05:30
2016-11-25 16:56:29 +05:30
}