/
e_user_providerTest.php
146 lines (119 loc) · 4.62 KB
/
e_user_providerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
* e107 website system
*
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*/
class e_user_providerTest extends \Codeception\Test\Unit
{
/** @var e_user_provider */
protected $e_user_provider;
protected function _before()
{
try
{
include_once(e_HANDLER . 'user_handler.php');
$this->e_user_provider = $this->make('e_user_provider');
}
catch (Exception $e)
{
$this->fail("Couldn't load e_user_provider object: {$e}");
}
}
public function testGetSupportedProviders()
{
$result = e_user_provider::getSupportedProviders();
$this->assertIsArray($result);
$this->assertContains("Facebook", $result);
$this->assertContains("Twitter", $result);
$this->assertCount(51, $result,
"The number of Hybridauth providers has changed! If this is intentional, note the change " .
"in Hybridauth providers in the release changelog and update the count in this test."
);
}
public function testGetProviderType()
{
$result = e_user_provider::getTypeOf("NotARealProvider");
$this->assertFalse($result);
$result = e_user_provider::getTypeOf("Steam");
$this->assertEquals("OpenID", $result);
$result = e_user_provider::getTypeOf("StackExchangeOpenID");
$this->assertEquals("OpenID", $result);
$result = e_user_provider::getTypeOf("Twitter");
$this->assertEquals("OAuth1", $result);
$result = e_user_provider::getTypeOf("WordPress");
$this->assertEquals("OAuth2", $result);
}
public function testGetStandardFieldsOf()
{
$result = e_user_provider::getStandardFieldsOf("Facebook");
$this->assertTrue(array_key_exists('id', $result['keys']));
$this->assertTrue(array_key_exists('secret', $result['keys']));
$this->assertTrue(array_key_exists('scope', $result));
$result = e_user_provider::getStandardFieldsOf("Steam");
$this->assertTrue(array_key_exists('openid_identifier', $result));
$result = e_user_provider::getStandardFieldsOf("Telegram");
$this->assertEmpty($result);
$result = e_user_provider::getStandardFieldsOf("Twitter");
$this->assertTrue(array_key_exists('key', $result['keys']));
$this->assertTrue(array_key_exists('secret', $result['keys']));
}
public function testGetSupplementalFieldsOf()
{
$result = e_user_provider::getSupplementalFieldsOf("Facebook");
$this->assertTrue(array_key_exists('photo_size', $result));
$result = e_user_provider::getSupplementalFieldsOf("Foursquare");
$this->assertTrue(array_key_exists('api_version', $result));
$this->assertTrue(array_key_exists('photo_size', $result));
$result = e_user_provider::getSupplementalFieldsOf("Google");
$this->assertTrue(array_key_exists('photo_size', $result));
$result = e_user_provider::getSupplementalFieldsOf("Odnoklassniki");
$this->assertTrue(array_key_exists('key', $result['keys']));
$this->assertTrue(array_key_exists('secret', $result['keys']));
$this->assertIsNotArray($result['keys']['key']);
$this->assertIsNotArray($result['keys']['secret']);
$result = e_user_provider::getSupplementalFieldsOf("StackExchange");
$this->assertTrue(array_key_exists('api_key', $result));
$this->assertTrue(array_key_exists('site', $result));
$result = e_user_provider::getSupplementalFieldsOf("Steam");
$this->assertFalse(array_key_exists('id', $result['keys']));
$this->assertTrue(array_key_exists('secret', $result['keys']));
$result = e_user_provider::getSupplementalFieldsOf("Telegram");
$this->assertTrue(array_key_exists('id', $result['keys']));
$this->assertTrue(array_key_exists('secret', $result['keys']));
$result = e_user_provider::getSupplementalFieldsOf("Twitter");
$this->assertTrue(array_key_exists('authorize', $result));
$this->assertTrue(array_key_exists('photo_size', $result));
$this->assertIsNotArray($result['photo_size']);
$result = e_user_provider::getSupplementalFieldsOf("Vkontakte");
$this->assertTrue(array_key_exists('photo_size', $result));
}
public function testNewSuppressExceptions()
{
$this->assertInstanceOf(
e_user_provider::class,
new e_user_provider("Facebook", ["providers" => ["Facebook", ["enabled" => true]]])
);
}
public function testNewNoSuppressConfigurationException()
{
$this->expectException(\Hybridauth\Exception\InvalidArgumentException::class);
new e_user_provider(
"Facebook",
["providers" => ["Facebook" => ["enabled" => true]]],
false
);
}
public function testNewNoSuppressDisabledException()
{
$this->expectException(\Hybridauth\Exception\UnexpectedValueException::class);
new e_user_provider(
"Facebook",
["providers" => ["Facebook" => ["enabled" => false]]],
false
);
}
}