1
|
|
|
<?php |
2
|
|
|
/*! |
3
|
|
|
* WordPress Social Login |
4
|
|
|
* |
5
|
|
|
* https://miled.github.io/wordpress-social-login/ | https://github.com/miled/wordpress-social-login |
6
|
|
|
* (c) 2011-2020 Mohamed Mrassi and contributors | https://wordpress.org/plugins/wordpress-social-login/ |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
class WSL_Test_Users extends WP_UnitTestCase |
10
|
|
|
{ |
11
|
|
|
protected $someUserID = null; |
12
|
|
|
protected $someUserLogin = 'wslusertest'; |
13
|
|
|
protected $someUserMail = '[email protected]'; |
14
|
|
|
protected $someUserIDP = 'Google'; |
15
|
|
|
protected $someUserProfile = null; |
16
|
|
|
|
17
|
|
|
function setUp() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
parent::setUp(); |
20
|
|
|
|
21
|
|
|
$this->someUserID = wp_create_user( $this->someUserLogin, wp_generate_password(), $this->someUserMail ); |
22
|
|
|
|
23
|
|
|
include_once WORDPRESS_SOCIAL_LOGIN_ABS_PATH . 'hybridauth/library/src/autoload.php'; |
24
|
|
|
|
25
|
|
|
$this->someUserProfile = new Hybridauth\User\Profile(); |
26
|
|
|
|
27
|
|
|
$this->someUserProfile->identifier = 'identifier'; |
28
|
|
|
$this->someUserProfile->firstName = 'firstName'; |
29
|
|
|
$this->someUserProfile->lastName = 'lastName'; |
30
|
|
|
$this->someUserProfile->displayName = 'display Name'; |
31
|
|
|
$this->someUserProfile->photoURL = ''; |
32
|
|
|
$this->someUserProfile->profileURL = ''; |
33
|
|
|
$this->someUserProfile->email = '[email protected]'; |
34
|
|
|
$this->someUserProfile->emailVerified = '[email protected]'; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function tearDown() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
parent::tearDown(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/* |
43
|
|
|
* make sure we can found a wordpress user by email |
44
|
|
|
*/ |
45
|
|
|
function test_wsl_wp_email_exists() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->assertEquals( $this->someUserID, wsl_wp_email_exists( $this->someUserMail ) ); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/* |
51
|
|
|
* make sure users social profiles setter and getters works correctly |
52
|
|
|
*/ |
53
|
|
|
function test_store_user_social_profile() |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
$insert_id = wsl_store_hybridauth_user_profile( $this->someUserID, $this->someUserIDP, $this->someUserProfile ); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$profile = (array) wsl_get_stored_hybridauth_user_profiles_by_user_id( $this->someUserID ); |
58
|
|
|
$this->assertEquals( 1 , count( $profile ) ); |
59
|
|
|
$this->assertEquals( $this->someUserID , $profile[0]->user_id ); |
60
|
|
|
$this->assertEquals( $this->someUserIDP , $profile[0]->provider ); |
61
|
|
|
$this->assertEquals( $this->someUserProfile->identifier , $profile[0]->identifier ); |
62
|
|
|
$this->assertEquals( $this->someUserProfile->email , $profile[0]->email ); |
63
|
|
|
$this->assertEquals( $this->someUserProfile->emailVerified , $profile[0]->emailverified ); |
64
|
|
|
|
65
|
|
|
$user_id = (int) wsl_get_stored_hybridauth_user_id_by_email_verified( $this->someUserProfile->email ); |
66
|
|
|
$this->assertEquals( $this->someUserID, $user_id ); |
67
|
|
|
|
68
|
|
|
$profile = (array) wsl_get_stored_hybridauth_user_id_by_provider_and_provider_uid( $this->someUserIDP, $this->someUserProfile->identifier ); |
69
|
|
|
$this->assertEquals( 1, count( $profile ) ); |
70
|
|
|
|
71
|
|
|
$user_id = wsl_get_stored_hybridauth_user_id_by_provider_and_provider_uid( $this->someUserIDP, $this->someUserProfile->identifier ); |
72
|
|
|
$this->assertEquals( $this->someUserID, $user_id ); |
73
|
|
|
|
74
|
|
|
$count = wsl_get_wsl_users_count(); |
75
|
|
|
$this->assertEquals( 1, $count ); |
76
|
|
|
|
77
|
|
|
$count = wsl_get_stored_hybridauth_user_profiles_count(); |
78
|
|
|
$this->assertEquals( 1, $count ); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/* |
82
|
|
|
* make sure users social profiles are deleted when the associated wordpress user is deleted |
83
|
|
|
*/ |
84
|
|
|
function test_delete_user_social_profile() |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$insert_id = wsl_store_hybridauth_user_profile( $this->someUserID, $this->someUserIDP, $this->someUserProfile ); |
|
|
|
|
87
|
|
|
|
88
|
|
|
$profile = (array) wsl_get_stored_hybridauth_user_profiles_by_user_id( $this->someUserID ); |
89
|
|
|
$this->assertEquals( 1, count( $profile ) ); |
90
|
|
|
|
91
|
|
|
wp_delete_user( $this->someUserID ); |
92
|
|
|
|
93
|
|
|
$profile = (array) wsl_get_stored_hybridauth_user_profiles_by_user_id( $this->someUserID ); |
94
|
|
|
$this->assertEquals( 0, count( $profile ) ); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.