WSL_Test_Users   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 19 1
A tearDown() 0 4 1
A test_wsl_wp_email_exists() 0 4 1
A test_store_user_social_profile() 0 27 1
A test_delete_user_social_profile() 0 12 1
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
54
	{
55
		$insert_id = wsl_store_hybridauth_user_profile( $this->someUserID, $this->someUserIDP, $this->someUserProfile );
0 ignored issues
show
Unused Code introduced by
$insert_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
85
	{
86
		$insert_id = wsl_store_hybridauth_user_profile( $this->someUserID, $this->someUserIDP, $this->someUserProfile );
0 ignored issues
show
Unused Code introduced by
$insert_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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