@@ -27,19 +27,139 @@ public function setUp() {
27
27
$ this ->mock ->register ();
28
28
}
29
29
30
+ /**
31
+ * Confirm that User Switching is installed and active.
32
+ */
33
+ public function test_user_switching_installed_and_activated () {
34
+ $ this ->assertTrue ( class_exists ( 'user_switching ' ) );
35
+ }
36
+
30
37
public function test_callback_switch_to_user () {
38
+ // Create and authenticate user to be switched from.
39
+ $ old_user_id = self ::factory ()->user ->create (
40
+ array (
41
+ 'user_login ' => 'oldtestuser ' ,
42
+ 'user_role ' => 'adminstrator ' ,
43
+ 'display_name ' => 'oldtestuserdisplay ' ,
44
+ )
45
+ );
46
+ wp_set_current_user ( $ old_user_id );
47
+
48
+ // Create user ID for destination user.
49
+ $ user_id = self ::factory ()->user ->create (
50
+ array (
51
+ 'user_login ' => 'testuser ' ,
52
+ 'user_role ' => 'adminstrator ' ,
53
+ 'display_name ' => 'testuserdisplay ' ,
54
+ )
55
+ );
56
+
57
+ // Expected log calls.
58
+ $ this ->mock ->expects ( $ this ->once () )
59
+ ->method ( 'log ' )
60
+ ->with (
61
+ $ this ->equalTo (
62
+ _x (
63
+ 'Switched user to %1$s (%2$s) ' ,
64
+ '1: User display name, 2: User login ' ,
65
+ 'stream '
66
+ )
67
+ ),
68
+ $ this ->equalTo (
69
+ array (
70
+ 'display_name ' => 'testuserdisplay ' ,
71
+ 'user_login ' => 'testuser ' ,
72
+ )
73
+ ),
74
+ $ this ->equalTo ( $ old_user_id ),
75
+ $ this ->equalTo ( 'sessions ' ),
76
+ $ this ->equalTo ( 'switched-to ' ),
77
+ $ this ->equalTo ( $ old_user_id )
78
+ );
31
79
80
+ // Switch to user to trigger callback.
81
+ \switch_to_user ( $ user_id );
82
+
83
+ // Check callback test action.
84
+ $ this ->assertGreaterThan ( 0 , did_action ( 'wp_stream_test_callback_switch_to_user ' ) );
32
85
}
33
86
34
87
public function test_callback_switch_back_user () {
88
+ // Create and authenticate users for later use.
89
+ $ old_user_id = self ::factory ()->user ->create (
90
+ array (
91
+ 'user_login ' => 'oldtestuser ' ,
92
+ 'user_role ' => 'adminstrator ' ,
93
+ 'display_name ' => 'oldtestuserdisplay ' ,
94
+ )
95
+ );
96
+ $ user_id = self ::factory ()->user ->create (
97
+ array (
98
+ 'user_login ' => 'testuser ' ,
99
+ 'user_role ' => 'adminstrator ' ,
100
+ 'display_name ' => 'testuserdisplay ' ,
101
+ )
102
+ );
103
+
104
+ wp_set_current_user ( $ old_user_id );
105
+ \switch_to_user ( $ user_id );
106
+
107
+ // Expected log calls.
108
+ $ this ->mock ->expects ( $ this ->once () )
109
+ ->method ( 'log ' )
110
+ ->with (
111
+ $ this ->equalTo (
112
+ _x (
113
+ 'Switched back to %1$s (%2$s) ' ,
114
+ '1: User display name, 2: User login ' ,
115
+ 'stream '
116
+ )
117
+ ),
118
+ $ this ->equalTo (
119
+ array (
120
+ 'display_name ' => 'oldtestuserdisplay ' ,
121
+ 'user_login ' => 'oldtestuser ' ,
122
+ )
123
+ ),
124
+ $ this ->equalTo ( $ user_id ),
125
+ $ this ->equalTo ( 'sessions ' ),
126
+ $ this ->equalTo ( 'switched-back ' ),
127
+ $ this ->equalTo ( $ user_id )
128
+ );
35
129
130
+ // Switch to user to trigger callback.
131
+ \switch_to_user ( $ old_user_id , false , false );
132
+
133
+ // Check callback test action.
134
+ $ this ->assertGreaterThan ( 0 , did_action ( 'wp_stream_test_callback_switch_back_user ' ) );
36
135
}
37
136
38
137
public function test_callback_switch_off_user () {
138
+ // Create/authenticate user for later use.
139
+ $ user_id = self ::factory ()->user ->create (
140
+ array (
141
+ 'user_login ' => 'testuser ' ,
142
+ 'user_role ' => 'adminstrator ' ,
143
+ 'display_name ' => 'testuserdisplay ' ,
144
+ )
145
+ );
146
+ wp_set_current_user ( $ user_id );
39
147
40
- }
148
+ $ this ->mock ->expects ( $ this ->once () )
149
+ ->method ( 'log ' )
150
+ ->with (
151
+ $ this ->equalTo ( __ ( 'Switched off ' , 'stream ' ) ),
152
+ $ this ->equalTo ( array () ),
153
+ $ this ->equalTo ( $ user_id ),
154
+ $ this ->equalTo ( 'sessions ' ),
155
+ $ this ->equalTo ( 'switched-off ' ),
156
+ $ this ->equalTo ( $ user_id )
157
+ );
41
158
42
- public function test_callback_wp_stream_after_connectors_registration () {
159
+ // Switch to user to trigger callback.
160
+ \switch_off_user ();
43
161
162
+ // Check callback test action.
163
+ $ this ->assertGreaterThan ( 0 , did_action ( 'wp_stream_test_callback_switch_off_user ' ) );
44
164
}
45
165
}
0 commit comments