2016-11-25 16:56:29 +05:30
|
|
|
<?php
|
|
|
|
namespace Ely\OAuth2\Client\Test;
|
|
|
|
|
2019-02-24 05:06:41 +05:30
|
|
|
use DateTime;
|
2016-11-25 16:56:29 +05:30
|
|
|
use Ely\OAuth2\Client\ResourceOwner;
|
2019-02-24 05:06:41 +05:30
|
|
|
use PHPUnit\Framework\TestCase;
|
2016-11-25 16:56:29 +05:30
|
|
|
|
2019-02-24 05:06:41 +05:30
|
|
|
class ResourceOwnerTest extends TestCase {
|
2018-08-20 18:09:57 +05:30
|
|
|
|
|
|
|
public function testGetId() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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();
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
$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();
|
2019-02-24 05:06:41 +05:30
|
|
|
$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() {
|
2019-02-24 05:06:41 +05:30
|
|
|
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
|
|
|
}
|