Skip to content

Commit

Permalink
Merge pull request #4 from jderusse/more-data
Browse files Browse the repository at this point in the history
Expose additional fields
  • Loading branch information
qdequippe authored Jun 15, 2021
2 parents 6035d94 + 6655132 commit 08339cd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
25 changes: 19 additions & 6 deletions src/Provider/SymfonyConnectResourceOwner.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,22 @@ public function getId()
return $this->data->attributes->getNamedItem('id')->value;
}

public function getName()
public function getUsername()
{
$username = null;
$accounts = $this->xpath->query('./foaf:account/foaf:OnlineAccount', $this->data);
for ($i = 0; $i < $accounts->length; ++$i) {
$account = $accounts->item($i);
if ('SymfonyConnect' === $this->getNodeValue('./foaf:name', $account)) {
$username = $this->getNodeValue('foaf:accountName', $account);

break;
return $this->getNodeValue('foaf:accountName', $account);
}
}

return $username ?: $this->getNodeValue('./foaf:name', $this->data);
return null;
}

public function getName()
{
return $this->getUsername() ?: $this->getNodeValue('./foaf:name', $this->data);
}

public function getEmail()
Expand All @@ -75,9 +77,20 @@ public function toArray(): array
{
return [
'id' => $this->getId(),
'username' => $this->getUsername(),
'name' => $this->getName(),
'email' => $this->getEmail(),
'profilePicture' => $this->getProfilePicture(),
'realname' => $this->getNodeValue('./foaf:name', $this->data),
'biography' => $this->getNodeValue('./bio:olb', $this->data),
'birthday' => $this->getNodeValue('./foaf:birthday', $this->data),
'city' => $this->getNodeValue('./vcard:locality', $this->data),
'country' => $this->getNodeValue('./vcard:country-name', $this->data),
'company' => $this->getNodeValue('./cv:hasWorkHistory/cv:employedIn', $this->data),
'jobPosition' => $this->getNodeValue('./cv:hasWorkHistory/cv:jobTitle', $this->data),
'blogUrl' => $this->getNodeValue('./foaf:weblog', $this->data),
'url' => $this->getNodeValue('./foaf:homepage', $this->data),
'feedUrl' => $this->getNodeValue('./atom:link[@title="blog/feed"]', $this->data),
];
}

Expand Down
11 changes: 11 additions & 0 deletions tests/current_user_response.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
<foaf:weblog>https://example.com</foaf:weblog>
<foaf:homepage>https://example.com</foaf:homepage>
<foaf:mbox>john@example.com</foaf:mbox>
<foaf:account>
<foaf:OnlineAccount>
<foaf:name>SymfonyConnect</foaf:name>
<foaf:accountName><![CDATA[jdoe]]></foaf:accountName>
<since>Wed, 29 Oct 2008 12:04:33 +0100</since>
</foaf:OnlineAccount>
<foaf:OnlineAccount>
<foaf:name>github</foaf:name>
<foaf:accountName><![CDATA[jdoe-github]]></foaf:accountName>
</foaf:OnlineAccount>
</foaf:account>
</foaf:Person>
</root>
</api>
17 changes: 15 additions & 2 deletions tests/src/Provider/SymfonyConnectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,26 @@ public function testUserData()
$this->assertInstanceOf(SymfonyConnectResourceOwner::class, $user);
$this->assertEquals('39c049bb-9261-4d85-922c-15730d6fa8b1', $user->getId());
$this->assertEquals('john@example.com', $user->getEmail());
$this->assertEquals('jdoe', $user->getUsername());
$this->assertEquals('jdoe', $user->getName());

$this->assertEquals(
[
'id' => '39c049bb-9261-4d85-922c-15730d6fa8b1',
'name' => 'John Doe',
'name' => 'jdoe',
'email' => 'john@example.com',
'profilePicture' => null
'profilePicture' => null,
'username' => 'jdoe',
'realname' => 'John Doe',
'biography' => 'My bio',
'birthday' => null,
'city' => null,
'country' => null,
'company' => null,
'jobPosition' => null,
'blogUrl' => 'https://example.com',
'url' => 'https://example.com',
'feedUrl' => null,
],
$user->toArray()
);
Expand Down

0 comments on commit 08339cd

Please sign in to comment.